123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- cc.Class({
- extends: cc.Component,
- properties: {
- },
-
- initView(param) {
- },
- createComponent(type, parent, param, cb, cache = false) {
- let prefabPath = G.UIMgr.defaultUIPath + JMC.UIPath[type];
- this.creawteUI(prefabPath, parent, param, cb, cache)
- },
- 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);
- let ret = self.safeAddChild(parent, node);
- if (!ret) {
- return;
- }
- let viewBase = node.getComponent("ViewBase");
- if (viewBase) {
- viewBase.initView(param)
- }
- if (!cache) {
- cc.loader.releaseRes(prefabPath);
- }
- if (cb) {
- cb(node, 'ok', undefined);
- }
- });
- },
- 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;
- },
- });
|