using UnityEngine; using UnityEngine.UI; using UnityEngine.InputSystem; using AlicizaX.InputGlyph; [RequireComponent(typeof(Image))] public class InputGlyphImage : MonoBehaviour { [SerializeField] private InputActionReference actionReference; private Image targetImage; [SerializeField] private bool hideIfMissing = true; void OnEnable() { if (targetImage == null) targetImage = GetComponent(); InputDeviceWatcher.OnDeviceChanged += OnDeviceChanged; UpdatePrompt(); } void OnDisable() { InputDeviceWatcher.OnDeviceChanged -= OnDeviceChanged; } void OnDeviceChanged(InputDeviceWatcher.InputDeviceCategory cat) { UpdatePrompt(); } void UpdatePrompt() { if (actionReference == null || actionReference.action == null || targetImage == null) return; InputDeviceWatcher.InputDeviceCategory deviceCategory = InputDeviceWatcher.CurrentCategory; string path = GlyphService.GetBindingControlPath(actionReference); if (GlyphService.TryGetUISpriteForActionPath(path, deviceCategory, out Sprite sprite)) { targetImage.sprite = sprite; } } }