OptionsControlBase.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. namespace SRDebugger.UI.Controls
  2. {
  3. using Internal;
  4. using SRF;
  5. using UnityEngine.UI;
  6. public abstract class OptionsControlBase : SRMonoBehaviourEx
  7. {
  8. private bool _selectionModeEnabled;
  9. [RequiredField] public Toggle SelectionModeToggle;
  10. public OptionDefinition Option;
  11. public bool SelectionModeEnabled
  12. {
  13. get { return _selectionModeEnabled; }
  14. set
  15. {
  16. if (value == _selectionModeEnabled)
  17. {
  18. return;
  19. }
  20. _selectionModeEnabled = value;
  21. SelectionModeToggle.gameObject.SetActive(_selectionModeEnabled);
  22. if (SelectionModeToggle.graphic != null)
  23. {
  24. SelectionModeToggle.graphic.CrossFadeAlpha(IsSelected ? _selectionModeEnabled ? 1.0f : 0.2f : 0f, 0,
  25. true);
  26. }
  27. }
  28. }
  29. public bool IsSelected
  30. {
  31. get { return SelectionModeToggle.isOn; }
  32. set
  33. {
  34. SelectionModeToggle.isOn = value;
  35. if (SelectionModeToggle.graphic != null)
  36. {
  37. SelectionModeToggle.graphic.CrossFadeAlpha(value ? _selectionModeEnabled ? 1.0f : 0.2f : 0f, 0, true);
  38. }
  39. }
  40. }
  41. protected override void Awake()
  42. {
  43. base.Awake();
  44. IsSelected = false;
  45. SelectionModeToggle.gameObject.SetActive(false);
  46. }
  47. protected override void OnEnable()
  48. {
  49. base.OnEnable();
  50. // Reapply selection indicator alpha (is reset when disabled / reenabled)
  51. if (SelectionModeToggle.graphic != null)
  52. {
  53. SelectionModeToggle.graphic.CrossFadeAlpha(IsSelected ? _selectionModeEnabled ? 1.0f : 0.2f : 0f, 0,
  54. true);
  55. }
  56. }
  57. public virtual void Refresh() {}
  58. }
  59. }