using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; namespace XRTool.UI { /// /// 简化的Toggle /// public class ToggleButton : Button { public Sprite closeImg; public Sprite openImg; public bool isOn = false; public event Action OnValueChanged; protected override void Start() { base.Start(); image.sprite = isOn ? openImg : closeImg; onClick.AddListener(OnClickAction); } private void OnClickAction() { isOn = !isOn; image.sprite = isOn ? openImg : closeImg; OnValueChanged?.Invoke(isOn); } } }