using UnityEngine; using UnityEngine.UI; namespace SpellBoundAR.MusicalInstruments.UI { [DisallowMultipleComponent] [RequireComponent(typeof(Graphic))] public class SongDisplayNeverSelectedAlertGraphic : MonoBehaviour { [Header("Cache")] private Graphic _graphic; private SongDisplay _songDisplay; private Song _song; private Song Song { get => _song; set { if (_song == value) return; if (_song) _song.OnTimesSelectedChanged -= RefreshGraphic; _song = value; if (_song) _song.OnTimesSelectedChanged += RefreshGraphic; RefreshGraphic(); } } private void Awake() { _graphic = GetComponent(); _songDisplay = GetComponentInParent(); } private void OnEnable() { if (_songDisplay) _songDisplay.OnSongChanged += RefreshSong; RefreshSong(); } private void OnDisable() { if (_songDisplay) _songDisplay.OnSongChanged -= RefreshSong; } private void RefreshSong() { Song = _songDisplay ? _songDisplay.Song : null; RefreshGraphic(); } private void RefreshGraphic() { if (!_graphic) return; _graphic.enabled = Song && Song.TimesSelected < 1; } } }