diff --git a/Assets/_Project/Scenes/Intro/Prologue.unity b/Assets/_Project/Scenes/Intro/Prologue.unity index 7598fa3..3e52981 100644 --- a/Assets/_Project/Scenes/Intro/Prologue.unity +++ b/Assets/_Project/Scenes/Intro/Prologue.unity @@ -291,8 +291,8 @@ Camera: m_GameObject: {fileID: 348178466} m_Enabled: 1 serializedVersion: 2 - m_ClearFlags: 1 - m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0} + m_ClearFlags: 2 + m_BackGroundColor: {r: 0, g: 0, b: 0, a: 1} m_projectionMatrixMode: 1 m_GateFitMode: 2 m_FOVAxisMode: 0 @@ -382,7 +382,7 @@ VideoPlayer: m_TargetMaterialRenderer: {fileID: 0} m_TargetMaterialProperty: m_RenderMode: 2 - m_AspectRatio: 2 + m_AspectRatio: 3 m_DataSource: 0 m_TimeUpdateMode: 2 m_PlaybackSpeed: 1 @@ -427,6 +427,7 @@ GameObject: - component: {fileID: 703046132} - component: {fileID: 703046134} - component: {fileID: 703046133} + - component: {fileID: 703046135} m_Layer: 5 m_Name: 'BackgroundVideo ' m_TagString: Untagged @@ -449,7 +450,7 @@ RectTransform: m_Father: {fileID: 2040686082} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} - m_AnchorMax: {x: 1, y: 1} + m_AnchorMax: {x: 0, y: 0} m_AnchoredPosition: {x: 0, y: 0} m_SizeDelta: {x: 0, y: 0} m_Pivot: {x: 0.5, y: 0.5} @@ -488,6 +489,20 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 703046131} m_CullTransparentMesh: 1 +--- !u!114 &703046135 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 703046131} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 86710e43de46f6f4bac7c8e50813a599, type: 3} + m_Name: + m_EditorClassIdentifier: + m_AspectMode: 3 + m_AspectRatio: 1.7777778 --- !u!1 &704261845 GameObject: m_ObjectHideFlags: 0 @@ -654,7 +669,7 @@ MonoBehaviour: - video: {fileID: 32900000, guid: e2c5bd66aa963c84491f643b037a6bce, type: 3} text: "\t\u8774\u8776\u843D\u4E86\u4E0B\u53BB\u3002\u5B83\u6CBE\u4E86\u4E00\u4E0B\u3002\r\n\r\n\t\u6CA1\u6709\u58F0\u97F3\u3002\u6CA1\u6709\u88C2\u5F00\u3002\u53EA\u662F\u4E00\u6EF4\u871C\u843D\u5728\u4E86\u8774\u8776\u7684\u89E6\u89D2\u4E0A\u3002\r" illustration: {fileID: 0} - textOffset: {x: -702, y: -134} + textOffset: {x: -686, y: -134} textBoxSize: {x: 500, y: 200} textAlignment: 513 textColor: {r: 0.09803922, g: 0.050980393, b: 0.02745098, a: 1} @@ -668,7 +683,7 @@ MonoBehaviour: - video: {fileID: 32900000, guid: 4e401322bf2b1984f93e4f9d5fba6121, type: 3} text: "\t\u8424\u706B\u866B\u7684\u89E6\u89D2\u78B0\u4E86\u4E0A\u53BB\u3002\u5B83\u4E5F\u6CBE\u4E86\u4E00\u4E0B\u3002\r" illustration: {fileID: 0} - textOffset: {x: 469, y: -485} + textOffset: {x: 469, y: -416} textBoxSize: {x: 700, y: 200} textAlignment: 513 textColor: {r: 1, g: 1, b: 1, a: 1} @@ -717,7 +732,7 @@ MonoBehaviour: - video: {fileID: 32900000, guid: 88ab7a17e53456a4798070b4aaa0268e, type: 3} text: "\t\u4F46\u8D70\u5230\u56ED\u5B50\u53E6\u4E00\u5934\u65F6\uFF0C\u6211\u5728\u667A\u6167\u6811\u7684\u6839\u65C1\uFF0C\u53C8\u770B\u89C1\u4E86\u4E00\u7C92\u6697\u7EA2\u8272\u7684\u5149\u3002\u4E24\u7C92\u5149\uFF0C\u9694\u7740\u4E00\u6574\u7247\u56ED\u5B50\uFF0C\u5374\u50CF\u662F\u540C\u4E00\u6837\u4E1C\u897F\u5206\u6210\u4E86\u4E24\u534A\u3002\r" illustration: {fileID: 0} - textOffset: {x: 590, y: 234} + textOffset: {x: 586, y: 234} textBoxSize: {x: 700, y: 200} textAlignment: 513 textColor: {r: 0.09803922, g: 0.050980393, b: 0.02745098, a: 1} @@ -883,6 +898,81 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1254873707} m_CullTransparentMesh: 1 +--- !u!1 &1485101073 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1485101074} + - component: {fileID: 1485101076} + - component: {fileID: 1485101075} + m_Layer: 5 + m_Name: VideoLetterbox + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &1485101074 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1485101073} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 2040686082} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 1, y: 1} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 0, y: 0} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &1485101075 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1485101073} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 0, g: 0, b: 0, a: 1} + m_RaycastTarget: 0 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_Sprite: {fileID: 0} + m_Type: 0 + m_PreserveAspect: 0 + m_FillCenter: 1 + m_FillMethod: 4 + m_FillAmount: 1 + m_FillClockwise: 1 + m_FillOrigin: 0 + m_UseSpriteMesh: 0 + m_PixelsPerUnitMultiplier: 1 +--- !u!222 &1485101076 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1485101073} + m_CullTransparentMesh: 1 --- !u!1 &1553228418 GameObject: m_ObjectHideFlags: 0 @@ -1183,11 +1273,11 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 0cd44c1031e13a943bb63640046fad76, type: 3} m_Name: m_EditorClassIdentifier: - m_UiScaleMode: 0 + m_UiScaleMode: 1 m_ReferencePixelsPerUnit: 100 m_ScaleFactor: 1 - m_ReferenceResolution: {x: 800, y: 600} - m_ScreenMatchMode: 0 + m_ReferenceResolution: {x: 1920, y: 1080} + m_ScreenMatchMode: 1 m_MatchWidthOrHeight: 0 m_PhysicalUnit: 3 m_FallbackScreenDPI: 96 @@ -1229,6 +1319,7 @@ RectTransform: m_LocalScale: {x: 0, y: 0, z: 0} m_ConstrainProportionsScale: 0 m_Children: + - {fileID: 1485101074} - {fileID: 703046132} - {fileID: 2018148223} - {fileID: 1816586272} diff --git a/Assets/_Project/Scripts/Editor/Persistence.meta b/Assets/_Project/Scripts/Editor/Persistence.meta new file mode 100644 index 0000000..39cf574 --- /dev/null +++ b/Assets/_Project/Scripts/Editor/Persistence.meta @@ -0,0 +1,5 @@ +fileFormatVersion: 2 +guid: 3c196fbce2544b05ba7ee784884665ad +folderAsset: yes +DefaultImporter: + externalObjects: {} diff --git a/Assets/_Project/Scripts/Editor/Persistence/SaveDataDebugWindow.cs b/Assets/_Project/Scripts/Editor/Persistence/SaveDataDebugWindow.cs new file mode 100644 index 0000000..6ab5be3 --- /dev/null +++ b/Assets/_Project/Scripts/Editor/Persistence/SaveDataDebugWindow.cs @@ -0,0 +1,231 @@ +#if UNITY_EDITOR +#nullable enable +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text.RegularExpressions; +using GeminiLab.Core; +using UnityEditor; +using UnityEngine; + +namespace GeminiLab.EditorTools +{ + public sealed class SaveDataDebugWindow : EditorWindow + { + private bool _developer = true; + private bool _player; + private bool _chat = true; + private bool _progress = true; + private Vector2 _scroll; + private string _lastBackup = ""; + private string _message = ""; + + [MenuItem("Tools/Gemini-Lab/Save Data Debug")] + public static void Open() + { + var window = GetWindow("存档调试"); + window.minSize = new Vector2(520, 440); + } + + private void OnEnable() + { + _developer = DevMode.Active; + _player = !DevMode.Active; + } + + private void OnGUI() + { + EditorGUILayout.LabelField("存档清理", EditorStyles.boldLabel); + EditorGUILayout.SelectableLabel(Application.persistentDataPath, EditorStyles.textField, GUILayout.Height(22)); + EditorGUILayout.HelpBox("先退出 Play,再清理。下次进入 Play 才会使用新档。公寓新手引导随存档一起重置;音量、语言和窗口设置保留。", MessageType.Info); + bool busy = EditorApplication.isPlayingOrWillChangePlaymode || EditorApplication.isCompiling || EditorApplication.isUpdating; + using (new EditorGUI.DisabledScope(busy)) + { + _developer = EditorGUILayout.ToggleLeft("开发存档 Saves-Dev(所有槽位、家具布局)", _developer); + _player = EditorGUILayout.ToggleLeft("玩家存档 Saves(所有槽位、家具布局)", _player); + _chat = EditorGUILayout.ToggleLeft("聊天记录 chat_history.json(两种模式共用)", _chat); + _progress = EditorGUILayout.ToggleLeft("全局进度:序章、跨日记录、调试日期、许愿记录(两种模式共用)", _progress); + try + { + var files = SaveDataDebugStorage.Preview(Application.persistentDataPath, _developer, _player, _chat); + EditorGUILayout.LabelField($"待清理文件:{files.Length}"); + _scroll = EditorGUILayout.BeginScrollView(_scroll, GUILayout.MinHeight(90)); + foreach (string file in files) EditorGUILayout.LabelField(file); + EditorGUILayout.EndScrollView(); + using (new EditorGUI.DisabledScope(files.Length == 0 && !_progress)) + { + if (GUILayout.Button("备份并清理所选存档", GUILayout.Height(30))) Clear(false, files.Length); + } + if (GUILayout.Button("仅重置序章播放标记")) Clear(true, 0); + } + catch (Exception ex) { EditorGUILayout.HelpBox(ex.Message, MessageType.Error); } + } + if (busy) EditorGUILayout.HelpBox("运行、切换 Play 或编译/导入时不能清理存档。", MessageType.Warning); + if (!string.IsNullOrEmpty(_message)) EditorGUILayout.HelpBox(_message, MessageType.Info); + if (GUILayout.Button("打开存档目录")) EditorUtility.RevealInFinder(Application.persistentDataPath); + if (!string.IsNullOrEmpty(_lastBackup) && GUILayout.Button("打开本次备份")) EditorUtility.RevealInFinder(_lastBackup); + } + + private void Clear(bool prologueOnly, int fileCount) + { + string detail = prologueOnly ? "仅重置序章播放标记,保留全部存档。" : $"清理预览中的 {fileCount} 个文件。" + (_progress ? "同时重置勾选的全局进度。" : "保留全局进度。"); + if (!EditorUtility.DisplayDialog("确认清理", detail + "\n\n文件及原进度键会先备份到存档目录内的 SaveDebugBackups。", "备份并清理", "取消")) return; + try + { + _lastBackup = SaveDataDebugStorage.Clear(Application.persistentDataPath, + !prologueOnly && _developer, !prologueOnly && _player, !prologueOnly && _chat, + !prologueOnly && _progress, prologueOnly); + _message = "清理完成。下次从 Boot 启动可验证开局流程。\n备份:" + _lastBackup; + Debug.Log("[SaveDataDebug] 清理完成,备份:" + _lastBackup); + } + catch (Exception ex) + { + _message = "清理未完成:" + ex.Message; + Debug.LogException(ex); + } + } + } + + /// 仅处理项目已知的存档文件;原文件移入备份,发生异常时移回。 + public static class SaveDataDebugStorage + { + private static readonly Regex SlotFile = new("^[A-Za-z0-9_-]+\\.sav(?:\\.tmp|\\.bak)?$", RegexOptions.IgnoreCase); + private static readonly string[] IntKeys = { "HasPlayedPrologue", "GeminiLab.Debug.ClockOffsetDays" }; + private static readonly string[] StringKeys = { "GeminiLab.DailyReset.LastDate", "geminilab.worldmap.wishes.v1" }; + + [Serializable] public sealed class Preference + { + public string key = ""; + public bool exists; + public bool isInt; + public int intValue; + public string stringValue = ""; + } + + [Serializable] public sealed class BackupManifest + { + public string sourceRoot = ""; + public string createdUtc = ""; + public string status = "prepared"; + public string[] files = Array.Empty(); + public Preference[] preferences = Array.Empty(); + } + + public static string[] Preview(string root, bool developer, bool player, bool chat) + { + root = ValidateRoot(root); + var files = new List(); + foreach (string directory in new[] { developer ? "Saves-Dev" : "", player ? "Saves" : "" }) + { + if (directory.Length == 0) continue; + string path = SafePath(root, directory); + if (!Directory.Exists(path)) continue; + foreach (string file in Directory.GetFiles(path).OrderBy(x => x, StringComparer.Ordinal)) + { + if (!SlotFile.IsMatch(Path.GetFileName(file))) continue; + string relative = directory + "/" + Path.GetFileName(file); + SafePath(root, relative); + files.Add(relative); + } + } + if (chat && File.Exists(SafePath(root, "chat_history.json"))) files.Add("chat_history.json"); + return files.ToArray(); + } + + public static string Clear(string root, bool developer, bool player, bool chat, bool progress, bool prologueOnly = false) + { + if (EditorApplication.isPlayingOrWillChangePlaymode || EditorApplication.isCompiling || EditorApplication.isUpdating) + throw new InvalidOperationException("请退出 Play 并等待编译和导入结束。"); + root = ValidateRoot(root); + var manifest = new BackupManifest + { + sourceRoot = root, + createdUtc = DateTime.UtcNow.ToString("o"), + files = Preview(root, developer && !prologueOnly, player && !prologueOnly, chat && !prologueOnly), + preferences = CapturePreferences(progress && !prologueOnly, prologueOnly) + }; + string backup = SafePath(root, "SaveDebugBackups/" + DateTime.UtcNow.ToString("yyyyMMdd-HHmmss-fff") + "-" + Guid.NewGuid().ToString("N")); + Directory.CreateDirectory(backup); + string manifestPath = Path.Combine(backup, "manifest.json"); + File.WriteAllText(manifestPath, JsonUtility.ToJson(manifest, true)); + var moved = new List(); + try + { + foreach (string relative in manifest.files) + { + string source = SafePath(root, relative); + string destination = SafePath(backup, relative); + Directory.CreateDirectory(Path.GetDirectoryName(destination)!); + File.Move(source, destination); + moved.Add(relative); + } + foreach (var pref in manifest.preferences) PlayerPrefs.DeleteKey(pref.key); + if (manifest.preferences.Length > 0) PlayerPrefs.Save(); + manifest.status = "completed"; + File.WriteAllText(manifestPath, JsonUtility.ToJson(manifest, true)); + return backup; + } + catch (Exception error) + { + // 回滚不覆盖同时出现的新文件;即使回滚失败,原文件仍在备份目录中。 + var errors = new List { error }; + foreach (string relative in moved.AsEnumerable().Reverse()) + { + try { File.Move(SafePath(backup, relative), SafePath(root, relative)); } + catch (Exception rollbackError) { errors.Add(rollbackError); } + } + try + { + foreach (var pref in manifest.preferences) + { + if (!pref.exists) PlayerPrefs.DeleteKey(pref.key); + else if (pref.isInt) PlayerPrefs.SetInt(pref.key, pref.intValue); + else PlayerPrefs.SetString(pref.key, pref.stringValue); + } + if (manifest.preferences.Length > 0) PlayerPrefs.Save(); + } + catch (Exception rollbackError) { errors.Add(rollbackError); } + throw new AggregateException("清理失败,已尝试恢复原数据。备份位置:" + backup, errors); + } + } + + private static Preference[] CapturePreferences(bool progress, bool prologueOnly) + { + var result = new List(); + foreach (string key in prologueOnly ? new[] { "HasPlayedPrologue" } : progress ? IntKeys : Array.Empty()) + result.Add(new Preference { key = key, exists = PlayerPrefs.HasKey(key), isInt = true, intValue = PlayerPrefs.GetInt(key) }); + if (progress) + foreach (string key in StringKeys) + result.Add(new Preference { key = key, exists = PlayerPrefs.HasKey(key), stringValue = PlayerPrefs.GetString(key) }); + return result.ToArray(); + } + + private static string ValidateRoot(string root) + { + if (string.IsNullOrWhiteSpace(root) || !Path.IsPathRooted(root)) throw new ArgumentException("存档根目录必须是绝对路径。"); + string full = Path.GetFullPath(root).TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); + if (string.Equals(full, Path.GetPathRoot(full)?.TrimEnd(Path.DirectorySeparatorChar), StringComparison.OrdinalIgnoreCase)) + throw new ArgumentException("不能将磁盘根目录作为存档目录。"); + RejectLinks(full); + return full; + } + + private static string SafePath(string root, string relative) + { + string full = Path.GetFullPath(Path.Combine(root, relative)); + if (!full.StartsWith(root + Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase)) + throw new IOException("目标不在存档目录内。"); + RejectLinks(full); + return full; + } + + private static void RejectLinks(string path) + { + for (string? current = path; !string.IsNullOrEmpty(current); current = Path.GetDirectoryName(current)) + if ((File.Exists(current) || Directory.Exists(current)) && (File.GetAttributes(current) & FileAttributes.ReparsePoint) != 0) + throw new IOException("为避免越界,不处理符号链接或目录联接:" + current); + } + } +} +#endif diff --git a/Assets/_Project/Scripts/Editor/Persistence/SaveDataDebugWindow.cs.meta b/Assets/_Project/Scripts/Editor/Persistence/SaveDataDebugWindow.cs.meta new file mode 100644 index 0000000..9e4e3ed --- /dev/null +++ b/Assets/_Project/Scripts/Editor/Persistence/SaveDataDebugWindow.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ec500f32f6164168bea982bdd46db3af +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} diff --git a/Assets/_Project/Tests/EditMode/SaveDataDebugTests.cs b/Assets/_Project/Tests/EditMode/SaveDataDebugTests.cs new file mode 100644 index 0000000..7f3251d --- /dev/null +++ b/Assets/_Project/Tests/EditMode/SaveDataDebugTests.cs @@ -0,0 +1,142 @@ +#if UNITY_EDITOR +#nullable enable +using System; +using System.IO; +using System.Linq; +using System.Reflection; +using NUnit.Framework; + +namespace GeminiLab.Tests.EditMode +{ + public sealed class SaveDataDebugTests + { + private string _root = ""; + private Type _storage = null!; + + [SetUp] + public void SetUp() + { + _root = Path.Combine(Path.GetTempPath(), "GeminiLabSaveDebugTests", Guid.NewGuid().ToString("N")); + Directory.CreateDirectory(_root); + _storage = AppDomain.CurrentDomain.GetAssemblies() + .Select(a => a.GetType("GeminiLab.EditorTools.SaveDataDebugStorage")) + .First(t => t != null)!; + } + + [TearDown] + public void TearDown() + { + string expectedParent = Path.GetFullPath(Path.Combine(Path.GetTempPath(), "GeminiLabSaveDebugTests")) + Path.DirectorySeparatorChar; + Assert.That(Path.GetFullPath(_root).StartsWith(expectedParent, StringComparison.OrdinalIgnoreCase), Is.True); + if (Directory.Exists(_root)) Directory.Delete(_root, true); + } + + [Test] + public void Preview_OnlyIncludesKnownFilesInSelectedDirectories() + { + Write("Saves-Dev/autosave.sav"); + Write("Saves-Dev/autosave.sav.tmp"); + Write("Saves-Dev/autosave.sav.bak"); + Write("Saves-Dev/readme.txt"); + Write("Saves-Dev/nested/slot1.sav"); + Write("Saves/slot1.sav"); + Write("chat_history.json"); + Write("SaveDebugBackups/old/Saves-Dev/autosave.sav"); + var paths = (string[])Call("Preview", _root, true, false, false); + Assert.That(paths, Is.EquivalentTo(new[] { "Saves-Dev/autosave.sav", "Saves-Dev/autosave.sav.tmp", "Saves-Dev/autosave.sav.bak" })); + } + + [Test] + public void Clear_MovesExactBytesToBackupAndPreservesOtherData() + { + byte[] bytes = { 0, 1, 255, 34, 67 }; + Write("Saves-Dev/autosave.sav"); + File.WriteAllBytes(Path.Combine(_root, "Saves-Dev/autosave.sav"), bytes); + Write("Saves/slot1.sav", "player"); + Write("chat_history.json", "chat"); + Write("Saves-Dev/notes.txt", "keep"); + string backup = Clear(true, false, false); + Assert.That(File.Exists(Path.Combine(_root, "Saves-Dev/autosave.sav")), Is.False); + Assert.That(File.ReadAllBytes(Path.Combine(backup, "Saves-Dev/autosave.sav")), Is.EqualTo(bytes)); + Assert.That(File.ReadAllText(Path.Combine(_root, "Saves/slot1.sav")), Is.EqualTo("player")); + Assert.That(File.ReadAllText(Path.Combine(_root, "chat_history.json")), Is.EqualTo("chat")); + Assert.That(File.ReadAllText(Path.Combine(_root, "Saves-Dev/notes.txt")), Is.EqualTo("keep")); + Assert.That(File.ReadAllText(Path.Combine(backup, "manifest.json")), Does.Contain("completed")); + } + + [Test] + public void ChatOnly_DoesNotTouchSaveSlots() + { + Write("chat_history.json", "chat"); + Write("Saves-Dev/furniture_layout.sav", "layout"); + string backup = Clear(false, false, true); + Assert.That(File.ReadAllText(Path.Combine(backup, "chat_history.json")), Is.EqualTo("chat")); + Assert.That(File.Exists(Path.Combine(_root, "chat_history.json")), Is.False); + Assert.That(File.ReadAllText(Path.Combine(_root, "Saves-Dev/furniture_layout.sav")), Is.EqualTo("layout")); + } + + [Test] + public void BackupCreationFailure_LeavesSourceUntouched() + { + Write("Saves-Dev/autosave.sav", "original"); + Write("SaveDebugBackups", "blocks directory creation"); + Assert.Throws(() => Clear(true, false, false)); + Assert.That(File.ReadAllText(Path.Combine(_root, "Saves-Dev/autosave.sav")), Is.EqualTo("original")); + } + + [Test] + [Platform("Win")] + public void MoveFailure_RollsBackEarlierFiles() + { + Write("Saves-Dev/a.sav", "a"); + Write("Saves-Dev/z.sav", "z"); + using (new FileStream(Path.Combine(_root, "Saves-Dev/z.sav"), FileMode.Open, FileAccess.Read, FileShare.None)) + Assert.Throws(() => Clear(true, false, false)); + Assert.That(File.ReadAllText(Path.Combine(_root, "Saves-Dev/a.sav")), Is.EqualTo("a")); + Assert.That(File.ReadAllText(Path.Combine(_root, "Saves-Dev/z.sav")), Is.EqualTo("z")); + } + + [Test] + public void RepeatedClear_PreservesPriorBackup() + { + Write("Saves-Dev/autosave.sav", "first"); + string first = Clear(true, true, true); + string second = Clear(true, true, true); + Assert.That(first, Is.Not.EqualTo(second)); + Assert.That(File.ReadAllText(Path.Combine(first, "Saves-Dev/autosave.sav")), Is.EqualTo("first")); + Assert.That((string[])Call("Preview", _root, true, true, true), Is.Empty); + } + + [Test] + public void Preview_RejectsRelativeAndDriveRoots() + { + Assert.Throws(() => Call("Preview", "relative", true, true, true)); + Assert.Throws(() => Call("Preview", Path.GetPathRoot(_root)!, true, true, true)); + } + + [Test] + public void PreferenceScope_ContainsOnlyKnownProgressKeys() + { + var capture = _storage.GetMethod("CapturePreferences", BindingFlags.NonPublic | BindingFlags.Static)!; + var prefs = (Array)capture.Invoke(null, new object[] { true, false })!; + string[] keys = prefs.Cast().Select(p => (string)p.GetType().GetField("key")!.GetValue(p)!).ToArray(); + Assert.That(keys, Is.EquivalentTo(new[] { "HasPlayedPrologue", "GeminiLab.Debug.ClockOffsetDays", "GeminiLab.DailyReset.LastDate", "geminilab.worldmap.wishes.v1" })); + var prologue = (Array)capture.Invoke(null, new object[] { false, true })!; + Assert.That(prologue.Length, Is.EqualTo(1)); + Assert.That(prologue.GetValue(0)!.GetType().GetField("key")!.GetValue(prologue.GetValue(0)), Is.EqualTo("HasPlayedPrologue")); + } + + private string Clear(bool developer, bool player, bool chat) => + (string)Call("Clear", _root, developer, player, chat, false, false); + + private object Call(string name, params object[] args) => _storage.GetMethod(name)!.Invoke(null, args)!; + + private void Write(string relative, string content = "data") + { + string path = Path.Combine(_root, relative); + Directory.CreateDirectory(Path.GetDirectoryName(path)!); + File.WriteAllText(path, content); + } + } +} +#endif diff --git a/Assets/_Project/Tests/EditMode/SaveDataDebugTests.cs.meta b/Assets/_Project/Tests/EditMode/SaveDataDebugTests.cs.meta new file mode 100644 index 0000000..ab36773 --- /dev/null +++ b/Assets/_Project/Tests/EditMode/SaveDataDebugTests.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 3afb519f913f4589b642fadb22596af0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} diff --git a/docs/ai-memory/gemini-lab-memory-main.md b/docs/ai-memory/gemini-lab-memory-main.md index 7eb155f..cb84b4e 100644 --- a/docs/ai-memory/gemini-lab-memory-main.md +++ b/docs/ai-memory/gemini-lab-memory-main.md @@ -1,5 +1,15 @@ # Gemini-Lab Memory Main +## 2026-09-11 序章视频适配 + +- Prologue 预置1920×1080自适应画布、16:9完整视频显示及黑色留边;3处文字偏移收进安全边界。未改运行时剧情代码。 +- 实际Play三种窗口比例均无视频越界;Scene/Play尺寸一致。验证范围见 `docs/prologue-viewport-fit.md`。 + +## 2026-09-11 存档清理调试入口 + +- 新增编辑器菜单 `Tools/Gemini-Lab/Save Data Debug`:预览并备份清理所选开发/玩家存档、聊天和四项全局进度;可仅重置序章标记。运行、编译和导入时禁用,保留设置与原始备份。 +- Unity 编译、窗口菜单打开和 8 项专项 EditMode 测试通过。使用范围、恢复方式和验证见 `docs/save-data-debug-tool.md`;本任务未清理真实存档。 + ## 2026-09-11 家具悬停与公寓引导 - 已保存 38 件家具的 Sprite 网格悬停、金色描边与固定文字提示,保留原点击链和物理占地;描边宽度 4,亮金黄色、不透明。 diff --git a/docs/ai-memory/gemini-lab-project-file-guide.md b/docs/ai-memory/gemini-lab-project-file-guide.md index b633713..6238be8 100644 --- a/docs/ai-memory/gemini-lab-project-file-guide.md +++ b/docs/ai-memory/gemini-lab-project-file-guide.md @@ -1,5 +1,16 @@ # Gemini-Lab Project File Guide +## 序章视频适配 + +- `Assets/_Project/Scenes/Intro/Prologue.unity`:CanvasScaler、视频AspectRatioFitter、VideoPlayer FitInside及预置VideoLetterbox。 +- `docs/prologue-viewport-fit.md`:参数与验证范围。 + +## 存档清理工具 + +- `Assets/_Project/Scripts/Editor/Persistence/SaveDataDebugWindow.cs`:编辑器窗口、范围检查、备份和失败恢复。 +- `Assets/_Project/Tests/EditMode/SaveDataDebugTests.cs`:临时目录专项测试。 +- `docs/save-data-debug-tool.md`:使用入口与精确清理范围。 + ## 2026-09-11 公寓引导与悬停入口 - `docs/apartment-onboarding.md`:实际行为、资源、编辑入口、验证证据与待验收项。 diff --git a/docs/ai-memory/memory-index.paths.txt b/docs/ai-memory/memory-index.paths.txt index 2c4a27c..a4c346f 100644 --- a/docs/ai-memory/memory-index.paths.txt +++ b/docs/ai-memory/memory-index.paths.txt @@ -332,3 +332,7 @@ Assets/_Project/Scripts/Modules/Persistence/ApartmentTutorialProgress.cs Assets/_Project/Scripts/Editor/SceneBootstrap/ApartmentOnboardingAuthoring.cs Assets/_Project/Tests/EditMode/ApartmentOnboardingTests.cs Assets/_Project/Art/UI/ApartmentOnboarding/README.md +docs/save-data-debug-tool.md +Assets/_Project/Scripts/Editor/Persistence/SaveDataDebugWindow.cs +Assets/_Project/Tests/EditMode/SaveDataDebugTests.cs +docs/prologue-viewport-fit.md diff --git a/docs/manual-validation-checklist.md b/docs/manual-validation-checklist.md index f0cac39..ac3fa49 100644 --- a/docs/manual-validation-checklist.md +++ b/docs/manual-validation-checklist.md @@ -1,5 +1,15 @@ # Gemini-Lab 人工验证清单 +## 序章窗口适配(2026-09-11) + +- 已验证:Play首段视频及文字,1329×600、16:9、16:10的视频矩形都在屏幕内且比例为16:9;当前窗口Scene/Play尺寸一致。 +- 20段文字框的参考画布安全范围已静态检查。完整20段播放和独立构建未验收。 + +## 存档清理工具(2026-09-11) + +- 已验证:Unity 编译、窗口菜单打开、8 项临时目录 EditMode 测试通过,覆盖范围排除、备份内容、失败回滚与重复清理。未执行真实存档清理。 +- 人工验收:退出 Play 后核对文件预览;确认清理的目录与共用进度;下次从 Boot 启动并进入空间系统验证新档和引导。真实存档清理需由使用者在窗口主动确认。 + ## 2026-09-11 家具悬停和公寓引导 - [x] 实际使用工程:38 项 EditMode(10 项新功能 + 28 项室内小门)通过。 diff --git a/docs/project-structure-overview.md b/docs/project-structure-overview.md index 597e43b..7880884 100644 --- a/docs/project-structure-overview.md +++ b/docs/project-structure-overview.md @@ -1,5 +1,13 @@ # Gemini-Lab 项目结构总览 +## 序章画布适配 + +- Prologue 的 Canvas 使用1920×1080参考画布;BackgroundVideo预置16:9 FitInParent,VideoLetterbox在其下方提供全屏黑底。具体设置见 `docs/prologue-viewport-fit.md`。 + +## 存档调试工具 + +- `Assets/_Project/Scripts/Editor/Persistence/` 保存存档调试窗口,菜单 `Tools/Gemini-Lab/Save Data Debug`;不需要 Scene 节点或运行时挂载。备份写入 persistentDataPath 下的 `SaveDebugBackups`,不进入 Assets。详见 `docs/save-data-debug-tool.md`。 + ## 2026-09-11 公寓引导增量 - `Apartment_Main` 新增 `ApartmentOnboarding`,内部有 `Btn_ApartmentTutorialOpen`、`Panel_ApartmentTutorial/TutorialCard` 与 `TutorialPage_1..6`。面板默认关闭,六页图文资源已保存。 diff --git a/docs/prologue-viewport-fit.md b/docs/prologue-viewport-fit.md new file mode 100644 index 0000000..cc2893e --- /dev/null +++ b/docs/prologue-viewport-fit.md @@ -0,0 +1,18 @@ +# 序章窗口适配 + +2026-09-11:针对视频大小与窗口不匹配,修改 `Assets/_Project/Scenes/Intro/Prologue.unity` 的预置布局。 + +- 28 个源视频均为 1280×720,现有视频 RenderTexture 为 1920×1080。保留视频和资源引用。 +- CanvasScaler 从固定像素改为 Scale With Screen Size,参考尺寸 1920×1080、Screen Match Mode = Expand。较小窗口按比例缩小图文。 +- `Canvas/BackgroundVideo `(原节点名末尾有空格)新增 AspectRatioFitter:Fit In Parent,16:9;VideoPlayer 使用 Fit Inside。完整显示视频,非16:9窗口留边,不裁剪或拉伸。 +- `Canvas/VideoLetterbox` 是视频下方预置的全屏黑色 Image,不拦截输入;避免附加 Boot 摄像机的蓝色背景影响留边。 +- 第7、9、16段文字位置收进1920×1080参考画布的24像素安全边距,未修改文案、顺序、文本框大小或运行时逻辑。 +- 所有适配组件和参数保存在场景中,可在 Inspector 调整;未新增运行时脚本。 + +## 验证 + +实际 Play 视频已准备并持续播放;1329×600、约1067×600(16:9)、960×600(16:10)三种 Game View 下,视频显示区分别约1066.67×600、1066.67×600、960×540,宽高比均为16:9,边界位于窗口内。 + +当前1329×600下,Scene与Play的视频矩形尺寸一致;20段文字框经静态边界检查,均处于参考画布安全范围。实际观看验证覆盖首段视频及首段文字,未完整播放全部剧情或执行独立构建。 + +截图和原场景、验证存档备份在本地忽略目录 `Logs/PrologueViewportFit/`。验证后恢复原存档;Game View恢复Free Aspect,退出Play。原有启动和序章进度/跳转问题不在本次修复范围。 diff --git a/docs/save-data-debug-tool.md b/docs/save-data-debug-tool.md new file mode 100644 index 0000000..d34b120 --- /dev/null +++ b/docs/save-data-debug-tool.md @@ -0,0 +1,26 @@ +# 存档清理调试工具 + +入口:`Tools > Gemini-Lab > Save Data Debug`,窗口标题「存档调试」。工具位于 `Assets/_Project/Scripts/Editor/Persistence/SaveDataDebugWindow.cs`,仅编辑器可用。 + +## 使用 + +1. 退出 Play,等待编译和资源导入结束。 +2. 打开工具,核对当前 `Application.persistentDataPath` 和文件预览。 +3. 选择开发存档 `Saves-Dev` / 玩家存档 `Saves`、共用聊天记录、共用进度。默认选择当前 Dev Mode 对应的目录,并选中聊天和进度。 +4. 点击「备份并清理所选存档」,确认后执行;下一次进入 Play 时使用新数据。 +5. 仅验证序章时,可点击「仅重置序章播放标记」,保留所有文件存档。 + +公寓引导进度是存档 bundle 中的 `apartment_tutorial` 服务;清理相应目录的存档会一起重置。引导仍需进入空间系统页面、等待首次读档尝试结束才出现。工具不改变现有 Boot 活动场景判断和序章流程。 + +## 精确范围与备份 + +- 仅处理所选目录顶层的合法槽位 `*.sav`、`*.sav.tmp`、`*.sav.bak`,包括 autosave、手动槽位、furniture_layout;不遍历子目录,不处理未知扩展名。 +- 聊天文件:根目录的 `chat_history.json`。 +- 全局进度键:`HasPlayedPrologue`、`GeminiLab.Debug.ClockOffsetDays`、`GeminiLab.DailyReset.LastDate`、`geminilab.worldmap.wishes.v1`。音量、语言、窗口配置不清理;不调用 `PlayerPrefs.DeleteAll`。全局键和聊天会影响两种存档模式。 +- 原文件移到同一存档根目录的 `SaveDebugBackups/-<唯一标识>/`,保留原相对路径。manifest.json 记录来源、文件列表、进度键原值及是否存在。 +- 清理中途失败会尝试恢复已移动文件和进度键;若文件被占用或同时被其他进程写入,可能无法完全回滚,窗口会报告备份位置。恢复时先退出 Play,按备份中的相对路径复制文件回原根目录;进度键原值见 manifest.json(工具不提供自动恢复按钮)。 +- 不处理符号链接或目录联接。Windows 独立运行的游戏与编辑器可能共用该持久化目录,使用前请关闭运行中的独立游戏。 + +## 验证 + +Unity 编译完成,8 项专项 EditMode 测试全部通过:已知文件筛选、精确字节备份与无关数据保留、仅聊天清理、备份创建失败不动源文件、Windows 文件占用时回滚、重复清理保留旧备份、拒绝相对/磁盘根路径、限定进度键集合。菜单窗口已打开并确认存在。测试仅操作临时目录,未清理用户真实存档或修改真实 PlayerPrefs;真实确认按钮的清理操作留给使用者。当前 Console 原有 UPM 包解析中止记录不属于本工具新增错误。