import { _decorator,instantiate,Prefab ,Node,find} from 'cc'; import { GameMng } from '../GameMng'; import { user_info_view } from '../Main/user_info_view'; import { userData } from '../UserData/userData'; import { ResMng } from './ResMng'; const { ccclass, property } = _decorator; @ccclass('UIManager') export class UIManager { private static _instance: UIManager | null = null; private static topLayerList:Node[] = []; private constructor() { } public static get Instance() { if (UIManager._instance === null) UIManager._instance = new UIManager(); return UIManager._instance; } public static AddPrefab(_prefab:Prefab,parent: any = null): Node { let prefab = instantiate(_prefab); if (parent == null) { parent = UIManager.Instance.TopLayer; if(_prefab.name==="UILoading"||_prefab.name==="waitView"||_prefab.name==="Dialog"){ this.pushLayer(prefab) console.log("_prefab name ",_prefab.name) } } parent.addChild(prefab); return prefab; } public static addUserInfoViewPrefab(user_data:userData): Node { let prefab = instantiate(GameMng.Instance.uiuserinfo); let parent:Node = UIManager.Instance.TopLayer; parent.addChild(prefab); prefab.getComponent(user_info_view).show(user_data) return prefab; } private topLayer: any = null; public get TopLayer() { this.topLayer = find("Canvas"); return this.topLayer; } public static removeLoadingLayer() { console.log("removeLoadingLayer") for (let index = 0; index < this.topLayerList.length; index++) { const element = this.topLayerList[index]; if(element){ console.log("element.name",element.name) if(element.name == "UILoading"){ element.destroy() this.topLayerList[index] = null; } } } } public static removeWaitViewLayer() { for (let index = 0; index < this.topLayerList.length; index++) { const element = this.topLayerList[index]; if(element){ console.log("element.name",element.name) if(element.name==="waitView"){ element.destroy() this.topLayerList[index] = null; } } } } public static removeDialogViewLayer() { for (let index = 0; index < this.topLayerList.length; index++) { const element = this.topLayerList[index]; if(element){ console.log("element.name",element.name) if(element.name==="Dialog"){ element.destroy() this.topLayerList[index] = null; } } } } public static pushLayer(layer:Node){ for (let index = 0; index < this.topLayerList.length; index++) { if(this.topLayerList[index]==null){ this.topLayerList[index] = layer; return; } } return this.topLayerList.push(layer) } }