using System; using System.Collections.Generic; namespace AibisDream.SaveSystem { /// /// 当前快照 schema 的版本号。结构变更时递增。 /// public static class SaveSnapshotSchema { public const int CurrentVersion = 1; } /// /// 存档快照根对象:描述「进入可存节点那一刻」的完整游戏状态。 /// /// 与槽位/文件路径解耦;序列化后写入 JSON。对应需求§3 四分类: /// anchor(恢复锚点)、sections(宏观 scene/macro + 表现类)、yarnVariables、deepRepair(深度维修,P5)。 /// /// /// 宏观阶段(场景 / 章节 SO / YarnProject)不单独冗余存储,统一以 sections["scene"] / sections["macro"] /// 为唯一来源;槽位 UI 等需要摘要时通过 现算派生,避免重复字段漂移。 /// /// [Serializable] public class SaveSnapshot { /// 快照结构版本,对应 public int schemaVersion = SaveSnapshotSchema.CurrentVersion; /// 保存时的 Application.version public string gameVersion; /// 保存时间(本地),格式 yyyy-MM-dd HH:mm:ss public string savedAt; /// 当前场景(恢复的第一步)。 public SceneSnapshotDto scene = new(); /// 恢复锚点:章节、YarnProject 与节点,读档最后阶段重新进入。 public AnchorSnapshot anchor = new(); /// 全部 Yarn 运行时变量(来自 )。 public YarnVariablesSnapshot yarnVariables = new(); /// /// 各子系统表现类快照,key 为 中的稳定 id。 /// public Dictionary sections = new(); /// /// 深度维修段。P1 捕获时不写入(null);P5 按模块策略填充。 /// public DeepRepairSnapshot deepRepair; } /// /// 恢复锚点:包含宏观章节信息,读档最后阶段加载对话工程并重新 StartDialogue。 /// [Serializable] public class AnchorSnapshot { /// 当前章节 TalkSceneSO 名称,用于 public string sceneSoName; public string yarnProjectId; public string nodeName; } /// Yarn 变量三分组,与 Yarn Spinner 支持的类型一致。 [Serializable] public class YarnVariablesSnapshot { public Dictionary floats = new(); public Dictionary strings = new(); public Dictionary bools = new(); } #region Provider DTOs /// sections["scene"]:当前加载的场景。 [Serializable] public class SceneSnapshotDto { public string sceneName; } /// sections["env"]:环境时间/天气。 [Serializable] public class EnvironmentSnapshotDto { /// 枚举名。 public string curTime; /// 枚举名。 public string curWeather; public bool isInitialized; } /// sections["actor"]:场景中所有角色的逐项状态。 [Serializable] public class ActorSnapshotDto { public List actors = new(); } /// 单个角色的快照条目。 [Serializable] public class ActorEntrySnapshotDto { public string actorName; public string slotName; public string actorType; public string stateName; public float alpha; public float faceParam; } /// sections["audio"]:FMOD 音乐/SFX 终态与 AMB 状态(不记播放进度)。 [Serializable] public class AudioSnapshotDto { /// key → FMOD event path。 public Dictionary musicPaths = new(); public Dictionary sfxPaths = new(); /// 枚举名。 public string ambState; } /// /// Timeline 终/初态标记(决策 D1.1:不按时间轴逐帧还原)。 /// 序列化进 JSON 时使用字符串形式存入 。 /// public enum TimelinePlaybackPhase { AtStart, AtEnd, Stopped } /// sections["timeline"]:各 PlayableDirector 的终/初态。 [Serializable] public class TimelineSnapshotDto { public List entries = new(); } [Serializable] public class TimelineEntrySnapshotDto { public string directorName; public bool isActive; /// 的字符串名。 public string phase; /// 若由 Addressables 加载 Timeline,记录 key;否则为空。 public string loadedAddressableKey; } /// sections["screen"]:屏幕饱和度与演出淡入淡出遮罩。 [Serializable] public class ScreenSnapshotDto { /// Post-process Volume weight(0=正常,1=完全褪色)。 public float saturationWeight; /// /// 演出遮罩终态:true = 黑屏盖住(FadeIn 完成); /// false = 画面可见(FadeOut 完成或遮罩未启用)。不记录转场中间 alpha。 /// public bool isFadeScreenCovered; } /// sections["fix"]:Fix 场景宏观状态(FixStateMachine)。 [Serializable] public class FixSnapshotDto { /// 枚举名。 public string state; /// 状态参数(如 BodyModule 的 ModuleState 字符串)。 public string args; /// BodyModule 当前分组(Body/Head)。 public string moduleState; /// EyeSystem 当前颜色阶段。 public string eyeColorState; /// FixPanelSystem 是否已启动。 public bool isSystemOn; /// RepairSystemManager 当前激活的系统类型名。 public string currentRepairSystemType; } #endregion /// /// 从 根对象直接读取的宏观摘要(场景 / 章节 SO / YarnProject)。 /// /// scene 与 anchor 已提升到根对象,无需再从 sections 字典派生。 /// 槽位 / 「继续游戏」等 UI 在需要展示时调用 即可。 /// /// public readonly struct SaveSnapshotSummary { /// Addressable 场景 key(来自 )。 public readonly string SceneName; /// 当前 TalkSceneSO 的 asset 名称(来自 )。 public readonly string SceneSoName; /// 当前 YarnProject 的 name(来自 )。 public readonly string YarnProjectId; public SaveSnapshotSummary(string sceneName, string sceneSoName, string yarnProjectId) { SceneName = sceneName; SceneSoName = sceneSoName; YarnProjectId = yarnProjectId; } /// 从快照根对象直接读取宏观摘要。 public static SaveSnapshotSummary From(SaveSnapshot snapshot) { if (snapshot == null) { return new SaveSnapshotSummary(null, null, null); } var sceneName = snapshot.scene?.sceneName; var sceneSoName = snapshot.anchor?.sceneSoName; var yarnProjectId = snapshot.anchor?.yarnProjectId; return new SaveSnapshotSummary(sceneName, sceneSoName, yarnProjectId); } } }