uGUITabPanel.cs 2.7 KB

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