using System; using System.Linq; using AlicizaX; using AlicizaX.InputGlyph; using UnityEngine; using TMPro; using UnityEngine.InputSystem; [RequireComponent(typeof(TextMeshProUGUI))] public class InputGlyphText : MonoBehaviour { [SerializeField] private InputActionReference actionReference; private TMP_Text textField; private string _oldText; void OnEnable() { if (textField == null) textField = GetComponent(); InputDeviceWatcher.OnDeviceChanged += OnDeviceChanged; _oldText=textField.text; UpdatePrompt(); } void OnDisable() { InputDeviceWatcher.OnDeviceChanged -= OnDeviceChanged; } void OnDeviceChanged(InputDeviceWatcher.InputDeviceCategory cat) { UpdatePrompt(); } void UpdatePrompt() { if (actionReference == null || actionReference.action == null || textField == null) return; var device = InputDeviceWatcher.CurrentCategory; if (GlyphService.TryGetTMPTagForActionPath(actionReference, device, out string tag, out string displayFallback)) { textField.text = Utility.Text.Format(_oldText, tag); return; } textField.text = Utility.Text.Format(_oldText, displayFallback);; } }