| | 1 | | using UnityEngine; |
| | 2 | | using UnityEngine.UI; |
| | 3 | |
|
| | 4 | | public class SwitchToggle : Toggle |
| | 5 | | { |
| 1 | 6 | | private static readonly int animatorOnBoolean = Animator.StringToHash("isOn"); |
| | 7 | |
|
| | 8 | | [SerializeField] Animator switchAnimator; |
| | 9 | |
|
| | 10 | | protected override void Awake() |
| | 11 | | { |
| 16 | 12 | | base.Awake(); |
| 16 | 13 | | OnValueChanged(this.isOn); |
| 16 | 14 | | this.onValueChanged.AddListener(OnValueChanged); |
| 16 | 15 | | } |
| | 16 | |
|
| | 17 | | protected override void OnEnable() |
| | 18 | | { |
| 17 | 19 | | base.OnEnable(); |
| 17 | 20 | | OnValueChanged(this.isOn); |
| 17 | 21 | | } |
| | 22 | |
|
| 70 | 23 | | private void OnValueChanged(bool value) { switchAnimator.SetBool(animatorOnBoolean, value); } |
| | 24 | | } |