41 lines
1.5 KiB
C#
41 lines
1.5 KiB
C#
using System.Collections;
|
||
|
||
namespace AibisDream.SaveSystem
|
||
{
|
||
/// <summary>
|
||
/// 快照层对外 API:Capture / Restore,不涉及文件与 UI。
|
||
/// 游戏逻辑应优先使用 <see cref="SaveRestoreOrchestrator"/> 完成存读档流程。
|
||
/// </summary>
|
||
public static class SnapshotService
|
||
{
|
||
/// <summary>捕获当前运行时快照。</summary>
|
||
/// <param name="triggerNodeName">见 <see cref="SnapshotCapture.Capture"/>。</param>
|
||
public static SaveSnapshot Capture(string triggerNodeName = null)
|
||
{
|
||
SnapshotRegistry.EnsureInitialized();
|
||
return SnapshotCapture.Capture(YarnVariableStorage.Instance, triggerNodeName);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 还原快照状态;默认继续执行 <see cref="SnapshotRestore.RestoreAnchor"/>。
|
||
/// 业务读档流程应优先使用 <see cref="SaveRestoreOrchestrator"/>,以获得黑屏与自动存档抑制。
|
||
/// </summary>
|
||
public static IEnumerator Restore(SaveSnapshot snapshot, bool restoreAnchor = true)
|
||
{
|
||
if (snapshot == null)
|
||
{
|
||
yield break;
|
||
}
|
||
|
||
SnapshotRegistry.EnsureInitialized();
|
||
var context = new SnapshotRestoreContext(snapshot);
|
||
yield return SnapshotRestore.RestoreState(YarnVariableStorage.Instance, snapshot, context);
|
||
|
||
if (restoreAnchor)
|
||
{
|
||
yield return SnapshotRestore.RestoreAnchor(snapshot, context);
|
||
}
|
||
}
|
||
}
|
||
}
|