UIWFTabPanel.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class UIWFTabPanel : MonoBehaviour
  5. {
  6. public void Start()
  7. {
  8. if (this.onclick_event_ != null)
  9. {
  10. return;
  11. }
  12. this.UpdateChildren();
  13. }
  14. public void AddChildrenList(List<UIWFTabButton> button_list)
  15. {
  16. if (!base.enabled)
  17. {
  18. return;
  19. }
  20. if (this.onclick_event_ == null)
  21. {
  22. this.onclick_event_ = new EventDelegate(this, "OnClick");
  23. }
  24. this.button_list_.Clear();
  25. for (int i = 0; i < button_list.Count; i++)
  26. {
  27. UIWFTabButton uiwftabButton = this.button_list_[i];
  28. if (uiwftabButton != null)
  29. {
  30. bool flag = false;
  31. for (int j = 0; j < uiwftabButton.onClick.Count; j++)
  32. {
  33. if (uiwftabButton.onClick[j] == this.onclick_event_)
  34. {
  35. flag = true;
  36. break;
  37. }
  38. }
  39. if (!flag)
  40. {
  41. uiwftabButton.onClick.Add(this.onclick_event_);
  42. }
  43. }
  44. }
  45. }
  46. public void UpdateChildren()
  47. {
  48. if (!base.enabled)
  49. {
  50. return;
  51. }
  52. if (this.onclick_event_ == null)
  53. {
  54. this.onclick_event_ = new EventDelegate(this, "OnClick");
  55. }
  56. this.button_list_.Clear();
  57. Transform transform = base.transform;
  58. for (int i = 0; i < transform.childCount; i++)
  59. {
  60. if (transform.gameObject.activeSelf)
  61. {
  62. UIWFTabButton componentInChildren = transform.GetChild(i).GetComponentInChildren<UIWFTabButton>();
  63. if (componentInChildren != null)
  64. {
  65. this.button_list_.Add(componentInChildren);
  66. bool flag = false;
  67. for (int j = 0; j < componentInChildren.onClick.Count; j++)
  68. {
  69. if (componentInChildren.onClick[j] == this.onclick_event_)
  70. {
  71. flag = true;
  72. break;
  73. }
  74. }
  75. if (!flag)
  76. {
  77. componentInChildren.onClick.Add(this.onclick_event_);
  78. }
  79. }
  80. }
  81. }
  82. }
  83. public void Select(UIWFTabButton button)
  84. {
  85. if (!base.enabled)
  86. {
  87. return;
  88. }
  89. UIWFTabButton current = UIWFTabButton.current;
  90. UIButton current2 = UIButton.current;
  91. UIWFTabButton.current = button;
  92. UIButton.current = button;
  93. EventDelegate.Execute(button.onClick);
  94. UIWFTabButton.current = current;
  95. UIButton.current = current2;
  96. }
  97. public void ResetSelect()
  98. {
  99. this.select_button_ = null;
  100. }
  101. public UIWFTabButton GetSelectButtonObject()
  102. {
  103. return this.select_button_;
  104. }
  105. private void OnClick()
  106. {
  107. if (!base.enabled)
  108. {
  109. return;
  110. }
  111. for (int i = 0; i < this.button_list_.Count; i++)
  112. {
  113. if (this.button_list_[i].enabled)
  114. {
  115. bool flag = UIButton.current == this.button_list_[i];
  116. if (flag)
  117. {
  118. this.select_button_ = this.button_list_[i];
  119. }
  120. this.button_list_[i].SetSelect(flag);
  121. }
  122. }
  123. }
  124. public List<UIWFTabButton> button_list
  125. {
  126. get
  127. {
  128. return this.button_list_;
  129. }
  130. }
  131. private List<UIWFTabButton> button_list_ = new List<UIWFTabButton>();
  132. private EventDelegate onclick_event_;
  133. private HashSet<int> event_add_object_hash_list_ = new HashSet<int>();
  134. private UIWFTabButton select_button_;
  135. }