using System; using System.Collections; using UnityEngine; namespace AibisDream.SaveSystem { /// /// 快照提供者契约:将某一子系统的运行时状态转换为纯数据 DTO。 /// 还原侧由同步 / 异步子接口显式声明,避免 Provider 内部 fire-and-forget。 /// public interface ISnapshotProvider { /// /// 稳定显式 id,用作 的 key。 /// 见 ,不使用 C# 类型全名。 /// string SaveId { get; } /// /// 同阶段内的读档还原顺序。数值越小越先执行。 /// int RestoreOrder { get; } /// 从当前运行时捕获该子系统的快照 DTO;无可存内容时可返回 null。 object Capture(); } /// /// 同步快照还原 Provider。实现中不得启动 fire-and-forget 协程。 /// public interface ISyncSnapshotProvider : ISnapshotProvider { void Restore(object dto, SnapshotRestoreContext context); } /// /// 异步快照还原 Provider。所有必须等待的加载 / 状态切换须通过此协程暴露给编排层。 /// public interface IAsyncSnapshotProvider : ISnapshotProvider { IEnumerator RestoreAsync(object dto, SnapshotRestoreContext context); } /// /// 单次读档还原流程上下文。 /// public sealed class SnapshotRestoreContext { public SnapshotRestoreContext(SaveSnapshot snapshot, bool strictMode = false, Action logStep = null) { Snapshot = snapshot; StrictMode = strictMode; LogStep = logStep; } public SaveSnapshot Snapshot { get; } public bool StrictMode { get; } public Action LogStep { get; } public void Log(string message) { LogStep?.Invoke(message); Debug.Log($"[SnapshotRestore] {message}"); } public void Warn(string message) { LogStep?.Invoke($"WARN: {message}"); Debug.LogWarning($"[SnapshotRestore] {message}"); } public void Error(string message) { LogStep?.Invoke($"ERROR: {message}"); Debug.LogError($"[SnapshotRestore] {message}"); } } }