using System; using DynamicExpresso; using Ichni.Story; using UnityEngine; namespace Ichni.Story { public static partial class StoryInterpreters { public static readonly Interpreter FunctionInterpreter; public static readonly Interpreter ConditionInterpreter; static StoryInterpreters() { FunctionInterpreter = new Interpreter(); ConditionInterpreter = new Interpreter(); SetFunctionInterpreter(); SetConditionInterpreter(); } static void SetFunctionInterpreter() { FunctionInterpreter.SetFunction("GetGlobalVariable", new Func(GetGlobalVariable)); } static void SetConditionInterpreter() { ConditionInterpreter.SetFunction("GetGlobalVariable", new Func(GetGlobalVariable)); } } public static partial class StoryInterpreters { /// /// 获取全局变量的值 /// static int GetGlobalVariable(string variableName) { if (StoryManager.instance.globalVariables.TryGetValue(variableName, out int value)) { return value; } throw new ArgumentException($"Global variable '{variableName}' not found."); } } }