12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- cc.Class({
- extends: cc.Component,
- properties: {
- },
-
- createComponent(type, parent, param, cb) {
- let prefabPath = G.UIMgr.defaultUIPath + JMC.UIPath[type];
- this.creawteUI(prefabPath, parent, param)
- },
- creawteUI(prefabPath, parent, param, cb, cache = false) {
- G.LogUtils.warn('showAlert', prefabPath);
- let self = this;
- cc.loader.loadRes(prefabPath, cc.Prefab, (completedCount, totalCount, item) => {
- }, (err, prefab) => {
- if (err) {
- G.AppUtils.getSceneCtrl().addToast('网络异常!');
- G.LogUtils.error('[showAlert]', err);
- if (cb) {
- cb(undefined, 'error', err);
- }
- return;
- }
- let node = cc.instantiate(prefab);
- if (cb) {
- cb(alert, 'willShow', undefined);
- }
- let ret = self.safeAddChild(parent, node);
- if (!ret) {
- return;
- }
- let viewBase = node.getComponent(ViewBase);
- if (viewBase) {
- viewBase.init(param)
- }
- if (!cache) {
- cc.loader.releaseRes(prefabPath);
- }
- });
- },
- safeAddChild(parent, node) {
- if (!cc.isValid(node) || !cc.isValid(parent)) {
- return false;
- }
- parent.addChild(node);
- cc.game.emit('e_ui_push_alert', {node});
- return true;
- },
- });
|