From bf416f604b9f5c7a0e126b1700112f555fc01a7e Mon Sep 17 00:00:00 2001 From: bottlefish <781230111@qq.com> Date: Fri, 26 Jun 2026 23:57:38 +0800 Subject: [PATCH] fix: handle Yarn initial variable storage fallback --- Assets/Scripts/Game Loop/StorageSystem.cs | 37 ++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/Assets/Scripts/Game Loop/StorageSystem.cs b/Assets/Scripts/Game Loop/StorageSystem.cs index a71d90653..4e9ccfdac 100644 --- a/Assets/Scripts/Game Loop/StorageSystem.cs +++ b/Assets/Scripts/Game Loop/StorageSystem.cs @@ -146,10 +146,45 @@ namespace AibisDream } } + if (TryGetInitialValue(variableName, out result)) + { + return true; + } + result = default; return false; } + private bool TryGetInitialValue(string variableName, out T result) + { + result = default; + + if (Program == null || !Program.InitialValues.TryGetValue(variableName, out var initialValue)) + { + return false; + } + + if (!InitialValueMatchesType(initialValue.ValueCase)) + { + return false; + } + + return Program.TryGetInitialValue(variableName, out result); + } + + private static bool InitialValueMatchesType(Yarn.Operand.ValueOneofCase valueCase) + { + var targetType = typeof(T); + + return valueCase switch + { + Yarn.Operand.ValueOneofCase.BoolValue => targetType == typeof(bool), + Yarn.Operand.ValueOneofCase.StringValue => targetType == typeof(string), + Yarn.Operand.ValueOneofCase.FloatValue => targetType == typeof(float), + _ => false + }; + } + #endregion #region εΊεˆ—εŒ– @@ -365,4 +400,4 @@ namespace AibisDream public string variableName; public object value; } -} \ No newline at end of file +}