Toggle.cs 914 B

12345678910111213141516171819202122232425262728293031323334353637
  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(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. if (!Visible) return;
  27. GUIStyle toggleStyle = new GUIStyle(GUI.skin.toggle);
  28. bool value = GUILayout.Toggle(Value, Label, toggleStyle);
  29. if (value != Value) Value = value;
  30. }
  31. }
  32. }