using UnityEngine; using UnityEngine.UI; using UnityEngine.InputSystem; using AlicizaX.InputGlyph; [RequireComponent(typeof(Image))] public class InputGlyphImage : MonoBehaviour { [SerializeField] private InputActionReference actionReference; [SerializeField] private Image targetImage; [SerializeField] private bool hideIfMissing = false; [SerializeField] private GameObject hideTargetObject; 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; if (GlyphService.TryGetUISpriteForActionPath(actionReference, deviceCategory, out Sprite sprite)) { targetImage.sprite = sprite; } if (hideTargetObject) hideTargetObject.SetActive(sprite != null && !hideIfMissing); } }