import GameLogic from "../gameLogic/gameLogic"; import gameData from "../gameLogic/utrl/gameData"; import bundleManager from "./bundleManager"; class dungeonManager { private _dungeonPrefab: cc.Node = null; private _curOpenID: string; remove() { if (this._dungeonPrefab) { this._dungeonPrefab.active = false; } } /** * * @param str 房间名 * @param type 房间类型 * @param callback 回调 * @returns */ open(str: string, type: number, callback?: Function) { let self = this; if (this._dungeonPrefab && str == this._curOpenID && type == gameData.curInDungeonType) { this._dungeonPrefab.active = true; if (callback) { callback(); } return; } gameData.curInDungeonType = type; self.saveCurOpenID(str); setTimeout(() => { bundleManager.getBundleByName('dungeon').load('dungeon_' + str, cc.Prefab, function (err, prefab: cc.Prefab) { if (prefab) { let node = cc.instantiate(prefab); var cavans = cc.director.getScene().getChildByName('world') node.parent = cavans; // node.zIndex = 200 self.remove(); self._dungeonPrefab = node; cavans.getComponent(GameLogic).dungeonInit(node); if (callback) { callback(node); } } }) }, 50); } preLoadLevel(str: string) { bundleManager.getBundleByName('dungeon').preload('dungeon_' + str, cc.Prefab, () => { console.log('预加载副本' + str + '完成'); }); } /** * 保存当前打开的副本ID * @param id 副本ID */ saveCurOpenID(str: string) { this._curOpenID = str; } /** * * @returns 获取当前打开的副本ID */ getCurOpenId() { return this._curOpenID; } resetDungen() { this._dungeonPrefab = null; } } export default new dungeonManager();