import { Scene, director } from "cc"; import { MainConfig } from "../../Launch/_MainConfig"; import { EUIFormsToIUIRes, IUIRes } from "../Mgr_UI/Config/SysDefine"; import { EUIForms } from "../const/UIFormCnf"; import { EResUrls } from "../ResUrl/EResUrls"; import ResLoad from "../ResUrl/ResLoad"; import { EBundleName, ESceneName, LoadSceneType } from "../const/GameEnum"; import BaseInitLoad from "./BaseInitLoad"; import CavernInitLoad from "./CavernInitLoad"; import UIMgr from "../Mgr_UI/UIMgr"; import { GameDataProxy } from "../Mgr_LocalData/DataTypeProxy/GameDataProxy"; export interface ISceneLoadData { /**加载中的场景 */ load_scene: ESceneName, /**加载中场景展示的UI */ loadingUI: string, /**加载得目标场景 */ scene_name: ESceneName, /**加载完成返回 */ back_funtion: Function, /**目标场景所在得Bundle包 */ bundle: EBundleName, /**默认打开的UI */ default_open_ui: IUIRes[], /**加载组处理 */ LoadGroup: BaseInitLoad, /**帧率 */ Frame: number, } export default class LevelManager { static level: Scene; static isPreLodingui: boolean = true; static LodeLevle(SceneName: string, onComplete?: Function) { director.loadScene(SceneName, (err, Scene) => { //Scene.re this.level = Scene; if (onComplete != null) { onComplete(Scene); } }); } /**预加载场景 */ private static PreloadedScene(param: ISceneLoadData, onComplete: Function) { ResLoad.Ins.loadBundle(param.bundle, () => { director.preloadScene(param.scene_name, (Data) => { onComplete && onComplete(); // if (this.isPreLodingui) { // this.PreloadedUIForms(param, onComplete); // } else { // onComplete && onComplete(); // } }); }); } /**预加载场景 */ private static PreloadedUIForms(param: ISceneLoadData, onComplete: Function) { let tCount = param.default_open_ui.length; if (tCount <= 0) { onComplete && onComplete(); } // ResLoad.Ins.loadBundleAsync(EBundleName.General).then(() => { for (let i = 0; i < param.default_open_ui.length; i++) { const tData = param.default_open_ui[i]; let time = Date.now(); ResLoad.Ins.Perfab(EResUrls.UIPrefabs(tData.uiUrl),tData.bundle, (error, assets:any) => { let offset = Date.now() - time; if( offset > 100){ // if(PREVIEW){ // let tempObject = {}; // if (Array.isArray(assets)) { // assets.forEach(value => { // let tbundle = CocosUtils.GetResBundle(value.uuid); // let path = CocosUtils.GetResBundlePath(value.uuid); // tempObject[value.uuid] = { // path, // tbundle // } // }) // } // ConsoleEx.Warn(tData.uiUrl, "(建议优化)UI预加载耗时: ", offset, tempObject); // }else{ ConsoleEx.LogLight(tData.uiUrl, "(建议优化)UI预加载耗时: ", offset, assets); // } } tCount--; if (tCount <= 0) { // GameDataProxy.Ins.preLoadAssets(); onComplete && onComplete(); } }); } // }); } /**打开对应场景 */ private static OpenScene(param: ISceneLoadData) { LevelManager.LodeLevleByloding(param); } private static LodeLevleByloding(param: ISceneLoadData) { director.loadScene(param.load_scene, () => { ResLoad.Ins.loadBundle(param.bundle, () => { UIMgr.Ins.ShowUIForms(param.loadingUI, param, param.bundle); }); }); } /***加载城市场景 */ static LoadForest2(type: LoadSceneType = LoadSceneType.OpenDirectly, onComplete?: Function) { /**进入游戏 */ let param: ISceneLoadData = { load_scene: ESceneName.Loading, scene_name: ESceneName.Game, back_funtion: onComplete, bundle: EBundleName.Game, default_open_ui: [ EUIFormsToIUIRes(EUIForms.MainBgUI), EUIFormsToIUIRes(EUIForms.MainTopUI) ], loadingUI: "LodingUI", LoadGroup: new CavernInitLoad(), Frame: MainConfig.GameFarme, } switch (type) { case LoadSceneType.Preloaded: param.default_open_ui.push(EUIFormsToIUIRes(EUIForms.MainUI)); this.PreloadedScene(param, onComplete); break; case LoadSceneType.OpenDirectly: this.OpenScene(param); break; } } }