using UnityEngine; using UnityEngine.UI; namespace SpellBoundAR.MusicalInstruments.UI { [DisallowMultipleComponent] [RequireComponent(typeof(Graphic))] public class SongDisplaySelectedGraphic : MonoBehaviour { [Header("Cache")] private Graphic _graphic; private SongDisplay _songDisplay; private void Awake() { _graphic = GetComponent(); _songDisplay = GetComponentInParent(); } private void OnEnable() { if (_songDisplay) _songDisplay.OnSongChanged += RefreshGraphic; MusicalInstrumentsManager.OnSongChanged += RefreshGraphic; RefreshGraphic(); } private void OnDisable() { if (_songDisplay) _songDisplay.OnSongChanged -= RefreshGraphic; MusicalInstrumentsManager.OnSongChanged -= RefreshGraphic; } private void RefreshGraphic() { if (!_graphic) return; _graphic.enabled = _songDisplay && _songDisplay.Song && _songDisplay.Song == MusicalInstrumentsManager.Song; } } }