48 lines
1.3 KiB
C#
48 lines
1.3 KiB
C#
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<string, int>(GetGlobalVariable));
|
|
}
|
|
|
|
static void SetConditionInterpreter()
|
|
{
|
|
ConditionInterpreter.SetFunction("GetGlobalVariable", new Func<string, int>(GetGlobalVariable));
|
|
}
|
|
}
|
|
|
|
public static partial class StoryInterpreters
|
|
{
|
|
/// <summary>
|
|
/// 获取全局变量的值
|
|
/// </summary>
|
|
static int GetGlobalVariable(string variableName)
|
|
{
|
|
if (StoryManager.instance.globalVariables.TryGetValue(variableName, out int value))
|
|
{
|
|
return value;
|
|
}
|
|
|
|
throw new ArgumentException($"Global variable '{variableName}' not found.");
|
|
}
|
|
}
|
|
} |