From c38c2f75be751180e2c7e9f1ad0c73b7694f51b6 Mon Sep 17 00:00:00 2001 From: bottlefish <781230111@qq.com> Date: Wed, 15 Jul 2026 19:27:18 +0800 Subject: [PATCH] =?UTF-8?q?fix(save):=20=E4=BF=AE=E5=A4=8D=E8=B7=A8?= =?UTF-8?q?=E7=AB=A0=E8=8A=82=E5=AD=98=E6=A1=A3=E6=81=A2=E5=A4=8D=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scenes/Persistence.unity | 5 ++- Assets/Scripts/Game Loop/GameManager.cs | 17 ++++++++-- Assets/Scripts/SaveSystem/SnapshotRestore.cs | 34 ++++++++++++++------ 3 files changed, 44 insertions(+), 12 deletions(-) diff --git a/Assets/Scenes/Persistence.unity b/Assets/Scenes/Persistence.unity index e73561291..a7fd91499 100644 --- a/Assets/Scenes/Persistence.unity +++ b/Assets/Scenes/Persistence.unity @@ -2445,7 +2445,10 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: feee73ba51d6e1a4da81ed7f94ab4694, type: 3} m_Name: m_EditorClassIdentifier: - firstTalkSo: {fileID: 11400000, guid: 0bdbd8e46fa688e49a5a670b78b6f956, type: 2} + firstTalkSo: {fileID: 11400000, guid: 2f763a2c04ecafb4981379b7363f9791, type: 2} + additionalRestoreSceneSos: + - {fileID: 11400000, guid: aaef579ad8bdda542b503b40ce6773a8, type: 2} + - {fileID: 11400000, guid: 0bdbd8e46fa688e49a5a670b78b6f956, type: 2} --- !u!1 &749156594 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Game Loop/GameManager.cs b/Assets/Scripts/Game Loop/GameManager.cs index 12e898e30..393fa87f0 100644 --- a/Assets/Scripts/Game Loop/GameManager.cs +++ b/Assets/Scripts/Game Loop/GameManager.cs @@ -20,6 +20,9 @@ namespace AibisDream [Header("生产环境数据(一般不动)")] public TalkSceneSO firstTalkSo; + [Header("存档恢复补充章节")] + [SerializeField] private List additionalRestoreSceneSos = new(); + #endregion private const float MainMenuFadeDuration = 0.5f; @@ -333,9 +336,19 @@ namespace AibisDream return _totalSceneSos; } - public void SetSceneSoByName(string soName) + public bool SetSceneSoByName(string soName) { - _currentTalkSceneSo.Value = Array.Find(_totalSceneSos.ToArray(), so => so.name == soName); + var sceneSo = _totalSceneSos?.Find(so => so != null && so.name == soName); + sceneSo ??= additionalRestoreSceneSos?.Find(so => so != null && so.name == soName); + + if (sceneSo == null) + { + Debug.LogError($"[GameManager] 找不到章节 SO:{soName}"); + return false; + } + + _currentTalkSceneSo.Value = sceneSo; + return true; } public void StartDialog() diff --git a/Assets/Scripts/SaveSystem/SnapshotRestore.cs b/Assets/Scripts/SaveSystem/SnapshotRestore.cs index ecf97667a..4ddee700c 100644 --- a/Assets/Scripts/SaveSystem/SnapshotRestore.cs +++ b/Assets/Scripts/SaveSystem/SnapshotRestore.cs @@ -73,17 +73,22 @@ namespace AibisDream.SaveSystem if (!string.IsNullOrEmpty(snapshot.anchor.yarnProjectId)) { var sceneSo = GameManager.Instance?.GetCurrentTalkSceneSo(); - if (sceneSo?.yarnProject != null && sceneSo.yarnProject.name == snapshot.anchor.yarnProjectId) + if (sceneSo?.yarnProject == null) { - if (runner.YarnProject == null || runner.YarnProject.name != snapshot.anchor.yarnProjectId) - { - dialog.LoadDialog(sceneSo.yarnProject); - } + context.Error($"章节 {snapshot.anchor.sceneSoName} 没有可用的 YarnProject。"); + yield break; } - else if (runner.YarnProject != null && runner.YarnProject.name != snapshot.anchor.yarnProjectId) + + if (sceneSo.yarnProject.name != snapshot.anchor.yarnProjectId) { - context.Warn( - $"YarnProject 不匹配:当前 {runner.YarnProject.name},存档 {snapshot.anchor.yarnProjectId}"); + context.Error( + $"章节 YarnProject 不匹配:章节 {sceneSo.yarnProject.name},存档 {snapshot.anchor.yarnProjectId}"); + yield break; + } + + if (runner.YarnProject == null || runner.YarnProject.name != snapshot.anchor.yarnProjectId) + { + dialog.LoadDialog(sceneSo.yarnProject); } } @@ -97,6 +102,14 @@ namespace AibisDream.SaveSystem yield return runner.Stop(); } + if (runner.YarnProject == null + || !System.Array.Exists(runner.YarnProject.NodeNames, node => node == snapshot.anchor.nodeName)) + { + context.Error( + $"YarnProject {runner.YarnProject?.name ?? "none"} 不包含节点 {snapshot.anchor.nodeName}。"); + yield break; + } + yield return runner.StartDialogue(snapshot.anchor.nodeName); } @@ -144,7 +157,10 @@ namespace AibisDream.SaveSystem return; } - gameManager.SetSceneSoByName(snapshot.anchor.sceneSoName); + if (!gameManager.SetSceneSoByName(snapshot.anchor.sceneSoName)) + { + context.Error($"找不到章节 SO:{snapshot.anchor.sceneSoName},无法恢复 YarnProject。"); + } } ///