BoolControl.cs 943 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System;
  2. using SRF;
  3. using UnityEngine.Events;
  4. using UnityEngine.UI;
  5. namespace SRDebugger.UI.Controls.Data
  6. {
  7. public class BoolControl : DataBoundControl
  8. {
  9. protected override void Start()
  10. {
  11. base.Start();
  12. this.Toggle.onValueChanged.AddListener(new UnityAction<bool>(this.ToggleOnValueChanged));
  13. }
  14. private void ToggleOnValueChanged(bool isOn)
  15. {
  16. base.UpdateValue(isOn);
  17. }
  18. protected override void OnBind(string propertyName, Type t)
  19. {
  20. base.OnBind(propertyName, t);
  21. this.Title.text = propertyName;
  22. this.Toggle.interactable = !base.IsReadOnly;
  23. }
  24. protected override void OnValueUpdated(object newValue)
  25. {
  26. bool isOn = (bool)newValue;
  27. this.Toggle.isOn = isOn;
  28. }
  29. public override bool CanBind(Type type, bool isReadOnly)
  30. {
  31. return type == typeof(bool);
  32. }
  33. [RequiredField]
  34. public Text Title;
  35. [RequiredField]
  36. public Toggle Toggle;
  37. }
  38. }