UIWFSwitchPanel.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class UIWFSwitchPanel : MonoBehaviour
  5. {
  6. public void Start()
  7. {
  8. if (this.onclick_event_ != null)
  9. {
  10. return;
  11. }
  12. this.SetNumberOfSelected(this.NumberOfSelected);
  13. this.UpdateChildren();
  14. }
  15. public void SetNumberOfSelected(int num)
  16. {
  17. this.NumberOfSelected = num;
  18. this.select_button_list_ = new UIWFSelectButton[num];
  19. }
  20. public void UpdateChildren()
  21. {
  22. if (!base.enabled)
  23. {
  24. return;
  25. }
  26. if (this.select_button_list_ == null)
  27. {
  28. this.SetNumberOfSelected(this.NumberOfSelected);
  29. }
  30. if (this.onclick_event_ == null)
  31. {
  32. this.onclick_event_ = new EventDelegate(this, "OnClick");
  33. }
  34. for (int i = 0; i < this.select_button_list_.Length; i++)
  35. {
  36. this.select_button_list_[i] = null;
  37. }
  38. this.button_list_.Clear();
  39. Transform transform = base.transform;
  40. for (int j = 0; j < transform.childCount; j++)
  41. {
  42. UIWFSelectButton componentInChildren = transform.GetChild(j).GetComponentInChildren<UIWFSelectButton>();
  43. if (componentInChildren != null)
  44. {
  45. this.button_list_.Add(componentInChildren);
  46. if (!this.event_add_object_hash_list_.Contains(componentInChildren.GetHashCode()))
  47. {
  48. componentInChildren.onClick.Add(this.onclick_event_);
  49. this.event_add_object_hash_list_.Add(componentInChildren.GetHashCode());
  50. }
  51. }
  52. }
  53. }
  54. public void SelectAll()
  55. {
  56. Transform transform = base.transform;
  57. for (int i = 0; i < transform.childCount; i++)
  58. {
  59. UIWFSelectButton componentInChildren = transform.GetChild(i).GetComponentInChildren<UIWFSelectButton>();
  60. if (componentInChildren != null && !componentInChildren.isSelected)
  61. {
  62. this.Select(componentInChildren);
  63. }
  64. }
  65. }
  66. public void SelectAllRelease()
  67. {
  68. Transform transform = base.transform;
  69. for (int i = 0; i < transform.childCount; i++)
  70. {
  71. UIWFSelectButton componentInChildren = transform.GetChild(i).GetComponentInChildren<UIWFSelectButton>();
  72. if (componentInChildren != null && componentInChildren.isSelected)
  73. {
  74. this.Select(componentInChildren);
  75. }
  76. }
  77. }
  78. public void Select(UIWFSelectButton button)
  79. {
  80. if (!base.enabled)
  81. {
  82. return;
  83. }
  84. UIWFSelectButton.current = button;
  85. UIButton.current = button;
  86. EventDelegate.Execute(button.onClick);
  87. UIWFSelectButton.current = null;
  88. UIButton.current = null;
  89. }
  90. public UIWFSelectButton[] select_button_list
  91. {
  92. get
  93. {
  94. return this.select_button_list_;
  95. }
  96. }
  97. public void OnClick()
  98. {
  99. if (!base.enabled)
  100. {
  101. return;
  102. }
  103. if (UIWFSelectButton.current.isSelected)
  104. {
  105. for (int i = 0; i < this.select_button_list_.Length; i++)
  106. {
  107. if (this.select_button_list_[i] == UIWFSelectButton.current)
  108. {
  109. this.select_button_list_[i] = null;
  110. UIWFSelectButton.current.SetSelect(false);
  111. break;
  112. }
  113. }
  114. }
  115. else
  116. {
  117. for (int j = 0; j < this.select_button_list_.Length; j++)
  118. {
  119. if (this.select_button_list_[j] == null)
  120. {
  121. this.select_button_list_[j] = UIWFSelectButton.current;
  122. UIWFSelectButton.current.SetSelect(true);
  123. break;
  124. }
  125. }
  126. }
  127. bool flag = true;
  128. for (int k = 0; k < this.select_button_list_.Length; k++)
  129. {
  130. if (this.select_button_list_[k] == null)
  131. {
  132. flag = false;
  133. break;
  134. }
  135. }
  136. if (flag)
  137. {
  138. for (int l = 0; l < this.button_list_.Count; l++)
  139. {
  140. if (!this.button_list_[l].isSelected)
  141. {
  142. this.button_list_[l].isEnabled = false;
  143. }
  144. }
  145. }
  146. else
  147. {
  148. for (int m = 0; m < this.button_list_.Count; m++)
  149. {
  150. if (!this.button_list_[m].isSelected && !this.button_list_[m].isEnabled)
  151. {
  152. this.button_list_[m].isEnabled = true;
  153. }
  154. }
  155. }
  156. }
  157. public int NumberOfSelected = 1;
  158. private List<UIWFSelectButton> button_list_ = new List<UIWFSelectButton>();
  159. private EventDelegate onclick_event_;
  160. private HashSet<int> event_add_object_hash_list_ = new HashSet<int>();
  161. private UIWFSelectButton[] select_button_list_;
  162. }