Files
ichni_Official/Assets/Scripts/NewStorySystem/YarnFunctions/VariableFunctions.cs
SoulliesOfficial 810d019619 剧情+对话完善
2026-07-21 15:24:42 -04:00

52 lines
2.2 KiB
C#

using Ichni.Story;
using Yarn.Unity;
namespace Ichni.Story.YarnFunctions
{
/// <summary>
/// ichni Official 的永久剧情变量 Yarn 接口。
/// <para>所有变量都属于当前 StoryData 对应的章节存档。请不要在新台本中使用 Yarn 原生的
/// <c>&lt;&lt;declare&gt;&gt;</c>、<c>&lt;&lt;set&gt;&gt;</c> 或 <c>$variable</c>,它们会创建不受本章节回滚系统管理的临时变量。</para>
/// <para>推荐语法:<c>&lt;&lt;set_bool "c0_intro_read" true&gt;&gt;</c>、
/// <c>&lt;&lt;if get_int("c0_route") == 1&gt;&gt;</c>。</para>
/// </summary>
public static class VariableCommands
{
[YarnCommand("set_bool")]
public static void SetBool(string key, bool value) => StoryProgress.SetBoolAndRefresh(key, value);
[YarnFunction("get_bool")]
public static bool GetBool(string key) => StoryVariables.GetBool(key);
[YarnCommand("set_int")]
public static void SetInt(string key, int value) => StoryProgress.SetIntAndRefresh(key, value);
[YarnCommand("add_int")]
public static void AddInt(string key, int delta) => StoryProgress.AddIntAndRefresh(key, delta);
[YarnFunction("get_int")]
public static int GetInt(string key) => StoryVariables.GetInt(key);
[YarnCommand("set_float")]
public static void SetFloat(string key, float value) => StoryProgress.SetFloatAndRefresh(key, value);
[YarnCommand("add_float")]
public static void AddFloat(string key, float delta) => StoryProgress.AddFloatAndRefresh(key, delta);
[YarnFunction("get_float")]
public static float GetFloat(string key) => StoryVariables.GetFloat(key);
[YarnCommand("set_string")]
public static void SetString(string key, string value) => StoryProgress.SetStringAndRefresh(key, value);
[YarnFunction("get_string")]
public static string GetString(string key) => StoryVariables.GetString(key);
[YarnCommand("remove_variable")]
public static void RemoveVariable(string key) => StoryProgress.RemoveVariableAndRefresh(key);
[YarnFunction("has_variable")]
public static bool HasVariable(string key) => StoryVariables.HasVariable(key);
}
}