fix(save-system): 修复读档时 UI 与游戏状态未对齐
This commit is contained in:
@@ -152,7 +152,7 @@ namespace AibisDream.SaveSystem
|
||||
return new AutoSaveSuppressScope(reason);
|
||||
}
|
||||
|
||||
/// <summary>旧档:Yarn 变量 + DeepRepairDataRegistry systemData。</summary>
|
||||
/// <summary>旧档:仅恢复 Yarn 变量,再 Capture 写入 slot_0 完成格式迁移。</summary>
|
||||
private static IEnumerator RestoreLegacy(string savePath)
|
||||
{
|
||||
var saveData = SnapshotPersistence.ReadLegacySaveRoot(savePath);
|
||||
@@ -161,13 +161,16 @@ namespace AibisDream.SaveSystem
|
||||
var boolDict = saveData["boolDict"]?.ToObject<Dictionary<string, bool>>();
|
||||
YarnVariableStorage.Instance.SetAllVariables(floatDict, stringDict, boolDict);
|
||||
|
||||
if (saveData["systemData"] is JObject systemDataJson)
|
||||
if (saveData["systemData"] != null)
|
||||
{
|
||||
yield return DeepRepairDataRegistry.LoadByJson(systemDataJson);
|
||||
Debug.LogWarning(
|
||||
"[SaveRestoreOrchestrator] 旧档 systemData 段已无法还原(IData 已移除);" +
|
||||
"仅恢复 Yarn 变量并迁移为新快照格式。");
|
||||
}
|
||||
|
||||
var snapshot = SnapshotService.Capture();
|
||||
SlotManager.SaveToAutoSlot(snapshot, null);
|
||||
yield break;
|
||||
}
|
||||
|
||||
private static IEnumerator RestoreLegacyWithFlow(string savePath)
|
||||
@@ -180,8 +183,10 @@ namespace AibisDream.SaveSystem
|
||||
try
|
||||
{
|
||||
yield return FadeInForRestore();
|
||||
PrepareGameSessionForRestore();
|
||||
yield return RestoreLegacy(savePath);
|
||||
yield return null;
|
||||
FinalizeGameSessionAfterRestore();
|
||||
yield return FadeOutForRestore();
|
||||
}
|
||||
finally
|
||||
@@ -210,6 +215,8 @@ namespace AibisDream.SaveSystem
|
||||
{
|
||||
yield return FadeInForRestore();
|
||||
|
||||
PrepareGameSessionForRestore();
|
||||
|
||||
SnapshotRegistry.EnsureInitialized();
|
||||
yield return SnapshotRestore.RestoreState(YarnVariableStorage.Instance, snapshot, context);
|
||||
yield return SnapshotRestore.RestoreAnchor(snapshot, context);
|
||||
@@ -217,6 +224,8 @@ namespace AibisDream.SaveSystem
|
||||
AddRestoreLog("Phase 3.5: settle one frame");
|
||||
yield return null;
|
||||
|
||||
FinalizeGameSessionAfterRestore();
|
||||
|
||||
yield return FadeOutForRestore();
|
||||
}
|
||||
finally
|
||||
@@ -227,6 +236,55 @@ namespace AibisDream.SaveSystem
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读档前对齐「已进入游戏」的 UI 与输入状态。
|
||||
/// 编辑器测试工具等路径可能跳过 <see cref="GameLoopEnum.GameStart"/>,导致 StartPanel 未关闭、
|
||||
/// <see cref="GameManager.state.isInGame"/> 为 false,从而无法推进对话。
|
||||
/// </summary>
|
||||
private static void PrepareGameSessionForRestore()
|
||||
{
|
||||
AddRestoreLog("Prepare game session for restore");
|
||||
|
||||
var gameManager = GameManager.Instance;
|
||||
if (gameManager != null && !gameManager.state.isInGame)
|
||||
{
|
||||
EnumEventSystem.Global.Send(GameLoopEnum.GameStart);
|
||||
}
|
||||
|
||||
var ui = UIManager.Instance;
|
||||
if (ui != null)
|
||||
{
|
||||
ui.HidePanel<StartPanel>();
|
||||
ui.ShowPanel<MainPanel>();
|
||||
ui.HidePanel<ChapterPanel>();
|
||||
ui.HidePanel<SavesPanel>();
|
||||
ui.HidePanel<EndPanel>();
|
||||
}
|
||||
|
||||
if (gameManager != null && gameManager.state.isInPause)
|
||||
{
|
||||
gameManager.ContinueGame();
|
||||
}
|
||||
else
|
||||
{
|
||||
DialogUIManager.Instance?.OpenCanvas();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>读档完成后确保对话 Canvas 可用、退出暂停态。</summary>
|
||||
private static void FinalizeGameSessionAfterRestore()
|
||||
{
|
||||
AddRestoreLog("Finalize game session after restore");
|
||||
|
||||
DialogUIManager.Instance?.OpenCanvas();
|
||||
|
||||
var gameManager = GameManager.Instance;
|
||||
if (gameManager != null && gameManager.state.isInPause)
|
||||
{
|
||||
gameManager.ContinueGame();
|
||||
}
|
||||
}
|
||||
|
||||
private static IEnumerator FadeInForRestore()
|
||||
{
|
||||
AddRestoreLog("Begin restore fade in");
|
||||
|
||||
@@ -115,6 +115,9 @@ namespace AibisDream.SaveSystem
|
||||
}
|
||||
|
||||
yield return sceneLoader.LoadSceneAsync(snapshot.scene.sceneName);
|
||||
|
||||
// 再等一帧,等Awake执行完
|
||||
yield return null;
|
||||
}
|
||||
|
||||
private static void RestoreSceneSo(SaveSnapshot snapshot, SnapshotRestoreContext context)
|
||||
|
||||
Reference in New Issue
Block a user