63 lines
1.7 KiB
C#
63 lines
1.7 KiB
C#
using AlicizaX;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
|
|
[RequireComponent(typeof(TextMeshProUGUI))]
|
|
public sealed class InputGlyphText : InputGlyphBehaviourBase
|
|
{
|
|
[SerializeField] private InputActionReference actionReference;
|
|
[SerializeField] private string compositePartName;
|
|
|
|
private TMP_Text _textField;
|
|
private string _templateText;
|
|
private string _cachedFormattedText;
|
|
private string _cachedReplacementToken;
|
|
|
|
protected override void OnEnable()
|
|
{
|
|
if (_textField == null)
|
|
{
|
|
_textField = GetComponent<TMP_Text>();
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(_templateText) && _textField != null)
|
|
{
|
|
_templateText = _textField.text;
|
|
}
|
|
|
|
base.OnEnable();
|
|
}
|
|
|
|
protected override void RefreshGlyph()
|
|
{
|
|
if (actionReference == null || actionReference.action == null || _textField == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
string replacementToken;
|
|
if (GlyphService.TryGetTMPTagForActionPath(actionReference, compositePartName, CurrentCategory, out string tag, out string displayFallback))
|
|
{
|
|
replacementToken = tag;
|
|
}
|
|
else
|
|
{
|
|
replacementToken = displayFallback;
|
|
}
|
|
|
|
if (_cachedReplacementToken == replacementToken)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_cachedReplacementToken = replacementToken;
|
|
string formattedText = Utility.Text.Format(_templateText, replacementToken);
|
|
if (_cachedFormattedText != formattedText)
|
|
{
|
|
_cachedFormattedText = formattedText;
|
|
_textField.text = formattedText;
|
|
}
|
|
}
|
|
}
|