PopUIManager.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. /// <summary>
  5. /// 这里主要处理和登录相关的UI
  6. ///
  7. /// </summary>
  8. public class PopUIManager : MonoBehaviour {
  9. [SerializeField]
  10. private PopBase[] popAry;//所有的POP弹框
  11. private Dictionary<PopType, PopBase> popDict = new Dictionary<PopType, PopBase>();
  12. void Start () {
  13. InitPops();
  14. MessageCenterController.Instance.Register(GameEnum.MESSAGE_ENTER_COURSE, EnterCourse);//创建房间后 进入房间
  15. MessageCenterController.Instance.Register(GameEnum.MESSAGE_EXIT_COURSE, ExitCourse);//退出房间
  16. MessageCenterController.Instance.Register(GameEnum.MESSAGE_SHOW_RECONNECT_POP, ShowReConnect);//重连
  17. MessageCenterController.Instance.Register(GameEnum.MESSAGE_SHOW_LOGOUT, ShowLogOut);//登出
  18. MessageCenterController.Instance.Register(GameEnum.MESSAGE_RESET_ACCOUNT, ShowResetLogin);//账号重置
  19. MessageCenterController.Instance.Register(GameEnum.MESSAGE_SHOW_MSG_POP, ShowMsgPop);//消息提示框弹出
  20. MessageCenterController.Instance.Register(GameEnum.MESSAGE_SHOW_CHANGE_CONFIRM_POP, ShowChangeConfirm);
  21. MessageCenterController.Instance.Register(GameEnum.MESSAGE_SHOW_IMAGE_POP, ShowImagePop);
  22. MessageCenterController.Instance.Register(GameEnum.MESSAGE_HIDE_IMAGE_POP, HIdeImagePop);
  23. MessageCenterController.Instance.Register(GameEnum.MESSAGE_HIDE_POP_BY_TYPE, HidePop);//影藏弹框
  24. MessageCenterController.Instance.Register(GameEnum.MESSAGE_SHOW_POP_BY_TYPE, ShowPop);//显示弹框
  25. }
  26. private void OnDestroy()
  27. {
  28. MessageCenterController.Instance.UnRegister(GameEnum.MESSAGE_ENTER_COURSE, EnterCourse);//创建房间后 进入房间
  29. MessageCenterController.Instance.UnRegister(GameEnum.MESSAGE_SHOW_RECONNECT_POP, ShowReConnect);//重连
  30. MessageCenterController.Instance.UnRegister(GameEnum.MESSAGE_SHOW_LOGOUT, ShowLogOut);//登出
  31. MessageCenterController.Instance.UnRegister(GameEnum.MESSAGE_RESET_ACCOUNT, ShowResetLogin);//账号重置
  32. MessageCenterController.Instance.UnRegister(GameEnum.MESSAGE_SHOW_MSG_POP, ShowMsgPop);//消息提示框弹出
  33. MessageCenterController.Instance.UnRegister(GameEnum.MESSAGE_SHOW_CHANGE_CONFIRM_POP, ShowChangeConfirm);
  34. MessageCenterController.Instance.UnRegister(GameEnum.MESSAGE_SHOW_IMAGE_POP, ShowImagePop);
  35. MessageCenterController.Instance.UnRegister(GameEnum.MESSAGE_HIDE_IMAGE_POP, HIdeImagePop);
  36. MessageCenterController.Instance.UnRegister(GameEnum.MESSAGE_HIDE_POP_BY_TYPE, HidePop);//影藏弹框
  37. MessageCenterController.Instance.UnRegister(GameEnum.MESSAGE_SHOW_POP_BY_TYPE, ShowPop);//显示弹框
  38. }
  39. private void InitPops()
  40. {
  41. //初始化POP的列表
  42. for (int i = 0; i < popAry.Length; i++)
  43. {
  44. if (popDict.ContainsKey(popAry[i].MType))
  45. {
  46. CDebug.Log(popAry[i].name + " 类型异常");
  47. }
  48. else
  49. {
  50. if (popAry[i].MType == PopType.Login)
  51. {
  52. popAry[i].Show();
  53. }
  54. else
  55. {
  56. popAry[i].gameObject.SetActive(false);
  57. }
  58. popDict.Add(popAry[i].MType, popAry[i]);
  59. }
  60. }
  61. }
  62. private void SetPop(PopType t, bool v, System.Object datas = null)
  63. {
  64. if (v)
  65. {
  66. if (datas != null)
  67. {
  68. GetPopByType(t).Show(datas);
  69. }
  70. else
  71. {
  72. GetPopByType(t).Show();
  73. }
  74. }
  75. else
  76. {
  77. GetPopByType(t).Hide();
  78. }
  79. }
  80. private PopBase GetPopByType(PopType t)
  81. {
  82. //CDebug.Log(t.ToString());
  83. if(!popDict.ContainsKey(t))
  84. {
  85. CDebug.Log(t.ToString() + "不存在");
  86. }
  87. return popDict[t];
  88. }
  89. private void EnterCourse(System.Object datas = null)
  90. {
  91. SetPop(PopType.Login, false);
  92. SetPop(PopType.RoomList, false);
  93. SetPop(PopType.CourseList, false);
  94. }
  95. private void ExitCourse(System.Object datas = null)
  96. {
  97. SetPop(PopType.RoomList, true);
  98. HIdeImagePop(null);
  99. }
  100. //检查重连
  101. public void ShowReConnect(System.Object datas = null)
  102. {
  103. SetPop(PopType.Reconnect, true);
  104. }
  105. private void ShowImagePop(System.Object datas)
  106. {
  107. SetPop(PopType.Image, true, datas);
  108. }
  109. private void HIdeImagePop(System.Object datas)
  110. {
  111. SetPop(PopType.Image, false);
  112. }
  113. private void ShowMsgPop(System.Object datas = null)
  114. {
  115. SetPop(PopType.Msg, true, datas);
  116. }
  117. //切换房主
  118. private void ShowChangeConfirm(System.Object datas = null)
  119. {
  120. SetPop(PopType.ChangeMaster, true, datas);
  121. }
  122. private void ShowLogOut(System.Object data = null)
  123. {
  124. SetPop(PopType.Login, true, true);
  125. SetPop(PopType.Msg, true, "账号登出");
  126. SetPop(PopType.RoomList, false);
  127. SetPop(PopType.CourseList, false);
  128. }
  129. public void ShowResetLogin(System.Object data = null)
  130. {
  131. SetPop(PopType.Login, true, true);
  132. SetPop(PopType.RoomList, false);
  133. SetPop(PopType.CourseList, false);
  134. }
  135. private void ShowNotice(System.Object data = null)
  136. {
  137. //CDebug.Log("ShowNotice-->" + data.ToString());
  138. SetPop(PopType.BadConnecting, true, data);
  139. }
  140. private void HideNotice(System.Object data = null)
  141. {
  142. //CDebug.Log("HideNotice-->");
  143. SetPop(PopType.BadConnecting, false, data);
  144. }
  145. private void ShowAnswerPop(System.Object datas = null)
  146. {
  147. SetPop(PopType.Answer, true, datas);
  148. }
  149. private void HideAnswerPop(System.Object datas = null)
  150. {
  151. SetPop(PopType.Answer, false);
  152. }
  153. private void HidePop(System.Object data = null)
  154. {
  155. PopType t = (PopType)data;
  156. SetPop(t, false);
  157. }
  158. private void ShowPop(System.Object data = null)
  159. {
  160. ShowPopData t = data as ShowPopData;
  161. SetPop(t.t, true, t.data);
  162. }
  163. }