| | 1 | | using UnityEngine; |
| | 2 | | using UnityEngine.EventSystems; |
| | 3 | | using UnityEngine.UI; |
| | 4 | |
|
| | 5 | | public class ToggleAudioHandler : MonoBehaviour, IPointerDownHandler |
| | 6 | | { |
| | 7 | | Toggle toggle; |
| | 8 | |
|
| | 9 | | void Awake() |
| | 10 | | { |
| 85 | 11 | | toggle = GetComponent<Toggle>(); |
| 85 | 12 | | toggle.onValueChanged.AddListener(OnValueChanged); |
| 85 | 13 | | } |
| | 14 | |
|
| | 15 | | public void OnPointerDown(PointerEventData eventData) |
| | 16 | | { |
| 0 | 17 | | if (toggle != null) |
| | 18 | | { |
| 0 | 19 | | if (toggle.interactable) |
| | 20 | | { |
| 0 | 21 | | AudioScriptableObjects.buttonClick.Play(true); |
| | 22 | | } |
| | 23 | | } |
| 0 | 24 | | } |
| | 25 | |
|
| | 26 | | public void OnValueChanged(bool isOn) |
| | 27 | | { |
| 12 | 28 | | if (toggle != null) |
| | 29 | | { |
| 12 | 30 | | if (toggle.interactable) |
| | 31 | | { |
| 12 | 32 | | if (isOn) |
| | 33 | | { |
| 3 | 34 | | AudioScriptableObjects.enable.Play(true); |
| 3 | 35 | | } |
| | 36 | | else |
| | 37 | | { |
| 9 | 38 | | AudioScriptableObjects.disable.Play(true); |
| | 39 | | } |
| | 40 | | } |
| | 41 | | } |
| 9 | 42 | | } |
| | 43 | | } |