/// <summary> /// 清除可能会冲突的实例(尽管禁用UIDate后再载入存档一般可以顺利进行,但游戏特殊情况仍会卡读档,在游戏开发稳定之前双保险) /// </summary> /// <returns></returns> private static bool Prefix(DateFile.LegendBook loadDate) { if (LoadFile.OnLoad) { LoadFile.OnLoad = false; #if DEBUG //var m_Container = ReflectionMethod.GetValue<SingletonObject, GameObject>(null, "m_Container"); //Main.Logger.Log($"DateFile_Loadloadlegend: Is m_Container null? {m_Container == null}"); //foreach(string key in SingletonMap.Keys) //{ // Main.Logger.Log($"DateFile_Loadloadlegend m_SingletonMap keys {key}"); //} #endif // 清除需要清除的实例(仿自 SingletonObject.ClearInstances) foreach (var inst in instancesToRemove) { if (SingletonMap.TryGetValue(inst, out object item) && !DontClearList.Contains(item)) { (item as IDisposable)?.Dispose(); if (item is Component cmp) { UnityEngine.Object.Destroy(cmp); } SingletonMap.Remove(inst); } } // 清除Subsystem中可能存在冲突的实例 SubSystems.OnLeaveGame(); } return(true); }
/// <summary> /// 执行存档读取操作 /// </summary> public static void DoLoad(int dataId) { OnLoad = true; // 先 ChangeGameState , 擠掉之前的 GameState // 避免在 DateFile.instance.Initialize 時觸發 前一個 State 的 OnExit // 會造成一些問題 (例如讀檔後戰鬥黑屏) Game.Instance.ChangeGameState(eGameState.Login, new object[] { eMainMenuShow.None }); // 用 GMPanel 的寫法 SubSystems.OnLeaveGame(); GameData.Common.OnLeaveGame(); WorldMapSystem.instance.ResetWorldMap(); UIManager.Instance.DestroyAllOldPrefabs(); SingletonObject.ClearInstances(); DateFile.instance.Initialize(dataId, false); }