CoursePannelManager.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. /// <summary>
  6. /// 这里主要处理课程开始后的UI
  7. ///
  8. /// </summary>
  9. public class CoursePannelManager : MonoBehaviour
  10. {
  11. [SerializeField]
  12. private CourseBarView CourseUI;
  13. [SerializeField]
  14. private GameObject Quanxi;
  15. [SerializeField]
  16. private BasePannel[] pannelAry;//所有的POP弹框
  17. private Dictionary<PannelType, BasePannel> pannelDict = new Dictionary<PannelType, BasePannel>();
  18. [SerializeField]
  19. private OnLineUserListPannel mOnLineUserListPannel;
  20. [SerializeField]
  21. private StudentPannel mStudentUIPannel;
  22. //当前的展示页面
  23. private PannelType curType = PannelType.Default;
  24. private void Awake()
  25. {
  26. mOnLineUserListPannel.Hide();
  27. mStudentUIPannel.Hide();
  28. }
  29. void Start()
  30. {
  31. InitPannels();
  32. CourseUI.Hide();
  33. SetQuanxi(false);
  34. MessageCenterController.Instance.Register(GameEnum.MESSAGE_ENTER_COURSE, EnterCourse);//进入房间
  35. MessageCenterController.Instance.Register(GameEnum.MESSAGE_EXIT_COURSE, ExitCourse);//关闭房间
  36. MessageCenterController.Instance.Register(GameEnum.MESSAGE_SHOW_COURSE, ShowCourse);//显示房间
  37. MessageCenterController.Instance.Register(GameEnum.MESSAGE_HIDE_COURSE, HideCourse);//隐藏房间
  38. MessageCenterController.Instance.Register(GameEnum.MESSAGE_SHOW_LOGOUT, ExitCourse);//登出
  39. MessageCenterController.Instance.Register(GameEnum.MESSAGE_RESET_ACCOUNT, ExitCourse);//账号重置
  40. MessageCenterController.Instance.Register(GameEnum.MESSAGE_SHOW_PANNEL_BY_TYPE, ShowPannelByType);//
  41. MessageCenterController.Instance.Register(GameEnum.MESSAGE_SEND_CHANGE_ROOM_OWNER_REFRESH, OwnerChange);//有房主的变动
  42. MessageCenterController.Instance.Register(GameEnum.MESSAGE_SHOW_MSG_NOTICE, ShowNotice);//显示提示
  43. MessageCenterController.Instance.Register(GameEnum.MESSAGE_HIDE_MSG_NOTICE, HideNotice);//隐藏提示
  44. }
  45. private void OnDestroy()
  46. {
  47. MessageCenterController.Instance.UnRegister(GameEnum.MESSAGE_ENTER_COURSE, EnterCourse);//进入房间
  48. MessageCenterController.Instance.UnRegister(GameEnum.MESSAGE_EXIT_COURSE, ExitCourse);//关闭房间
  49. MessageCenterController.Instance.UnRegister(GameEnum.MESSAGE_SHOW_LOGOUT, ExitCourse);//登出
  50. MessageCenterController.Instance.UnRegister(GameEnum.MESSAGE_RESET_ACCOUNT, ExitCourse);//账号重置
  51. MessageCenterController.Instance.UnRegister(GameEnum.MESSAGE_SHOW_PANNEL_BY_TYPE, ShowPannelByType);//房间列表
  52. MessageCenterController.Instance.UnRegister(GameEnum.MESSAGE_SEND_CHANGE_ROOM_OWNER_REFRESH, OwnerChange);//有房主的变动
  53. MessageCenterController.Instance.UnRegister(GameEnum.MESSAGE_SHOW_MSG_NOTICE, ShowNotice);//显示提示
  54. MessageCenterController.Instance.UnRegister(GameEnum.MESSAGE_HIDE_MSG_NOTICE, HideNotice);//隐藏提示
  55. }
  56. private void InitPannels()
  57. {
  58. //刚开始的时候影藏Pannel的列表
  59. for (int i = 0; i < pannelAry.Length; i++)
  60. {
  61. if (pannelDict.ContainsKey(pannelAry[i].MType))
  62. {
  63. CDebug.Log(pannelAry[i].name + " 类型异常");
  64. }
  65. else
  66. {
  67. pannelAry[i].Hide();
  68. pannelDict.Add(pannelAry[i].MType, pannelAry[i]);
  69. }
  70. }
  71. }
  72. private void ResetAllPannelDatas()
  73. {
  74. //刚开始的时候影藏Pannel的列表
  75. for (int i = 0; i < pannelAry.Length; i++)
  76. {
  77. pannelAry[i].InitManagerData();
  78. }
  79. }
  80. private void ChangePannel(PannelType t)
  81. {
  82. if (curType != PannelType.Default)
  83. pannelDict[curType].Hide();
  84. curType = t;
  85. if (curType != PannelType.Default)
  86. pannelDict[curType].Show();
  87. if (curType != PannelType.Question)
  88. {
  89. MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_HIDE_IMAGE_POP);
  90. }
  91. }
  92. private void ShowPannelByType(System.Object datas = null)
  93. {
  94. PannelType t = (PannelType)datas;
  95. pannelDict[t].InitManagerData();
  96. ChangePannel(t);
  97. OwnerChange();
  98. this.CourseUI.Show();
  99. SetQuanxi(GamePlayerData.Instance.IsFangzhu());
  100. LoadPrefabManager.Instance.ResetObj();//清除加载的缓存
  101. }
  102. private string title_str = "{0}-{1}";
  103. private string user_name_str = "用户名: {0}";
  104. private string room_str = "房间名字: {0}";
  105. private void EnterCourse(System.Object datas = null)
  106. {
  107. UIDataManager.Instance.Init();//清空需要同步的数据
  108. LoadPrefabManager.Instance.ResetObj();//清除加载的缓存
  109. CourseUI.Show();//主面板的初始化
  110. SetQuanxi(GamePlayerData.Instance.IsFangzhu());
  111. if (GamePlayerData.Instance.IsFangzhu())
  112. {
  113. ResetAllPannelDatas();
  114. CDebug.Log("是房主直接打开默认的Pannel");
  115. ChangePannel(PannelType.Goal);
  116. }
  117. else
  118. {
  119. CDebug.Log("不是房主等待同步房主的Pannel");
  120. }
  121. OwnerChange();
  122. MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_REFRESH_USER_LIST_DATA);
  123. MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_OPEN_COURSE_PANNEL);
  124. }
  125. private void ExitCourse(System.Object datas = null)
  126. {
  127. UIDataManager.Instance.Reset();
  128. //移除有可能存在的答案的弹框
  129. MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_HIDE_POP_BY_TYPE, PopType.Answer);
  130. CourseUI.Hide();
  131. SetQuanxi(false);
  132. if(pannelDict.ContainsKey(curType))
  133. pannelDict[curType].Hide();
  134. mOnLineUserListPannel.Hide();
  135. mStudentUIPannel.Hide();
  136. LoadPrefabManager.Instance.ResetObj();//清除加载的缓存
  137. UIDataManager.Instance.ClearAll();
  138. }
  139. private void ShowCourse(System.Object datas = null)
  140. {
  141. OwnerChange();
  142. this.CourseUI.Show();
  143. pannelDict[curType].Show();
  144. SetQuanxi(GamePlayerData.Instance.IsFangzhu());
  145. LoadPrefabManager.Instance.ResetObj();//清除加载的缓存
  146. }
  147. private void HideCourse(System.Object datas = null)
  148. {
  149. this.CourseUI.Hide();
  150. mOnLineUserListPannel.Hide();
  151. mStudentUIPannel.Hide();
  152. SetQuanxi(false);
  153. if (pannelDict.ContainsKey(curType))
  154. pannelDict[curType].Hide();
  155. }
  156. private void SetQuanxi(bool v)
  157. {
  158. Quanxi.gameObject.SetActive(false);
  159. }
  160. private void OwnerChange(System.Object data = null)
  161. {
  162. if (GamePlayerData.Instance.user_type == 0 || GamePlayerData.Instance.user_type == 3)
  163. {
  164. mOnLineUserListPannel.Show();
  165. mStudentUIPannel.Hide();
  166. }
  167. else
  168. {
  169. mOnLineUserListPannel.Hide();
  170. mStudentUIPannel.Show();
  171. }
  172. }
  173. private void ShowNotice(System.Object data = null)
  174. {
  175. //CDebug.Log("ShowNotice-->" + data.ToString());
  176. }
  177. private void HideNotice(System.Object data = null)
  178. {
  179. //CDebug.Log("HideNotice-->");
  180. }
  181. private void ShowLogOut(System.Object data = null)
  182. {
  183. //如果当前面板有开启的话 就关掉它
  184. }
  185. private void RefreshChatTip()
  186. {
  187. }
  188. }