using UnityEngine; using UnityEngine.UI; namespace SpellBoundAR.Items.Selections.UI { [DisallowMultipleComponent] [RequireComponent(typeof(Image))] public class ItemTypeSelectionButtonImage : MonoBehaviour { [Header("Cache")] private ItemTypeSelectionButton _button; private Image _image; private void Awake() { _button = GetComponentInParent(); _image = GetComponent(); } private void OnEnable() { if (_button) _button.OnItemTypeChanged += Refresh; Refresh(); } private void OnDisable() { if (_button) _button.OnItemTypeChanged -= Refresh; } private void Refresh() { if (!_image) return; _image.sprite = _button && _button.ScriptedItemTypeData ? _button.ScriptedItemTypeData.Depiction : null; _image.color = _image.sprite ? Color.white : Color.clear; _image.preserveAspect = true; } } }