Toggle.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System;
  2. using UnityEngine;
  3. namespace COM3D2.MeidoPhotoStudio.Plugin
  4. {
  5. public class Toggle : BaseControl
  6. {
  7. private bool value;
  8. public bool Value
  9. {
  10. get => value;
  11. set
  12. {
  13. this.value = value;
  14. OnControlEvent(EventArgs.Empty);
  15. }
  16. }
  17. public string Label { get; set; }
  18. public Toggle(string label, bool state = false)
  19. {
  20. Label = label;
  21. value = state;
  22. }
  23. public override void Draw(params GUILayoutOption[] layoutOptions)
  24. {
  25. Draw(new GUIStyle(GUI.skin.toggle), layoutOptions);
  26. }
  27. public void Draw(GUIStyle toggleStyle, params GUILayoutOption[] layoutOptions)
  28. {
  29. bool value = GUILayout.Toggle(Value, Label, toggleStyle, layoutOptions);
  30. if (value != Value) Value = value;
  31. }
  32. public void Draw(Rect rect)
  33. {
  34. bool value = GUI.Toggle(rect, Value, Label);
  35. if (value != Value) Value = value;
  36. }
  37. }
  38. }