Toggle.cs 1022 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System;
  2. using UnityEngine;
  3. namespace COM3D2.MeidoPhotoStudio.Plugin
  4. {
  5. internal 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(bool state = false) : this("", state) { }
  19. public Toggle(string label, bool state = false)
  20. {
  21. Label = label;
  22. this.value = state;
  23. }
  24. public override void Draw(params GUILayoutOption[] layoutOptions)
  25. {
  26. Draw(new GUIStyle(GUI.skin.toggle), layoutOptions);
  27. }
  28. public void Draw(GUIStyle toggleStyle, params GUILayoutOption[] layoutOptions)
  29. {
  30. if (!Visible) return;
  31. bool value = GUILayout.Toggle(Value, Label, toggleStyle);
  32. if (value != Value) Value = value;
  33. }
  34. }
  35. }