2026-03-17 20:02:47 +08:00
|
|
|
|
using AlicizaX;
|
2025-12-09 20:31:44 +08:00
|
|
|
|
using TMPro;
|
2026-03-17 20:02:47 +08:00
|
|
|
|
using UnityEngine;
|
2025-12-09 20:31:44 +08:00
|
|
|
|
using UnityEngine.InputSystem;
|
|
|
|
|
|
|
|
|
|
|
|
[RequireComponent(typeof(TextMeshProUGUI))]
|
2026-03-17 20:02:47 +08:00
|
|
|
|
public sealed class InputGlyphText : InputGlyphBehaviourBase
|
2025-12-09 20:31:44 +08:00
|
|
|
|
{
|
|
|
|
|
|
[SerializeField] private InputActionReference actionReference;
|
2026-03-09 20:38:15 +08:00
|
|
|
|
|
2026-03-17 20:02:47 +08:00
|
|
|
|
private TMP_Text _textField;
|
|
|
|
|
|
private string _templateText;
|
|
|
|
|
|
private string _cachedFormattedText;
|
2025-12-09 20:31:44 +08:00
|
|
|
|
|
2026-03-17 20:02:47 +08:00
|
|
|
|
protected override void OnEnable()
|
2025-12-09 20:31:44 +08:00
|
|
|
|
{
|
2026-03-17 20:02:47 +08:00
|
|
|
|
if (_textField == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
_textField = GetComponent<TMP_Text>();
|
|
|
|
|
|
}
|
2025-12-09 20:31:44 +08:00
|
|
|
|
|
2026-03-17 20:02:47 +08:00
|
|
|
|
if (string.IsNullOrEmpty(_templateText) && _textField != null)
|
2026-03-09 20:38:15 +08:00
|
|
|
|
{
|
2026-03-17 20:02:47 +08:00
|
|
|
|
_templateText = _textField.text;
|
2026-03-09 20:38:15 +08:00
|
|
|
|
}
|
2026-03-17 20:02:47 +08:00
|
|
|
|
|
|
|
|
|
|
base.OnEnable();
|
2025-12-09 20:31:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-17 20:02:47 +08:00
|
|
|
|
protected override void RefreshGlyph()
|
2025-12-09 20:31:44 +08:00
|
|
|
|
{
|
2026-03-17 20:02:47 +08:00
|
|
|
|
if (actionReference == null || actionReference.action == null || _textField == null)
|
2025-12-09 20:31:44 +08:00
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-17 20:02:47 +08:00
|
|
|
|
string formattedText;
|
|
|
|
|
|
if (GlyphService.TryGetTMPTagForActionPath(actionReference, string.Empty, CurrentCategory, out string tag, out string displayFallback))
|
|
|
|
|
|
{
|
|
|
|
|
|
formattedText = Utility.Text.Format(_templateText, tag);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
formattedText = Utility.Text.Format(_templateText, displayFallback);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (_cachedFormattedText != formattedText)
|
2026-03-09 20:38:15 +08:00
|
|
|
|
{
|
2026-03-17 20:02:47 +08:00
|
|
|
|
_cachedFormattedText = formattedText;
|
|
|
|
|
|
_textField.text = formattedText;
|
2026-03-09 20:38:15 +08:00
|
|
|
|
}
|
2025-12-09 20:31:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|