using DG.Tweening; using UnityEngine; using UnityEngine.UI; public class UI_SelectSong_AutoPlayToggle : MonoBehaviour { [Header("Wiring")] [SerializeField] private Button button; [SerializeField] private Toggle toggle; [SerializeField] private Image buttonImage; [SerializeField] private Text labelText; // Text (Legacy) [Header("Tween")] [SerializeField] private float tweenDuration = 0.25f; [SerializeField] private Ease tweenEase = Ease.OutCubic; private static readonly Color32 OnBg = new Color32(0x3A, 0x3A, 0x3A, 0xFF); private static readonly Color32 OffBg = new Color32(0xFF, 0xFF, 0xFF, 0xFF); private static readonly Color32 OnText = new Color32(0xFF, 0xFF, 0xFF, 0xFF); private static readonly Color32 OffText = new Color32(0x3A, 0x3A, 0x3A, 0xFF); private void Awake() { TryAutoWire(); } private void OnEnable() { TryAutoWire(); if (button != null) { button.onClick.RemoveListener(OnClick); button.onClick.AddListener(OnClick); } if (toggle != null) { toggle.onValueChanged.RemoveListener(OnToggleChanged); toggle.onValueChanged.AddListener(OnToggleChanged); // Keep UI state consistent with global setting. toggle.SetIsOnWithoutNotify(GameConfig.autoPlayEnabled); } ApplyVisual(GameConfig.autoPlayEnabled, instant: true); } private void OnDisable() { if (button != null) { button.onClick.RemoveListener(OnClick); } if (toggle != null) { toggle.onValueChanged.RemoveListener(OnToggleChanged); } KillTweens(); } public void TryAutoWire() { button = button != null ? button : GetComponent