import BasicView from "../../../Engine/Basic/BasicView"; import { _EJsonRes } from "../../../Engine/Data/CommonDataType"; import EventManager from "../../../Engine/Event/EventManager"; import JsonResources from "../../../Engine/Resources/JsonResources"; import LoadProgress from "../../../Engine/Component/View/LoadProgress"; import { _EGameBehavior, ConstObject, _EGameJsonRes } from "../../Data/GameDataType"; import { _IUserData } from "../../Data/User/UserConfig"; import GameEventName from "../../Event/GameEventName"; import { _IViewResConfig } from "../../../Engine/View/Data/ViewConfig"; import GameAudioResData from "../../Game/Data/GameMusicResData"; /** * 启动页 */ export default class InitLoadView extends BasicView { public static resPath: string = "InitLoadView"; /**进度条 */ private progress: fgui.GProgressBar; protected _initView(): void { this.progress = this.fgui.getChild("progress").asProgress; // 更新加载进度条 EventManager.onEvent(GameEventName.Res.Res_LoadProgress, this, (_progress: number) => { this.progress.value = _progress*this.progress.max; }); let load1 = false; let load2 = false; cc.assetManager.loadBundle("res/prefab", (err: Error, prefab: cc.AssetManager.Bundle) => { cc.assetManager.loadBundle("res/audio", (err: Error, audio: cc.AssetManager.Bundle) => { load1 = true; if (load1 == true && load2 == true) { this.laodComplete(); } }); }); // 加载游戏资源 { // 加载配置表 let json: Array = []; for (let name in _EJsonRes) { json.push(_EJsonRes[name]); } for (let name in _EGameJsonRes) { json.push(_EGameJsonRes[name]); } JsonResources.loadJsonResources(ConstObject.ResPath, json, 1/4, 0, () => { // 关闭事件监听 EventManager.offEventByTarget(this); let viewResConfig: _IViewResConfig = JsonResources.getResources(_EJsonRes.ResGroup)["InitLoadView"]; this.addComponentIntance(new LoadProgress(this.progress, (_progress: number) => { this.progress.getChild("progressText").asTextField.text = Math.round(_progress)+"%"; }, () => { load2 = true; if (load1 == true && load2 == true) { this.laodComplete(); } }, viewResConfig)); } ); } } protected _refreshView(): void { } protected _clearView(): void { } protected resize () { this.fgui.width = fgui.GRoot.inst.width; } private laodComplete (): void { EventManager.sendEvent(GameEventName.Audio.Audio_PlayMusic, GameAudioResData.BGM); EventManager.sendEvent(GameEventName.Behavior.Behavior_SetPreconditionData, _EGameBehavior.Hall, {initLoad: true}); EventManager.sendEventByTargetID(GameEventName.Behavior.Behavior_EnterBehavior, ConstObject.GameFlowTreeID, _EGameBehavior.Gameing); } }