Files
ichni_Official/Assets/Scripts/NewStorySystem/YarnFunctions/VariableFunctions.cs
SoulliesOfficial 7b7d069b84 StorySystem
2026-07-07 01:28:27 -04:00

77 lines
2.2 KiB
C#

using UnityEngine;
using Yarn.Unity;
using Ichni.Story;
namespace Ichni.Story.YarnFunctions
{
/// <summary>
/// 提供可以直接在 Yarn 脚本中调用的全局变量读写指令。
/// 完全兼容旧系统中的自定义函数(避免旧的 .yarn 报错),
/// 底层统一指向全新的 StoryVariables 枢纽。
/// </summary>
public static class VariableCommands
{
[YarnCommand("set_bool")]
public static void SetBool(string key, bool value)
{
StoryVariables.SetBool(key, value);
}
[YarnFunction("get_bool")]
public static bool GetBool(string key)
{
return StoryVariables.GetBool(key);
}
[YarnCommand("set_int")]
public static void SetInt(string key, int value)
{
StoryVariables.SetInt(key, value);
}
[YarnCommand("modify_int")]
public static void ModifyInt(string key, int modification)
{
int currentValue = StoryVariables.GetInt(key);
StoryVariables.SetInt(key, currentValue + modification);
}
[YarnFunction("get_int")]
public static int GetInt(string key)
{
return StoryVariables.GetInt(key);
}
[YarnCommand("set_float")]
public static void SetFloat(string key, float value)
{
StoryVariables.SetFloat(key, value);
}
[YarnCommand("modify_float")]
public static void ModifyFloat(string key, float modification)
{
float currentValue = StoryVariables.GetFloat(key);
StoryVariables.SetFloat(key, currentValue + modification);
}
[YarnFunction("get_float")]
public static float GetFloat(string key)
{
return StoryVariables.GetFloat(key);
}
[YarnCommand("set_string")]
public static void SetString(string key, string value)
{
StoryVariables.SetString(key, value);
}
[YarnFunction("get_string")]
public static string GetString(string key)
{
return StoryVariables.GetString(key);
}
}
}