50 lines
1.4 KiB
C#
50 lines
1.4 KiB
C#
|
|
using System;
|
||
|
|
using UnityEngine;
|
||
|
|
using UnityEngine.UI;
|
||
|
|
using TMPro;
|
||
|
|
|
||
|
|
namespace AlicizaX.UI
|
||
|
|
{
|
||
|
|
/// <summary>
|
||
|
|
/// Text 内容状态控制
|
||
|
|
/// 控制 Text 或 TextMeshProUGUI 的文本内容
|
||
|
|
/// </summary>
|
||
|
|
[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<Text>(out var text))
|
||
|
|
{
|
||
|
|
text.text = _text;
|
||
|
|
}
|
||
|
|
else if (recorder.TryGetComponent<TextMeshProUGUI>(out var tmp))
|
||
|
|
{
|
||
|
|
tmp.text = _text;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public override bool Valid(UXControllerStateRecorder recorder)
|
||
|
|
{
|
||
|
|
return recorder != null &&
|
||
|
|
(recorder.GetComponent<Text>() != null || recorder.GetComponent<TextMeshProUGUI>() != null);
|
||
|
|
}
|
||
|
|
|
||
|
|
public override string GetDescription()
|
||
|
|
{
|
||
|
|
string preview = _text.Length > 30 ? _text.Substring(0, 30) + "..." : _text;
|
||
|
|
return $"匹配时: \"{preview}\"";
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|