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

75 lines
2.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using Sirenix.OdinInspector;
using UnityEngine;
namespace Ichni.Story
{
/// <summary>
/// StoryData 中声明的章节变量默认值类型。
/// 数值变量会保存为 floatInt 仅决定 Inspector 和读取接口的语义。
/// </summary>
public enum StoryVariableType
{
Bool,
Int,
Float,
String
}
/// <summary>
/// 一个章节变量的静态默认定义。
/// 默认值不写入玩家存档当存档中没有同名覆盖值时StoryVariables 才返回此处的配置。
/// 因此“重开章节”只要清空章节变量容器,便会自然回到该定义的初始状态。
/// </summary>
[Serializable]
[InlineProperty]
[HideReferenceObjectPicker]
public class StoryVariableDefinition
{
[HorizontalGroup("Variable", 0.55f)]
[LabelText("Key")]
[LabelWidth(28)]
[Tooltip("变量 Key使用小写英文、数字和下划线例如 c0_route_choice。不要使用 Yarn 的 $variable 语法。")]
public string key;
[HorizontalGroup("Variable", 0.18f)]
[LabelText("Type")]
[LabelWidth(32)]
[Tooltip("变量的默认值类型。运行时可由 Yarn 的 set_* 指令写入同名永久章节变量。")]
public StoryVariableType type;
[HorizontalGroup("Variable")]
[LabelText("Default")]
[LabelWidth(48)]
[ShowIf(nameof(IsBool))]
[Tooltip("变量尚未被玩家存档覆盖时使用的默认 Bool 值。")]
public bool boolValue;
[HorizontalGroup("Variable")]
[LabelText("Default")]
[LabelWidth(48)]
[ShowIf(nameof(IsInt))]
[Tooltip("变量尚未被玩家存档覆盖时使用的默认 Int 值。")]
public int intValue;
[HorizontalGroup("Variable")]
[LabelText("Default")]
[LabelWidth(48)]
[ShowIf(nameof(IsFloat))]
[Tooltip("变量尚未被玩家存档覆盖时使用的默认 Float 值。")]
public float floatValue;
[HorizontalGroup("Variable")]
[LabelText("Default")]
[LabelWidth(48)]
[ShowIf(nameof(IsString))]
[Tooltip("变量尚未被玩家存档覆盖时使用的默认 String 值。")]
public string stringValue;
private bool IsBool() => type == StoryVariableType.Bool;
private bool IsInt() => type == StoryVariableType.Int;
private bool IsFloat() => type == StoryVariableType.Float;
private bool IsString() => type == StoryVariableType.String;
}
}