local GameApp = {} local LuaFuncEntry = require("Main/LuaFuncEntry") local LuaUpdater = require('Main/LuaUpdater') local EventSystem = require('Event/EventSystem') local HttpReq = require('Http/HttpReq') local private = {} function GameApp.Startup() private.IsShowSplash = false private.BeginUncompress = false LuaFuncEntry.Startup() private.SetupEntryFunc(true) end function private.SetupEntryFunc(isRegist) LuaFuncEntry.SetupMainEntryFunc(isRegist, LuaFuncEntry.FuncType.RebootGameMsg, private.OnRebootGameMsg, LuaFuncEntry.FuncType.OnLuaStateShutdown, private.OnLuaStateShutdown, LuaFuncEntry.FuncType.OnApplicationPause, private.OnApplicationPause, LuaFuncEntry.FuncType.OnApplicationQuit, private.OnApplicationQuit, LuaFuncEntry.FuncType.OnRebootOver, private.OnRebootOver, LuaFuncEntry.FuncType.BeginShowUncompressProgress, private.OnBeginShowUncompressProgress, LuaFuncEntry.FuncType.FinishUncompressInternal, GameApp.OnUncompressInternalFinish ) end function private.OnRebootGameMsg(msg) UTL.MessageBox.ShowOnlyOkNoCloseBox(Const_IDS.IDS_WARNING, msg, SDKUtil.OnClickKickCallback) end --Lua中进行清理事件 function private.OnLuaStateShutdown() -- 开始进行 LuaStateShutdown 此时派发一个事件 方便去做特殊逻辑 EventSystem.Dispatch(EventID.BeginLuaStateShutdown) LuaUpdater.Shutdown() if not NetManager.IsLaunch() then LevelManager.OnShutdown() end UIManager.OnShutdown() DataSheetManager.ClearData() Modules.Shutdown() TimerUtil.Clear() CameraController.DestroyGameCamera() AuxUtil.ClearLoadedAsset() HttpReq.OnShutdown() if DEF.USE_YIDUN_PROTECT then if UNITY_ANDROID then --新版本易盾修复卡死问题 if GameAppInfo.IsOverseaPackage() then if GameAppInfo.IsVersionGreaterThan113400() then AuxUtil.NetSecProtectLogout() end elseif GameAppInfo.IsJapanesePackage() then if GameAppInfo.IsVersionGreaterThan113000() then AuxUtil.NetSecProtectLogout() end else AuxUtil.NetSecProtectLogout() end end end if GameAppInfo.IsVersionGreaterThan16000() then local opCode = 20 AuxUtil.OperateGameSystem("ApplicationSystem", opCode) AuxUtil.OperateGameSystem("ChatSystem", opCode) if GameAppInfo.IsPCPackage() or GameAppInfo.EditorOpenGME() then AuxUtil.OperateGameSystem("GMEPCSDKSystem", opCode) end if GameAppInfo.IsVersionGreaterThan19000() then AuxUtil.OperateGameSystem("RenderEntityAppendSystem", opCode) end end private.Shutdown() NetManager.SetIsLaunch(true) end function private.Shutdown() private.SetupEntryFunc(false) LuaFuncEntry.Shutdown() end --程序暂停切换事件,不要直接调用模块,通过事件方式进行处理 function private.OnApplicationPause(pause) logging.crit(LTAG.CRIT, "OnApplicationPause", pause) if not NetManager.IsLaunch() then if BattleDataGetter.IsSyncLevel() then EventSystem.Dispatch(EventID.BI_LevelMiddle, BIManager.BIType.SyncBattle, "[sync]GamePause", pause and 1 or 0) LevelManager.CurLevelFunc:OnApplicationPause(pause) end if not pause and BattleDataGetter.IsTownLevel() then SDKUtil.GetNewMessageNum() end end AuxUtil.OnCSApplicationPause(pause) UTL.Time.OnApplicationPause(pause) NetManager.OnApplicationPause(pause) if pause then private.applicationPauseTime = UTL.Time.GetServerTimestamp() EventSystem.Dispatch(EventID.ApplicationPause, true) else EventSystem.Dispatch(EventID.ApplicationPause, false, UTL.Time.GetServerTimestamp() - private.applicationPauseTime) end end --程序退出事件 function private.OnApplicationQuit() AuxUtil.OnCSApplicationQuit() EventSystem.Dispatch(EventID.ApplicationQuit) end --重置资源回调 --isReloadBundle是否重新加载bundle --isHotfix是否热更重置调用 function private.OnRebootOver(isReloadBundle, isHotfix) if isReloadBundle and isHotfix then BIManager.SendWithEncode("ReloadHotUpdateAssets") end end function private.OnBeginShowUncompressProgress(totalCount) logging.crit(LTAG.CRIT, "begin uncompress", totalCount) --简单做个解压表现 UIManager.OpenView(Const_UI_Lua.UIEnum.UILoadingPanel_Uncompress, { totalCount = totalCount }) if GameAppInfo.IsJapanesePackage() then --首次安装执行解压缩的开关,用于判断闪屏逻辑 private.BeginUncompress = true end end function GameApp.OnUncompressInternalFinish() logging.crit(LTAG.CRIT, "finish uncompress internal") BIManager.OnUncompressInternalFinish() UIManager.CloseView(Const_UI_Lua.UIEnum.UILoadingPanel_Uncompress) --Proto生成代码中使用了module函数,需要向全局表插入键值对,需要在开启限制前加载 def_G("MessageEnums", require("Proto/message_enums_pb")) --网络 def_G("NetManager", require("Main/NetManager")) --数据,本地化Localization.Init要用 def_G("DataSheetManager", require("Main/DataSheetManager")) Localization.OnUncompressInternalFinish() --启动基础系统模块,此时尚未登录游戏,玩家数据和游戏逻辑还未初始化 Modules.Bootstrap() if DEF.ENABLE_ASSET_ANALYSIS then local AssetAnalysisTools = require("ProfilerKit/AssetAnalysisTools") AssetAnalysisTools.Start() else if string.find(UIUtils.GetActiveSceneName(), "RenderModel_EditorScene") then UIManager.OpenView(Const_UI_Lua.UIEnum.UIRenderTextureEditor) else if private.BeginUncompress then --进入Login;拉取公告、热更 CTL.Login.Start() else --这里代表是非首次安装,走闪屏。 if private.IsShowSplash and (GameAppInfo.IsChinesePackage() or GameAppInfo.IsJapanesePackage()) then UIManager.OpenView(Const_UI_Lua.UIEnum.UISplash) else --进入Login;拉取公告、热更 CTL.Login.Start() end end end end end function GameApp.SetIsShowSplash(status) private.IsShowSplash = status end return GameApp