12345678910111213141516171819202122232425262728293031 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- namespace XRTool.UI
- {
- /// <summary>
- /// 简化的Toggle
- /// </summary>
- public class ToggleButton : Button
- {
- public Sprite closeImg;
- public Sprite openImg;
- public bool isOn = false;
- public event Action<bool> 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);
- }
- }
- }
|