import { _decorator } from "cc"; import GameApp from "./GameApp"; import BaseLaunch from "./scripts/base/architecture/BaseLaunch"; import BaseModule from "./scripts/base/architecture/module/BaseModule"; import CommonModule from "./scripts/module/common/CommonModule"; import { SceneConst } from "./scripts/define/SceneConst"; import { LoadingEvent } from "./scripts/module/common/loading/LoadingConst"; import GameModule from "./scripts/module/game/GameModule"; import { ConfigConst } from "./scripts/define/ConfigConst"; const { ccclass, property } = _decorator; @ccclass export default class GameLaunch extends BaseLaunch { // 修改这个,会影响本地数据存储 gameName: string = "demo"; // 修改这个,会影响本地数据存储 version: string = "v1"; // 游戏模块 moduleList: BaseModule[] = [ CommonModule.GetInstance(), GameModule.GetInstance(), ]; async init() { const _this = this; GameApp.S.SceneMgr.getCurScene().open(); // sdk初始化 await GameApp.S.SDKMgr.init(); // 预加载场景 let loadScenePromise = _this.preloadScene(); // 初始化策略 _this.initStrategy(); // 初始化资源bundle await _this.initBundle(); // 初始化功能模块 _this.initModules(); GameApp.S.DataMgr.setProjectTag(`${_this.gameName}_${_this.version}`) await loadScenePromise } async preloadScene() { let sceneList = [SceneConst.Game] let curFinishCount = 0 let needLoadingCount = sceneList.length GameApp.S.EventMgr.emit(LoadingEvent.LoadingScene, curFinishCount, needLoadingCount) let asyncList = [] for (let i = 0; i < sceneList.length; i++) { let loadScene = sceneList[i]; asyncList.push(new Promise(async (r, j) => { await GameApp.S.SceneMgr.preload(loadScene); curFinishCount++ GameApp.S.EventMgr.emit(LoadingEvent.LoadingScene, curFinishCount, needLoadingCount) r(); })) } await Promise.all(asyncList); } async initBundle() { let _this = this let bundleList = [ GameApp.S.ResMgr.addBundle("resources"), GameApp.S.ResMgr.addBundle("common"), ] _this.moduleList.forEach(module => { bundleList.push(...module.loadBundle()) }); let curFinishCount = 0 let needLoadingCount = bundleList.length GameApp.S.EventMgr.emit(LoadingEvent.LoadingBundle, curFinishCount, needLoadingCount) let asyncList = [] for (let i = 0; i < bundleList.length; i++) { let loadBundle = bundleList[i]; asyncList.push(new Promise(async (r, j) => { await loadBundle curFinishCount++ GameApp.S.EventMgr.emit(LoadingEvent.LoadingBundle, curFinishCount, needLoadingCount) r(); })) } await Promise.all(asyncList); await GameApp.S.ConfigMgr.loadConfig(ConfigConst.GameData) } initModules(): void { // 初始化配置文件 this.moduleList.forEach(module => { module.initConfig() }); // 初始化模块 this.moduleList.forEach(module => { module.initModel() }); } }