using UnityEngine; using UnityEngine.InputSystem; using UnityEngine.UI; public sealed class InputGlyphImage : InputGlyphBehaviourBase { [SerializeField] private InputActionReference actionReference; [SerializeField] private string compositePartName; [SerializeField] private Image targetImage; [SerializeField] private bool hideIfMissing = false; [SerializeField] private GameObject hideTargetObject; private Sprite _cachedSprite; protected override void OnEnable() { if (targetImage == null) { targetImage = GetComponent(); } base.OnEnable(); } protected override void RefreshGlyph() { if (actionReference == null || actionReference.action == null || targetImage == null) { if (targetImage != null && _cachedSprite != null) { _cachedSprite = null; targetImage.sprite = null; } ApplyVisibility(false); return; } bool hasSprite = GlyphService.TryGetUISpriteForActionPath(actionReference, compositePartName, CurrentCategory, out Sprite sprite); if (_cachedSprite != sprite) { _cachedSprite = sprite; targetImage.sprite = sprite; } ApplyVisibility(hasSprite && sprite != null); } private void ApplyVisibility(bool hasSprite) { if (hideTargetObject == null) { return; } bool shouldBeActive = !hideIfMissing || hasSprite; if (hideTargetObject.activeSelf != shouldBeActive) { hideTargetObject.SetActive(shouldBeActive); } } }