diff --git a/Assets/Scripts/Framework/Core/Core.cs b/Assets/Scripts/Framework/Core/Core.cs index 3315bd954..2ae268add 100644 --- a/Assets/Scripts/Framework/Core/Core.cs +++ b/Assets/Scripts/Framework/Core/Core.cs @@ -1,9 +1,6 @@ using System; -using System.Collections; using System.Collections.Generic; using System.Linq; -using AibisDream.Utility; -using Newtonsoft.Json.Linq; using UnityEngine; namespace AibisDream.Framework @@ -24,15 +21,6 @@ namespace AibisDream.Framework public abstract void SaveLevel(); } - public interface IData - { - IEnumerator Load(); - - void Save() - { - } - } - #region IOC容器 public class IOCContainer @@ -89,183 +77,6 @@ namespace AibisDream.Framework } } - public class DataContainer - { - private Dictionary _instances = new(); - - public int Count => _instances.Count; - - public void Register(T instance) where T : IData - { - var key = typeof(T).AssemblyQualifiedName; - if (key != null) _instances[key] = instance; - } - - public T Get() where T : class, IData - { - var key = typeof(T).AssemblyQualifiedName; - if (key != null && _instances.TryGetValue(key, out var retInstance)) - { - return retInstance as T; - } - - return null; - } - - public object Get(Type type) - { - var key = type.AssemblyQualifiedName; - if (key != null && _instances.TryGetValue(key, out var retInstance)) - { - return retInstance; - } - - return null; - } - - public T Unregister() where T : class, IData - { - var res = Get(); - var assemblyQualifiedName = typeof(T).AssemblyQualifiedName; - if (res != null && assemblyQualifiedName != null) - { - _instances.Remove(assemblyQualifiedName); - return res; - } - - return null; - } - - public void Clear() - { - _instances.Clear(); - } - - public JObject SaveAsJson() - { - foreach (var data in _instances.Values) - { - data.Save(); - } - return JObject.FromObject(_instances); - } - - public IEnumerator LoadByJson(JObject dataJson) - { - // 从加载序号1到10加载数据 - for (var i = 1; i <= 10; i++) - { - // 先筛选对应序号 - var curIdx = i; - var idxInstances = _instances.Where(item => LoadIndex.GetLoadIdx(item.Value) == curIdx).ToArray(); - // 回填数据并加载 - foreach (var instancePair in idxInstances) - { - if (!dataJson.TryGetValue(instancePair.Key, out var data)) - { - Debug.Log(instancePair.Key + "未注册"); - continue; - } - - var fixDataType = Type.GetType(instancePair.Key); - if (fixDataType == null) - { - Debug.Log(instancePair.Key + "类型不存在"); - continue; - } - - // 把Json中读到的参数填回Data - var tempObj = data.ToObject(fixDataType); - CommonUtil.CopyFields(tempObj, instancePair.Value); - - // 回填完成后进行加载 - yield return instancePair.Value.Load(); - } - } - } - - public bool TryGetFieldValue(string variableName, out T fieldValue) - { - fieldValue = default; - var parts = variableName.Split('.'); - if (parts.Length <= 3) - { - Debug.LogError($"{variableName}输入格式错误,应为 '$data.类名.字段名'"); - return false; - } - - var className = parts[1]; - var fieldName = parts[2]; - - var key = _instances.Keys.FirstOrDefault(key => key.Contains(className)); - if (string.IsNullOrEmpty(key)) - { - Debug.LogError($"未找到类名为 {className} 的实例"); - return false; - } - - var instance = _instances[key]; - var fieldInfo = instance.GetType().GetField(fieldName); - if (fieldInfo == null) - { - Debug.LogError($"未找到字段名为 {fieldName} 的字段"); - return false; - } - - var value = fieldInfo.GetValue(instance); - if (typeof(T) == typeof(string)) - { - // 单独处理字符串类型 - fieldValue = (T)(object)(value?.ToString() ?? string.Empty); - return true; - } - - if (typeof(T) == typeof(float)) - { - // 处理数字类型转换为 float - if (value is IConvertible) - { - try - { - fieldValue = (T)(object)Convert.ToSingle(value); - return true; - } - catch (Exception ex) - { - Debug.LogError($"无法将字段值转换为 float: {ex.Message}"); - return false; - } - } - - Debug.LogError("字段值不是可转换为 float 的类型"); - return false; - } - - if (typeof(T) == typeof(bool)) - { - // 处理布尔类型转换为 bool - if (value is IConvertible) - { - fieldValue = (T)(object)Convert.ToBoolean(value); - return true; - } - - Debug.LogError("字段值不是可转换为 bool 的类型"); - return false; - } - - if (value is T typedValue) - { - // 处理其他类型 - fieldValue = typedValue; - return true; - } - - Debug.LogError($"未找到类型为 {typeof(T).Name} 的转换方法"); - return false; - } - } - #endregion #region 事件相关 diff --git a/Assets/Scripts/Game Loop/LoadIndex.cs b/Assets/Scripts/Game Loop/LoadIndex.cs deleted file mode 100644 index 3d7e3d596..000000000 --- a/Assets/Scripts/Game Loop/LoadIndex.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.Reflection; - -namespace AibisDream -{ - public class LoadIndex : Attribute - { - private int Idx { get; } - - public LoadIndex(int idx) - { - Idx = idx; - } - - public static int GetLoadIdx(T instance) - { - // 先通过反射拿到属性 - var attribute = instance.GetType().GetCustomAttribute(); - return attribute?.Idx ?? 5; - } - } -} \ No newline at end of file diff --git a/Assets/Scripts/Game Loop/LoadIndex.cs.meta b/Assets/Scripts/Game Loop/LoadIndex.cs.meta deleted file mode 100644 index 64ce7dda2..000000000 --- a/Assets/Scripts/Game Loop/LoadIndex.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: cbb1d63c733941879217082bda086ade -timeCreated: 1742905792 \ No newline at end of file diff --git a/Assets/Scripts/SaveSystem/DeepRepairDataRegistry.cs b/Assets/Scripts/SaveSystem/DeepRepairDataRegistry.cs deleted file mode 100644 index f65b80477..000000000 --- a/Assets/Scripts/SaveSystem/DeepRepairDataRegistry.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System.Collections; -using AibisDream.Framework; -using Newtonsoft.Json.Linq; - -namespace AibisDream.SaveSystem -{ - /// - /// 深度维修子系统的旧 IData 注册表(基于 )。 - /// - /// FixSystem / Eye / Chip 等仍通过此处 RegisterData;尚未纳入新 。 - /// P5 评估后迁移或废弃;与 、快照 I/O 分离。 - /// - /// - public static class DeepRepairDataRegistry - { - private static readonly DataContainer Container = new(); - - public static void RegisterData(T data) where T : IData - { - Container.Register(data); - } - - public static void UnregisterData() where T : class, IData - { - Container.Unregister(); - } - - /// 旧格式存档 systemData 段还原;按 LoadIndex 顺序执行各 IData.Load()。 - public static IEnumerator LoadByJson(JObject dataJson) - { - if (dataJson == null) - { - yield break; - } - - yield return Container.LoadByJson(dataJson); - } - } -} diff --git a/Assets/Scripts/SaveSystem/DeepRepairDataRegistry.cs.meta b/Assets/Scripts/SaveSystem/DeepRepairDataRegistry.cs.meta deleted file mode 100644 index f3174e2cb..000000000 --- a/Assets/Scripts/SaveSystem/DeepRepairDataRegistry.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: ba4cbc590c8177045b16b8a02db31121 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/SaveSystem/DeepRepairSnapshot.cs b/Assets/Scripts/SaveSystem/DeepRepairSnapshot.cs deleted file mode 100644 index 499498276..000000000 --- a/Assets/Scripts/SaveSystem/DeepRepairSnapshot.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System; -using System.Collections.Generic; -using Newtonsoft.Json.Linq; - -namespace AibisDream.SaveSystem -{ - /// - /// 深度维修是否纳入新快照、以何种粒度纳入(P5 逐个定案)。 - /// - public enum DeepRepairSavePolicy - { - /// 完整阶段终点状态写入 deepRepair.sections。 - Supported, - - /// 只存简化后的关键字段。 - Simplified, - - /// 不存;读档回到进入该维修前的可存点。 - Dropped - } - - /// - /// 占位段。 - /// P1 捕获时不写入;读档时缺省或 sections 为空则不报错。 - /// 正式实现后替代/收敛 的旧 IData 路径。 - /// - [Serializable] - public class DeepRepairSnapshot - { - public DeepRepairSavePolicy policy = DeepRepairSavePolicy.Dropped; - - /// 按维修模块 id 分子段,具体 key 在 P5 定义。 - public Dictionary sections = new(); - } -} diff --git a/Assets/Scripts/SaveSystem/DeepRepairSnapshot.cs.meta b/Assets/Scripts/SaveSystem/DeepRepairSnapshot.cs.meta deleted file mode 100644 index a64eebf57..000000000 --- a/Assets/Scripts/SaveSystem/DeepRepairSnapshot.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 6ee71c8af7b93d64aa87335a011eccf5 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: