ConfigSelectButton.cs 967 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System;
  2. using UnityEngine;
  3. public class ConfigSelectButton : MonoBehaviour
  4. {
  5. protected bool srcValue
  6. {
  7. get
  8. {
  9. return this.onGetValue != null && this.onGetValue();
  10. }
  11. set
  12. {
  13. if (this.onSetValue != null)
  14. {
  15. this.onSetValue(value);
  16. }
  17. }
  18. }
  19. public void Initialize()
  20. {
  21. this.UpdateButton();
  22. EventDelegate.Add(this.onButton.onClick, delegate()
  23. {
  24. this.srcValue = true;
  25. this.SetSelect(true);
  26. });
  27. EventDelegate.Add(this.offButton.onClick, delegate()
  28. {
  29. this.srcValue = false;
  30. this.SetSelect(false);
  31. });
  32. }
  33. public void UpdateButton()
  34. {
  35. this.SetSelect(this.srcValue);
  36. }
  37. private void SetSelect(bool isOn)
  38. {
  39. bool flag = false;
  40. if (isOn)
  41. {
  42. flag = true;
  43. }
  44. this.onButton.SetSelect(flag);
  45. this.offButton.SetSelect(!flag);
  46. }
  47. [SerializeField]
  48. private UIWFTabButton onButton;
  49. [SerializeField]
  50. private UIWFTabButton offButton;
  51. public Func<bool> onGetValue;
  52. public Action<bool> onSetValue;
  53. }