using UnityEngine; using UnityEngine.UI; namespace SpellBoundAR.Items.Inventories.UI { [DisallowMultipleComponent] [RequireComponent(typeof(Image))] public class InventoryEntryDisplayImage : MonoBehaviour { [Header("Cache")] private Image _image; private InventoryEntryDisplay _display; private void Awake() { _image = GetComponent(); _display = GetComponentInParent(); } private void OnEnable() { if (_display) _display.OnEntryChanged += Refresh; Refresh(); } private void OnDisable() { if (_display) _display.OnEntryChanged -= Refresh; } private void Refresh() { if (!_image) return; _image.sprite = _display && _display.Entry is {ItemTypeData: { }} ? _display.Entry.ItemTypeData.Depiction : null; _image.color = _image.sprite ? Color.white : Color.clear; _image.preserveAspect = true; } } }