using UnityEngine; using UnityEngine.UI; namespace SpellBoundAR.MusicalInstruments.UI { [DisallowMultipleComponent] [RequireComponent(typeof(Text))] public class SongDisplayDifficultyText : MonoBehaviour { [SerializeField] private string easyLabel = "Easy"; [SerializeField] private Color easyColor = Color.green; [Space] [SerializeField] private string mediumLabel = "Medium"; [SerializeField] private Color mediumColor = Color.yellow; [Space] [SerializeField] private string hardLabel = "Hard"; [SerializeField] private Color hardColor = Color.red; [Header("Cache")] private Text _text; private SongDisplay _songDisplay; public string EasyLabel { get => easyLabel; set => easyLabel = value; } public string MediumLabel { get => mediumLabel; set => mediumLabel = value; } public string HardLabel { get => hardLabel; set => hardLabel = value; } 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; if (_songDisplay && _songDisplay.Song) { switch (_songDisplay.Song.Difficulty) { case Difficulty.Easy: _text.text = EasyLabel; _text.color = easyColor; break; case Difficulty.Medium: _text.text = MediumLabel; _text.color = mediumColor; break; case Difficulty.Hard: _text.text = HardLabel; _text.color = hardColor; break; } } else _text.text = string.Empty; } } }