HomeMgr.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using LitJson;
  5. using SC.XR.Unity.Module_InputSystem;
  6. using ShadowStudio.Model;
  7. using ShadowStudio.UI;
  8. using Studio.Scripts;
  9. using Studio.WebSocket.Message;
  10. using UnityEngine;
  11. using UnityEngine.SceneManagement;
  12. using XRTool.Util;
  13. namespace ShadowStudio.Mgr
  14. {
  15. public class HomeMgr : UnitySingleton<HomeMgr>
  16. {
  17. /// <summary>
  18. /// 场景中游戏对象界面集合(除房间显示界面以外)
  19. /// </summary>
  20. private List<GameObject> ViewList;
  21. public static int CREATESEARCHRROOMDLG = 0;
  22. public static int CREATROOMDLG = 1;
  23. public static int AboutMeDlg = 2;
  24. /// <summary>
  25. /// 场景中显示房间游戏对象
  26. /// </summary>
  27. public GameObject roomListDlg
  28. {
  29. get;
  30. set;
  31. }
  32. /// <summary>
  33. /// 房间游戏对象身上的 MenuListDlg 脚本
  34. /// </summary>
  35. public MenuListDlg _menuListDlg
  36. {
  37. get;
  38. set;
  39. }
  40. /// <summary>
  41. /// 自己创建的房间数据集合(作为数据备份)
  42. /// </summary>
  43. public List<RoomConfig> SelfRoomConfigList
  44. {
  45. get;
  46. set;
  47. }
  48. void Start()//初始化
  49. {
  50. ViewList = new List<GameObject>();
  51. SelfRoomConfigList = new List<RoomConfig>();
  52. roomListDlg = transform.GetChild(0).gameObject;
  53. _menuListDlg = roomListDlg.GetComponent<MenuListDlg>();
  54. Invoke("InitViewList", 1f);
  55. //请求数据以及处理数据
  56. WSHandler.User.OnGetSelfRoomList -= getRoomList;
  57. WSHandler.User.OnGetSelfRoomList += getRoomList;//(收到数据后)处理数据的方法
  58. WSHandler.User.GetSelfRoomList();//向服务器请求数据
  59. HomeProxy.Instance.GetSettingsAction += GetSettings;
  60. HomeProxy.Instance.RequestGetSettings();
  61. }
  62. /// <summary>
  63. /// 获取房间数据信息以及处理数据
  64. /// </summary>
  65. /// <param name="data"></param>
  66. private void getRoomList(SelfRoomListResponseMessage roomListData)
  67. {
  68. for (int i = 0,roomCount = roomListData.data.Count; i < roomCount; i++)
  69. {
  70. RoomNetData roomNetData = roomListData.data[i];
  71. RoomConfig itemConfig = new RoomConfig(roomNetData, "1");
  72. ConfigModel.Instance.InitElement(itemConfig);
  73. SelfRoomConfigList.Add(itemConfig);
  74. }
  75. while (ConfigModel.Instance.Count < 5)//如果数据不够五个,则补齐为五个数据(造假空数据)
  76. {
  77. RoomConfig itemConfig = new RoomConfig("", "1", "教育", "", "", "", "", "", "", "");
  78. ConfigModel.Instance.InitElement(itemConfig);
  79. SelfRoomConfigList.Add(itemConfig);
  80. }
  81. StartCoroutine(InitRoomList());
  82. }
  83. private void GetSettings(MySetting mySetting)
  84. {
  85. CommonMethod.mySetting = mySetting;
  86. }
  87. /// <summary>
  88. /// 初始化房间游戏对象
  89. /// </summary>
  90. /// <returns></returns>
  91. IEnumerator InitRoomList()
  92. {
  93. /*
  94. * 由于WorldDlg在start函数里进行了0.02秒的缩放延迟:(由(0,0,0)放大为正常尺寸)
  95. 所以这里为了避免初始化冲突,则也同样进行0.02秒的延迟处理来保证代码的流程
  96. */
  97. yield return new WaitForSeconds(0.02f);
  98. _menuListDlg._menuUI.Init();//初始化游戏对象
  99. MenuListDlg.Instance.UpdateData();//刷新数据显示
  100. _menuListDlg.Show();//显示房间游戏对象(动画)
  101. }
  102. /// <summary>
  103. /// 初始化场景中游戏对象界面集合(除房间显示界面以外)
  104. /// </summary>
  105. public void InitViewList()
  106. {
  107. for (int i = 0; i < transform.childCount; i++)
  108. {
  109. ViewList.Add(transform.GetChild(i).gameObject);
  110. }
  111. ViewList.RemoveAt(0);
  112. }
  113. /// <summary>
  114. /// 显示指定索引的界面
  115. /// </summary>
  116. /// <param name="index"></param>
  117. public void ShowView(int index)
  118. {
  119. for (int i = 0; i < ViewList.Count; i++)
  120. {
  121. if (index == i)
  122. {
  123. ViewList[i].SetActive(true);
  124. }
  125. else
  126. {
  127. ViewList[i].SetActive(false);
  128. }
  129. }
  130. }
  131. public void LoadSence()
  132. {
  133. CommonMethod.ShowLoading();
  134. Invoke("LoadShowSence", 0.1f);
  135. CommonMethod.LoadSence("Show");
  136. this.gameObject.SetActive(false);
  137. }
  138. public void LoadShowSence()
  139. {
  140. CommonMethod.HideLoading();
  141. CommonMethod.AllowLoadSence();
  142. }
  143. protected override void OnDestroy()
  144. {
  145. base.OnDestroy();
  146. WSHandler.User.OnGetSelfRoomList -= getRoomList;
  147. if (HomeProxy.Instance)
  148. {
  149. HomeProxy.Instance.GetSettingsAction -= GetSettings;
  150. }
  151. }
  152. public void LoadLoginSence()
  153. {
  154. CommonMethod.ShowLoading();
  155. Invoke("AllowLoadSence", 0.1f);
  156. CommonMethod.LoadSence("Login");
  157. this.gameObject.SetActive(false);
  158. }
  159. public void AllowLoadSence()
  160. {
  161. CommonMethod.HideLoading();
  162. CommonMethod.AllowLoadSence();
  163. }
  164. }
  165. }