| | 1 | | using System; |
| | 2 | | using System.Collections; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using UnityEngine; |
| | 5 | | using UnityEngine.UI; |
| | 6 | |
|
| | 7 | | [RequireComponent(typeof(Toggle))] |
| | 8 | | public abstract class UIToggle : MonoBehaviour |
| | 9 | | { |
| | 10 | | protected Toggle toggle; |
| | 11 | |
|
| | 12 | | public bool isOn |
| | 13 | | { |
| 0 | 14 | | get { return toggle.isOn; } |
| | 15 | | set |
| | 16 | | { |
| 0 | 17 | | if (value != toggle.isOn) |
| | 18 | | { |
| 0 | 19 | | toggle.isOn = value; |
| | 20 | | } |
| 0 | 21 | | } |
| | 22 | | } |
| | 23 | |
|
| | 24 | | protected void Awake() |
| | 25 | | { |
| 1582 | 26 | | toggle = GetComponent<Toggle>(); |
| 1582 | 27 | | OnValueChanged(toggle.isOn); |
| 1582 | 28 | | toggle.onValueChanged.AddListener(OnValueChanged); |
| 1582 | 29 | | } |
| | 30 | |
|
| 3164 | 31 | | private void OnDestroy() { toggle.onValueChanged.RemoveListener(OnValueChanged); } |
| | 32 | |
|
| | 33 | | protected abstract void OnValueChanged(bool isOn); |
| | 34 | | } |