// 加载战场 // readData:是否读取数据 IEnumerator <float> _LoadBattle() { yield return(Timing.WaitForOneFrame); Callback_OnBattleLoadStart?.Invoke(); float startTime = Time.realtimeSinceStartup; IsLoadingBattle = true; IsLoadBattleEnd = false; IsGameStart = false; //开始Tip SubBattleCoroutine.Run(_RandTip()); //开始加载 Callback_OnBattleLoad?.Invoke(); yield return(Timing.WaitForOneFrame); OnLoadSceneStart(); Callback_OnLoadingProgressChanged?.Invoke("Start to load", 0.0f); //演示几秒,给UI渐变的时间 yield return(Timing.WaitForSeconds(DelayLoadSceneTime)); //加载场景 SceneName = CurData.GetRawSceneName(); SceneAsset = GRMgr.LoadScene(SceneName); while (!SceneAsset.IsDone) { yield return(Timing.WaitForOneFrame); Callback_OnLoadingProgressChanged?.Invoke("LoadingScene", SceneAsset.Progress * 0.8f); } //延时一帧 yield return(Timing.WaitForOneFrame); SceneManager.SetActiveScene(SceneManager.GetSceneByName(SceneName)); Callback_OnBattleLoadedScene?.Invoke(); //这里必须延迟一帧,等待UI创建,注册事件 yield return(Timing.WaitForOneFrame); GC.Collect(); Callback_OnLoadingProgressChanged?.Invoke("GC", 1.0f); IsLoadingBattle = false; //场景加载结束 Callback_OnBattleLoaded?.Invoke(); IsLoadBattleEnd = true; Callback_OnGameStart?.Invoke(); IsGameStart = true; }
/// <summary> /// 加载战场 /// </summary> /// readData:是否读取数据 /// <returns></returns> IEnumerator <float> _LoadBattle(bool readData = true) { BaseView.IsFullScreenState.Reset(); SelfBaseGlobal.ResumeGame(); SelfBaseGlobal.PlotMgr.ResumePlotMode(); yield return(Timing.WaitForOneFrame); OnLoadBattleStart(); float startTime = Time.realtimeSinceStartup; IsLoadingBattle = true; //开始Tip BattleCoroutine.Run(_RandTip()); //开始加载 Callback_OnBattleLoad?.Invoke(); yield return(Timing.WaitForOneFrame); OnLoadSceneStart(); //演示几秒,给UI渐变的时间 yield return(Timing.WaitForSeconds(DelayLoadSceneTime)); //加载场景 string sceneName = CurData.GetSceneName(); SceneAsset = SelfBaseGlobal.DLCMgr.LoadScene("scene/" + sceneName, sceneName); while (!SceneAsset.isDone) { yield return(Timing.WaitForOneFrame); Callback_OnLoadingProgressChanged?.Invoke("LoadingScene", SceneAsset.progress * 0.8f); } //延时一帧 yield return(Timing.WaitForOneFrame); SceneManager.SetActiveScene(SceneManager.GetSceneByName(sceneName)); Callback_OnBattleLoadedScene?.Invoke(); //这里必须延迟一帧,等待UI创建,注册事件 yield return(Timing.WaitForOneFrame); //读取数据前,资源加载 yield return(Timing.WaitUntilDone(BattleCoroutine.Run(BeforeReadData()))); Callback_OnLoadingProgressChanged?.Invoke("BeforeReadData", 0.9f); if (readData) { //读取战场数据 Callback_OnReadBattleDataStart?.Invoke(); SelfBaseGlobal.DBMgr.ReadGameDBData(); Callback_OnReadBattleDataEnd?.Invoke(); } else { //不读取数据,适用于闯关 yield return(Timing.WaitForSeconds(0.1f)); } //增加加载战场次数 LoadBattleCount++; //读取数据后资源加载 yield return(Timing.WaitUntilDone(BattleCoroutine.Run(AffterReadData()))); Callback_OnLoadingProgressChanged?.Invoke("AffterReadData", 0.95f); //卸载未使用的资源 SelfBaseGlobal.DLCMgr.UnLoadBattleAssetBundle(); GC.Collect(); Callback_OnLoadingProgressChanged?.Invoke("GC", 1.0f); IsLoadingBattle = false; //场景加载结束 Callback_OnBattleLoaded?.Invoke(); OnLoadBattleEnd(); //游戏开始 Callback_OnGameStart?.Invoke(); while (IsLockGameStartFlow) { yield return(Timing.WaitForSeconds(0.01f)); } yield return(Timing.WaitUntilDone(BattleCoroutine.Run(BattleStart()))); //进入自定义流程的时候暂停 Callback_OnStartCustomBattleCoroutine?.Invoke(); SelfBaseGlobal.PlotMgr.EnablePlotMode(true); yield return(Timing.WaitUntilDone(SelfBaseGlobal.PlotMgr.CustomStartBattleCoroutine())); SelfBaseGlobal.PlotMgr.EnablePlotMode(false); Callback_OnEndCustomBattleCoroutine.Invoke(); IsStartBattle = true; Callback_OnGameStartOver?.Invoke(); }
// 加载战场 // readData:是否读取数据 IEnumerator <float> _loadBattle(bool readData = true) { BaseGlobal.ResumeGame(); BaseInputMgr.ResetFullScreenState(); Callback_OnBattleLoadStart?.Invoke(); yield return(Timing.WaitForOneFrame); float startTime = Time.realtimeSinceStartup; IsLoadedScene = false; IsLoadingBattle = true; IsLoadBattleEnd = false; IsGameStartOver = false; IsGameStart = false; IsInPauseLoadingView = false; //开始Tip BattleCoroutine.Run(_randTip()); //开始加载 Callback_OnBattleLoad?.Invoke(); yield return(Timing.WaitForOneFrame); OnLoadSceneStart(); Callback_OnLoadingProgressChanged?.Invoke(Util.GetStr("StartToLoad"), 0.0f); //演示几秒,给UI渐变的时间 yield return(Timing.WaitForSeconds(DelayLoadSceneTime)); //加载场景 SceneName = CurData.GetSceneName(); SceneAsset = GRMgr.LoadScene(SceneName); while (!SceneAsset.IsDone) { yield return(Timing.WaitForOneFrame); Callback_OnLoadingProgressChanged?.Invoke(Util.GetStr("LoadingScene"), SceneAsset.Progress * 0.8f); } //延时一帧 yield return(Timing.WaitForOneFrame); Scene = SceneManager.GetSceneByName(SceneName); SceneManager.SetActiveScene(Scene); IsLoadedScene = true; Callback_OnBattleLoadedScene?.Invoke(); if (BaseSceneObject == null) { CLog.Error("错误,场景里没有SceneObject"); } //这里必须延迟一帧,等待UI创建,注册事件 yield return(Timing.WaitForOneFrame); //读取数据前,资源加载 yield return(Timing.WaitUntilDone(BattleCoroutine.Run(BeforeReadData()))); Callback_OnLoadingProgressChanged?.Invoke(Util.GetStr("BeforeReadData"), 0.9f); if (readData) { BaseGlobal.IsUnReadData = false; //读取战场数据 BaseGlobal.DBMgr.ReadGameDBData(); BaseGlobal.IsUnReadData = true; } yield return(Timing.WaitForOneFrame); Callback_OnBattleReadDataEnd?.Invoke(); //增加加载战场次数 LoadBattleCount++; //读取数据后资源加载 yield return(Timing.WaitUntilDone(BattleCoroutine.Run(AffterReadData()))); Callback_OnLoadingProgressChanged?.Invoke(Util.GetStr("AffterReadData"), 0.95f); while (IsInCustomLoading) { yield return(Timing.WaitForOneFrame); } GC.Collect(); Callback_OnLoadingProgressChanged?.Invoke(Util.GetStr("GC"), 1.0f); IsLoadingBattle = false; //场景加载结束 Callback_OnBattleLoaded?.Invoke(); IsLoadBattleEnd = true; yield return(Timing.WaitForOneFrame); //游戏开始(预处理最后阶段) SelfBaseGlobal.OnGameStart1(); SelfBaseGlobal.OnGameStart2(); Callback_OnGameStart?.Invoke(); yield return(Timing.WaitForOneFrame); SelfBaseGlobal.OnGameStarted1(); SelfBaseGlobal.OnGameStarted2(); Callback_OnGameStarted?.Invoke(); IsGameStart = true; //暂停在加载界面 Callback_OnInPauseLoadingView?.Invoke(); IsInPauseLoadingView = NeedPauseLoading; while (IsInPauseLoadingView) { yield return(Timing.WaitForOneFrame); } SelfBaseGlobal.OnCloseLoadingView(); Callback_OnCloseLoadingView?.Invoke(); //锁定进入战场流程 while (IsLockBattleStartFlow) { yield return(Timing.WaitForOneFrame); } yield return(Timing.WaitUntilDone(BattleCoroutine.Run(BattleStart()))); //进入自定义流程的时候暂停 Callback_OnStartCustomBattleCoroutine?.Invoke(); if (PlotMgr != null) { PlotMgr?.SetPlotPause(true); yield return(Timing.WaitUntilDone(PlotMgr.CustomStartBattleCoroutine())); PlotMgr?.SetPlotPause(false); } Callback_OnEndCustomBattleCoroutine.Invoke(); //结尾部分 SelfBaseGlobal.OnGameStartOver(); Callback_OnGameStartOver?.Invoke(); IsGameStartOver = true; }