LoadToggleSample.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // /******************************************************************************
  2. // * File: LoadToggleSample.cs
  3. // * Copyright (c) 2023 Qualcomm Technologies, Inc. and/or its subsidiaries. All rights reserved.
  4. // *
  5. // *
  6. // ******************************************************************************/
  7. using UnityEngine;
  8. using UnityEngine.Events;
  9. using UnityEngine.UI;
  10. namespace QCHT.Samples.Menu
  11. {
  12. [RequireComponent(typeof(Toggle))]
  13. public class LoadToggleSample : MonoBehaviour
  14. {
  15. [SerializeField] public SampleSettings _sampleToLoad;
  16. private Toggle _toggle;
  17. public UnityEvent<SampleSettings> OnSampleClicked = new UnityEvent<SampleSettings>();
  18. private void Awake() {
  19. _toggle = GetComponent<Toggle>();
  20. }
  21. private void OnEnable() {
  22. _toggle.onValueChanged.AddListener(OnToggleValueChanged);
  23. }
  24. private void OnDisable() {
  25. _toggle.onValueChanged.RemoveListener(OnToggleValueChanged);
  26. }
  27. public void OnToggleValueChanged(bool isOn) {
  28. if (isOn)
  29. OnSampleClicked?.Invoke(_sampleToLoad);
  30. }
  31. }
  32. }