using System; using UnityEngine; using UnityEngine.UI; using TMPro; namespace AlicizaX.UI { /// /// Text 内容状态控制 /// 控制 Text 或 TextMeshProUGUI 的文本内容 /// [Serializable] [ControlerStateName("Text/Content")] [ControlerStateAttachType(true)] public class TextContentState : ControllerStateBase { [SerializeField] [TextArea(3, 10)] private string _text = ""; public override void Init(UXControllerStateRecorder recorder) { } public override void Execute(UXControllerStateRecorder recorder, int entryIndex, int selectionIndex) { if (recorder == null || entryIndex != selectionIndex) return; if (recorder.TryGetComponent(out var text)) { text.text = _text; } else if (recorder.TryGetComponent(out var tmp)) { tmp.text = _text; } } public override bool Valid(UXControllerStateRecorder recorder) { return recorder != null && (recorder.GetComponent() != null || recorder.GetComponent() != null); } public override string GetDescription() { string preview = _text.Length > 30 ? _text.Substring(0, 30) + "..." : _text; return $"匹配时: \"{preview}\""; } } }