// UI class UIMgr{ constructor() { console.log('UIMgr初始化'); this.recordList = {}; this.popupList = []; } openUI(path, callBack){ let arr = path.split('/'); let key = arr[arr.length - 1]; if(key != 'TipsLayer') this.showWait(); cc.resources.load(path, function(err, prefab){ if(err){ console.log('加载界面出错: ', path); return; } this.hideWait(); if(cc.isValid(this.recordList[key])){ console.log("弹框已加载: ", key); if (callBack) callBack(this.recordList[key]); return; } let pf = cc.instantiate(prefab); let layer = cc.director.getScene(); pf.parent = layer; pf.name = key; this.setLayerIndex(pf); this.recordList[key] = pf; this.popupList.push({name: key, node: pf}); if(callBack) callBack(pf); }.bind(this)); } setLayerIndex(target){ let tName = target.name; if(tName == 'TipsLayer'){ target.zIndex = 100 + this.popupList.length; }else{ // target.zIndex = 200 + this.popupList.length; } } clearPopupList(){ this.popupList = []; } getPopupNums() { console.log('getPopupNums: ', this.popupList); return this.popupList.length; } closeUI(key, bDestroy=true){ for(let i=0; i < this.popupList.length; i++){ let item = this.popupList[i]; if(item.name == key){ if(bDestroy){ if(cc.isValid(item.node)){ item.node.destroy(); } } this.popupList.splice(i, 1); break; } } delete this.recordList[key]; } closeAllUI(){ for(let i=0; i < this.popupList.length; i++){ let item = this.popupList[i]; if (cc.isValid(item.node)) { item.node.destroy(); } } this.popupList = []; this.recordList = {}; } // -------- wait -------- showWait(callBack = null){ let waitNode = cc.find('WaitNodeLayer'); if(waitNode) waitNode.getComponent('WaitNodeLayer').showWait(callBack); } hideWait(){ let waitNode = cc.find('WaitNodeLayer'); if(waitNode) waitNode.getComponent('WaitNodeLayer').hideWait(); } } let instance = null; UIMgr.getInstance = function(){ if(!instance){ instance = new UIMgr(); } return instance; } export default UIMgr.getInstance();