1
This commit is contained in:
48
Assets/Scripts/Story/Dialog/StoryInterpreters.cs
Normal file
48
Assets/Scripts/Story/Dialog/StoryInterpreters.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user