57 lines
1.8 KiB
C#
57 lines
1.8 KiB
C#
using System.Collections;
|
|
using UnityEngine;
|
|
|
|
namespace AibisDream.SaveSystem
|
|
{
|
|
/// <summary>
|
|
/// sections["macro"]:章节 TalkSceneSO 与 YarnProject 绑定。
|
|
/// RestoreOrder=30,在场景与环境就绪后设置 GameManager 并 LoadDialog(不 Start 节点,锚点由 RestoreAnchor 负责)。
|
|
/// </summary>
|
|
public class MacroSnapshotProvider : ISnapshotProvider
|
|
{
|
|
public string SaveId => SnapshotProviderIds.Macro;
|
|
public int RestoreOrder => 30;
|
|
|
|
public object Capture()
|
|
{
|
|
var gameManager = GameManager.Instance;
|
|
var dialog = DialogController.Instance;
|
|
var yarnProject = dialog?.DialogueRunner?.YarnProject;
|
|
|
|
return new MacroSnapshotDto
|
|
{
|
|
sceneSoName = gameManager != null ? gameManager.GetSceneSoName() : null,
|
|
yarnProjectId = yarnProject != null ? yarnProject.name : null
|
|
};
|
|
}
|
|
|
|
public IEnumerator Restore(object dto)
|
|
{
|
|
if (dto is not MacroSnapshotDto macro)
|
|
{
|
|
yield break;
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(macro.sceneSoName))
|
|
{
|
|
GameManager.Instance.SetSceneSoByName(macro.sceneSoName);
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(macro.yarnProjectId))
|
|
{
|
|
var sceneSo = GameManager.Instance.GetCurrentTalkSceneSo();
|
|
if (sceneSo?.yarnProject != null && sceneSo.yarnProject.name == macro.yarnProjectId)
|
|
{
|
|
DialogController.Instance.LoadDialog(sceneSo.yarnProject);
|
|
}
|
|
else
|
|
{
|
|
Debug.LogWarning($"[MacroSnapshotProvider] 无法匹配 YarnProject: {macro.yarnProjectId}");
|
|
}
|
|
}
|
|
|
|
yield break;
|
|
}
|
|
}
|
|
}
|