SelectButtonCtrl.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. public class SelectButtonCtrl : MonoBehaviour
  6. {
  7. public void Awake()
  8. {
  9. if (this.Panel == null)
  10. {
  11. this.Panel = base.transform.parent.gameObject.GetComponent<UIPanel>();
  12. }
  13. }
  14. public void CreateSelectButtons(List<KeyValuePair<string, KeyValuePair<string, bool>>> listSelectBtn, Action<string, string> onClickCallBack, UnityEngine.Object selectBtnPrefab)
  15. {
  16. this.m_OnClickCallBack = null;
  17. this.m_OnClickCallEvent = null;
  18. this.ClearExistSelectButton();
  19. this.m_OnClickCallBack = onClickCallBack;
  20. this.m_listSelectBtn = new List<KeyValuePair<string, SelectButtonCtrl.SelectButton>>();
  21. int num = 0;
  22. foreach (KeyValuePair<string, KeyValuePair<string, bool>> keyValuePair in listSelectBtn)
  23. {
  24. GameObject gameObject = UnityEngine.Object.Instantiate(selectBtnPrefab) as GameObject;
  25. UIButton component = gameObject.GetComponent<UIButton>();
  26. EventDelegate.Add(component.onClick, new EventDelegate.Callback(this.ClickSelectButton));
  27. gameObject.name = "selectButton_" + num;
  28. gameObject.transform.parent = base.transform;
  29. gameObject.transform.localScale = Vector3.one;
  30. gameObject.transform.localPosition = Vector3.zero;
  31. gameObject.transform.rotation = Quaternion.identity;
  32. EventDelegate.Set(gameObject.GetComponent<TweenAlpha>().onFinished, new EventDelegate.Callback(this.OnFinished));
  33. UILabel component2 = UTY.GetChildObject(gameObject, "Option", false).GetComponent<UILabel>();
  34. component2.text = keyValuePair.Key;
  35. SelectButtonCtrl.SelectButton selectButton = new SelectButtonCtrl.SelectButton();
  36. selectButton.m_btnName = gameObject.name;
  37. selectButton.m_goSelectBtn = gameObject;
  38. selectButton.m_msg = keyValuePair.Key;
  39. selectButton.m_tag = keyValuePair.Value.Key;
  40. component.isEnabled = keyValuePair.Value.Value;
  41. this.m_listSelectBtn.Add(new KeyValuePair<string, SelectButtonCtrl.SelectButton>(selectButton.m_btnName, selectButton));
  42. num++;
  43. }
  44. base.GetComponent<UIGrid>().Reposition();
  45. this.m_EffectStat = SelectButtonCtrl.EffectStat.Null;
  46. }
  47. public void SetPanelAlpha(float value)
  48. {
  49. this.Awake();
  50. this.Panel.alpha = value;
  51. }
  52. public bool IsPlayingEffect()
  53. {
  54. return this.m_EffectStat != SelectButtonCtrl.EffectStat.Null;
  55. }
  56. public void ClearExistSelectButton()
  57. {
  58. IEnumerator enumerator = base.transform.GetEnumerator();
  59. try
  60. {
  61. while (enumerator.MoveNext())
  62. {
  63. object obj = enumerator.Current;
  64. Transform transform = (Transform)obj;
  65. UnityEngine.Object.Destroy(transform.gameObject);
  66. }
  67. }
  68. finally
  69. {
  70. IDisposable disposable;
  71. if ((disposable = (enumerator as IDisposable)) != null)
  72. {
  73. disposable.Dispose();
  74. }
  75. }
  76. }
  77. public void ClickSelectButton()
  78. {
  79. string b = string.Empty;
  80. b = UIButton.current.name;
  81. foreach (KeyValuePair<string, SelectButtonCtrl.SelectButton> keyValuePair in this.m_listSelectBtn)
  82. {
  83. GameObject goSelectBtn = keyValuePair.Value.m_goSelectBtn;
  84. if (keyValuePair.Key == b)
  85. {
  86. if (GameMain.Instance.ScriptMgr.adv_kag.skip_mode)
  87. {
  88. TweenAlpha.Begin(goSelectBtn, 0.01f, 0f);
  89. }
  90. else
  91. {
  92. TweenAlpha.Begin(keyValuePair.Value.m_goSelectBtn, 1f * GameMain.Instance.CMSystem.FadeSpeedRate, 0f);
  93. }
  94. if (this.m_OnClickCallBack != null)
  95. {
  96. string text = keyValuePair.Value.m_msg;
  97. string tag = keyValuePair.Value.m_tag;
  98. Action<string, string> tmp = this.m_OnClickCallBack;
  99. this.m_OnClickCallEvent = delegate
  100. {
  101. tmp(text, tag);
  102. };
  103. this.m_OnClickCallBack = null;
  104. }
  105. }
  106. else
  107. {
  108. goSelectBtn.GetComponent<TweenAlpha>().onFinished = null;
  109. if (GameMain.Instance.ScriptMgr.adv_kag.skip_mode)
  110. {
  111. TweenAlpha.Begin(goSelectBtn, 0.01f, 0f);
  112. }
  113. else
  114. {
  115. TweenAlpha.Begin(goSelectBtn, 0.3f * GameMain.Instance.CMSystem.FadeSpeedRate, 0f);
  116. }
  117. }
  118. goSelectBtn.GetComponent<BoxCollider>().enabled = false;
  119. }
  120. this.m_EffectStat = SelectButtonCtrl.EffectStat.EndOut;
  121. }
  122. private void OnFinished()
  123. {
  124. if (this.dragMat == null)
  125. {
  126. this.dragMat = base.transform.parent.parent.Find("DragMat").gameObject;
  127. }
  128. this.dragMat.SetActive(false);
  129. this.ClearExistSelectButton();
  130. base.transform.parent.GetComponent<UIScrollView>().ResetPosition();
  131. this.m_EffectStat = SelectButtonCtrl.EffectStat.Null;
  132. if (this.m_OnClickCallEvent != null)
  133. {
  134. this.m_OnClickCallEvent();
  135. }
  136. this.m_OnClickCallEvent = null;
  137. }
  138. [SerializeField]
  139. private GameObject dragMat;
  140. private UIPanel Panel;
  141. private List<KeyValuePair<string, SelectButtonCtrl.SelectButton>> m_listSelectBtn;
  142. private Action<string, string> m_OnClickCallBack;
  143. private Action m_OnClickCallEvent;
  144. private SelectButtonCtrl.EffectStat m_EffectStat;
  145. private enum EffectStat
  146. {
  147. Null,
  148. StartIn,
  149. EndOut
  150. }
  151. private class SelectButton
  152. {
  153. public string m_btnName { get; set; }
  154. public string m_msg { get; set; }
  155. public string m_tag { get; set; }
  156. public GameObject m_goSelectBtn { get; set; }
  157. public override string ToString()
  158. {
  159. return string.Format("SelectButton=[m_btnName={0}, m_msg={1}, m_tag={2}, m_goSelectBtn={3}]", new object[]
  160. {
  161. this.m_btnName,
  162. this.m_msg,
  163. this.m_tag,
  164. this.m_goSelectBtn
  165. });
  166. }
  167. }
  168. }