diff --git a/Assets/Render/Renderer2Dtest.asset b/Assets/Render/Renderer2Dtest.asset index bd16daaa1..20b6152ad 100644 --- a/Assets/Render/Renderer2Dtest.asset +++ b/Assets/Render/Renderer2Dtest.asset @@ -513,19 +513,15 @@ MonoBehaviour: m_PostInfinity: 2 m_RotationOrder: 4 _filter: - - 0.0048309183 - - 0.016401261 - - 0.04532712 - - 0.08293076 - - 0.12053438 - - 0.14946026 - - 0.1610306 - - 0.14946026 - - 0.12053438 - - 0.08293076 - - 0.04532712 - - 0.016401261 - - 0.0048309183 + - 0.007228916 + - 0.043749984 + - 0.12409639 + - 0.20444278 + - 0.24096388 + - 0.20444278 + - 0.12409639 + - 0.043749984 + - 0.007228916 --- !u!114 &-6086986437317696584 MonoBehaviour: m_ObjectHideFlags: 3 diff --git a/Assets/Scripts/FixSystemNew/BodyModule/BodyModule.cs b/Assets/Scripts/FixSystemNew/BodyModule/BodyModule.cs index da1fec5b1..ab409d649 100644 --- a/Assets/Scripts/FixSystemNew/BodyModule/BodyModule.cs +++ b/Assets/Scripts/FixSystemNew/BodyModule/BodyModule.cs @@ -155,8 +155,6 @@ namespace AibisDream.FixSystem // 功能信息 [Header("功能参数")] public bool cantStopRunning; - public string showPicPath; - // 只读 [JsonIgnore] public string PlugInNodeName => string.Format(PlugInNodeTemplate, moduleName); [JsonIgnore] public string DeepInNodeName => string.Format(DeepInTemplate, moduleName); @@ -167,10 +165,6 @@ namespace AibisDream.FixSystem get => !string.IsNullOrEmpty(modulePicPath) ? ResourceKit.LoadSpriteFromPsd(modulePicPath) : null; set => modulePicPath = ResourceKit.SaveSprite(value); } - - [JsonIgnore] - public Sprite ScreenPic => - !string.IsNullOrEmpty(showPicPath) ? ResourceKit.LoadSpriteFromPsd(showPicPath) : null; [JsonIgnore] public Vector3 ModulePos diff --git a/Assets/Scripts/Game Loop/EventEnums.cs b/Assets/Scripts/Game Loop/EventEnums.cs index 29adc34c3..313d951bc 100644 --- a/Assets/Scripts/Game Loop/EventEnums.cs +++ b/Assets/Scripts/Game Loop/EventEnums.cs @@ -71,4 +71,9 @@ namespace AibisDream }; } } + + public enum StorageEvent + { + VariableSet + } } \ No newline at end of file diff --git a/Assets/Scripts/Game Loop/StorageSystem.cs b/Assets/Scripts/Game Loop/StorageSystem.cs new file mode 100644 index 000000000..9d833a0c6 --- /dev/null +++ b/Assets/Scripts/Game Loop/StorageSystem.cs @@ -0,0 +1,236 @@ +using System.Collections.Generic; +using System.Linq; +using AibisDream.Framework; +using UnityEngine; +using Yarn.Unity; + +namespace AibisDream +{ + public class StorageSystem : VariableStorageBehaviour + { + private const string VariablePrefix = "$"; + private const string GlobalPrefix = "$global."; + private const string DataPrefix = "$data."; + + #region 存储部分 + + private readonly Dictionary _variableDict = new(); + private readonly DataContainer _dataContainer = new(); + + #endregion + + #region 数据类注册和注销 + + public void RegisterData(IData data) + { + _dataContainer.Register(data); + } + + public void UnregisterData() where T : class, IData + { + _dataContainer.Unregister(); + } + + #endregion + + #region 变量设置 + + public override void SetValue(string variableName, bool boolValue) + { + SetValue(variableName, boolValue); + } + + public override void SetValue(string variableName, string stringValue) + { + SetValue(variableName, stringValue); + } + + public override void SetValue(string variableName, float floatValue) + { + SetValue(variableName, floatValue); + } + + private void SetValue(string variableName, T value) + { + var variableType = ValidateVariableName(variableName); + + if (variableType == VariableType.Illegal) + { + Debug.LogError($"{variableName}: 缺少$前缀"); + return; + } + + if (variableType == VariableType.DataField) + { + Debug.LogError($"{variableName}: 暂时不支持直接设置系统数据"); + return; + } + + // Global和Local直接设置 + _variableDict[variableName] = value; + + // 数据设置事件广播 + var variableItem = new VariableItem + { + variableName = variableName, + value = value + }; + EnumEventSystem.Global.Send(StorageEvent.VariableSet, variableItem); + } + + public override void Clear() + { + _variableDict.Clear(); + } + + public void ClearLocal() + { + // 收集所有Local类型的变量 + var locals = _variableDict.Keys.Where(item => ValidateVariableName(item) == VariableType.Local).ToArray(); + // 清除 + foreach (var localKey in locals) + { + _variableDict.Remove(localKey); + } + } + + #endregion + + #region 变量获取 + + public override bool Contains(string variableName) + { + return _variableDict.ContainsKey(variableName); + } + + public override bool TryGetValue(string variableName, out T result) + { + var variableType = ValidateVariableName(variableName); + // 非法的直接pass + if (variableType == VariableType.Illegal) + { + result = default; + return false; + } + // 在系统数据中查找 + if (variableType == VariableType.DataField) + { + Debug.LogWarning("查找Data数据功能待实现"); + result = default; + return true; + } + // 直接查找数据 + if (_variableDict.TryGetValue(variableName, out var value)) + { + if (value is T target) + { + result = target; + return true; + } + } + + result = default; + return false; + } + + #endregion + + #region 序列化 + + public override void SetAllVariables(Dictionary floats, Dictionary strings, + Dictionary bools, bool clear = true) + { + if (clear) + { + _dataContainer.Clear(); + } + + foreach (var value in floats) + { + SetValue(value.Key, value.Value); + } + foreach (var value in strings) + { + SetValue(value.Key, value.Value); + } + foreach (var value in bools) + { + SetValue(value.Key, value.Value); + } + } + + public override (Dictionary FloatVariables, Dictionary StringVariables, + Dictionary BoolVariables) GetAllVariables() + { + var floatDict = new Dictionary(); + var stringDict = new Dictionary(); + var boolDict = new Dictionary(); + + foreach (var variablePair in _variableDict) + { + switch (variablePair.Value) + { + case float: + { + var value = System.Convert.ToSingle(variablePair.Value); + floatDict.Add(variablePair.Key, value); + break; + } + case string: + { + var value = System.Convert.ToString(variablePair.Value); + stringDict.Add(variablePair.Key, value); + break; + } + case bool: + { + var value = System.Convert.ToBoolean(variablePair.Value); + boolDict.Add(variablePair.Key, value); + break; + } + default: + Debug.Log($"{variablePair.Key} is not a valid type"); + break; + } + } + + return (floatDict, stringDict, boolDict); + } + + #endregion + + private static VariableType ValidateVariableName(string variableName) + { + if (string.IsNullOrWhiteSpace(variableName) || !variableName.StartsWith(VariablePrefix)) + { + return VariableType.Illegal; + } + + if (variableName.StartsWith(GlobalPrefix)) + { + return VariableType.Global; + } + + if (variableName.StartsWith(DataPrefix)) + { + return VariableType.DataField; + } + + return VariableType.Local; + } + } + + public enum VariableType + { + Local, + Global, + DataField, + Illegal + } + + public struct VariableItem + { + public string variableName; + public object value; + } +} \ No newline at end of file diff --git a/Assets/Scripts/Game Loop/StorageSystem.cs.meta b/Assets/Scripts/Game Loop/StorageSystem.cs.meta new file mode 100644 index 000000000..8d87d35be --- /dev/null +++ b/Assets/Scripts/Game Loop/StorageSystem.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: bd2f44edfbd942b49bb7a37f80d7a5eb +timeCreated: 1742802488 \ No newline at end of file