using UnityEngine; using UnityEngine.UI; namespace SpellBoundAR.MusicalInstruments.UI { [DisallowMultipleComponent] [RequireComponent(typeof(Text))] public class SongDisplayNameText : MonoBehaviour { [Header("Cache")] private Text _text; private SongDisplay _songDisplay; private void Awake() { _text = GetComponent(); _songDisplay = GetComponentInParent(); } private void OnEnable() { if (_songDisplay) _songDisplay.OnSongChanged += Refresh; Refresh(); } private void OnDisable() { if (_songDisplay) _songDisplay.OnSongChanged -= Refresh; } private void Refresh() { if (!_text) return; _text.text = _songDisplay && _songDisplay.Song ? _songDisplay.Song.Name : string.Empty; } } }