LongPressToggleGroup.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // /******************************************************************************
  2. // * File: LongPressToggleGroup.cs
  3. // * Copyright (c) 2023 Qualcomm Technologies, Inc. and/or its subsidiaries. All rights reserved.
  4. // *
  5. // *
  6. // ******************************************************************************/
  7. using UnityEngine;
  8. using System.Collections.Generic;
  9. namespace QCHT.Samples.Menu
  10. {
  11. public class LongPressToggleGroup : MonoBehaviour
  12. {
  13. // [SerializeField] private bool allowSwitchOff;
  14. private readonly List<LongPressToggle> _toggles = new List<LongPressToggle>();
  15. public void RegisterToggle(LongPressToggle toggle)
  16. {
  17. if (!_toggles.Contains(toggle))
  18. _toggles.Add(toggle);
  19. }
  20. public void UnRegisterToggle(LongPressToggle toggle)
  21. {
  22. if (_toggles.Contains(toggle))
  23. _toggles.RemoveAll(x => x == toggle);
  24. }
  25. public void NotifyToggleOn(LongPressToggle toggle, bool sendCallback = false)
  26. {
  27. if (!_toggles.Contains(toggle))
  28. return;
  29. foreach (var t in _toggles)
  30. {
  31. if (t == toggle)
  32. continue;
  33. if (sendCallback)
  34. t.IsOn = false;
  35. else
  36. t.SetIsOnWithoutNotify(false);
  37. }
  38. }
  39. }
  40. }