ShowViewMgr.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using BeinLab.Util;
  6. using LitJson;
  7. using ShadowStudio.Mgr;
  8. using ShadowStudio.Model;
  9. using ShadowStudio.UI;
  10. using UnityEngine;
  11. using UnityEngine.SceneManagement;
  12. using XRTool.Util;
  13. public class ShowViewMgr : UnitySingleton<ShowViewMgr>
  14. {
  15. public event Action<List<Peer>, bool> OnUserChange;
  16. public event Action<int, int> OnRoomPageChange;//第一个是total,第二个是当前的
  17. public event Action<string, List<SceneConfig>, SceneConfig> OnChangeRoom;
  18. public string roomId;
  19. public List<ArtContainer> artContainerList;
  20. public List<SceneConfig> SceneList;
  21. public Transform Target;
  22. public static Action<SceneConfig> ChooseSenceAction;//选择场景的监听
  23. public static Action<List<SceneConfig>> RemoteSenceAction;//移除场景的监听
  24. protected override void Awake()
  25. {
  26. base.Awake();
  27. artContainerList = new List<ArtContainer>();
  28. SceneList = new List<SceneConfig>();
  29. ArtInfoMgr.Instance.ContainerCreate -= CreateSuccess;
  30. ArtInfoMgr.ContainerSelect -= OnContainerSelect;
  31. ArtInfoMgr.Instance.ContainerDel -= DeleteContainer;
  32. WSHandler.Room.OnOtherUserJoinRoom -= OtherUserJoinRoom;
  33. WSHandler.Room.OnOtherUserLeaveRoom -= OtherUserLeaveRoom;
  34. WSHandler.Room.onChangeScene -= ChangeScene;
  35. OnChangeRoom -= OnLocalChangeRoom;
  36. WSHandler.Room.OnClose -= Close;
  37. ArtInfoMgr.Instance.ContainerCreate += CreateSuccess;
  38. ArtInfoMgr.ContainerSelect += OnContainerSelect;
  39. ArtInfoMgr.Instance.ContainerDel += DeleteContainer;
  40. WSHandler.Room.OnOtherUserJoinRoom += OtherUserJoinRoom;
  41. WSHandler.Room.OnOtherUserLeaveRoom += OtherUserLeaveRoom;
  42. WSHandler.Room.onChangeScene += ChangeScene;
  43. OnChangeRoom += OnLocalChangeRoom;
  44. WSHandler.Room.OnClose += Close;
  45. }
  46. private void Close(JsonData data)
  47. {
  48. CommonMethod.ShowNetErrorAbnormalOutPop();
  49. }
  50. private void ChangeScene(string peerId, List<SceneConfig> scenes, SceneConfig currentScene)
  51. {
  52. List<SceneConfig> sceneList = new List<SceneConfig>();
  53. for (int i = 0; i < scenes.Count; i++)
  54. {
  55. sceneList.Add(scenes[i]);
  56. }
  57. OnRoomPageChange?.Invoke(scenes.Count, currentScene.Id);
  58. CompareList(SceneList, scenes, currentScene);
  59. SceneList.Clear();
  60. for (int i = 0; i < sceneList.Count; i++)
  61. {
  62. SceneList.Add(sceneList[i]);
  63. }
  64. CommonMethod.currentScene = currentScene;
  65. }
  66. private void OnLocalChangeRoom(string method, List<SceneConfig> remainscene, SceneConfig currentScene)
  67. {
  68. switch (method)
  69. {
  70. case "RemoveSence":
  71. RemoteSenceAction.Invoke(remainscene);
  72. if (ItemSenceList.Instance)
  73. {
  74. ItemSenceList.Instance.SetCreateSenceBtnBtn(true);
  75. }
  76. break;
  77. case "AddSence":
  78. ItemSenceList.Instance.Init(remainscene, currentScene);
  79. ItemSenceSmallList.Instance.Init(remainscene, currentScene);
  80. break;
  81. case "ChangeSence":
  82. break;
  83. }
  84. ChooseSenceAction?.Invoke(currentScene);
  85. }
  86. void Start()
  87. {
  88. ArtInfoMgr.Instance.ListenPage();
  89. ArtInfoMgr.Instance.ListenUser();
  90. roomId = CommonMethod.roomConfig.Id;
  91. //WSHandler.User.OnRoomChange += roomChange;
  92. TimerMgr.Instance.CreateTimer(Init, 0.5f);
  93. }
  94. private void CreateSuccess(ArtContainer artContainer)
  95. {
  96. if (artContainer.GetGoodsInfo().art_id != "ArtId_GameObject")
  97. {
  98. Texture2D icon;
  99. if (artContainer.GetContainerIcon())
  100. {
  101. icon = artContainer.GetContainerIcon() as Texture2D;
  102. artContainerList.Add(artContainer);
  103. ItemFileList.Instance.AddFileIcon(icon, artContainer);
  104. }
  105. else
  106. {
  107. //icon = new Texture2D(100, 100);
  108. artContainer.GetContainerIcon((tex) =>
  109. {
  110. if (tex)
  111. {
  112. icon = tex as Texture2D;
  113. }
  114. else
  115. {
  116. icon = new Texture2D(64, 64);
  117. }
  118. artContainerList.Add(artContainer);
  119. ItemFileList.Instance.AddFileIcon(icon, artContainer);
  120. });
  121. }
  122. }
  123. }
  124. private void DeleteContainer(ArtContainer artContainer)
  125. {
  126. if (artContainer!=null&& artContainer.GetGoodsInfo().art_id != "ArtId_GameObject")
  127. {
  128. for (int i = 0; i < ItemFileList.Instance.Itemfilelist.Count; i++)
  129. {
  130. ItemFileView itemFileView = ItemFileList.Instance.Itemfilelist[i].transform.GetComponent<ItemFileView>();
  131. if (artContainer == itemFileView.artContainer)
  132. {
  133. DestroyImmediate(ItemFileList.Instance.Itemfilelist[i]);
  134. ItemFileList.Instance.Itemfilelist.RemoveAt(i);
  135. }
  136. }
  137. artContainerList.Remove(artContainer);
  138. //FileListDlg.Instance.fileCountText.text = LanguageMgr.Instance.GetMessage("1069").Message + artContainerList.Count + LanguageMgr.Instance.GetMessage("1070").Message;
  139. }
  140. }
  141. private void OnContainerSelect(ArtContainer artContainer, bool isSelect)
  142. {
  143. if (artContainer.GetGoodsInfo().art_id != "ArtId_GameObject"&& artContainer.GetGoodsInfo().art_id != "ArtId_PlayerView")
  144. {
  145. FileListDlg.ChooseFileAction?.Invoke(artContainer,isSelect);
  146. }
  147. }
  148. private void OtherUserJoinRoom(JsonData data)
  149. {
  150. List<Peer> peerList = new List<Peer>();
  151. Peer peer = new Peer();
  152. peer.PeerId = data["data"]["peerId"].ToString();
  153. peer.NickName = data["data"]["nickName"].ToString();
  154. peer.Avatar = data["data"]["avatar"].ToString();
  155. peerList.Add(peer);
  156. if (UserItemList.Instance != null)
  157. {
  158. UserItemList.Instance.AddUserItem(peer);
  159. }
  160. OnUserChange?.Invoke(peerList, true);
  161. }
  162. public void SelfLeaveRoom()
  163. {
  164. List<Peer> peerList = new List<Peer>();
  165. peerList.Add(CommonMethod.MyPeer);
  166. OnUserChange?.Invoke(peerList, false);
  167. }
  168. private void OtherUserLeaveRoom(JsonData data)
  169. {
  170. List<Peer> peerList = new List<Peer>();
  171. Peer peer = new Peer();
  172. peer.PeerId = data["data"]["peerId"].ToString();
  173. peer.NickName = data["data"]["nickName"].ToString();
  174. peerList.Add(peer);
  175. if (UserItemList.Instance != null)
  176. {
  177. UserItemList.Instance.DeleteUserItem(peer.PeerId);
  178. }
  179. OnUserChange?.Invoke(peerList, false);
  180. }
  181. public void Init()
  182. {
  183. OnRoomPageChange?.Invoke(CommonMethod.scenes.Count, CommonMethod.currentScene.Id);
  184. WSHandler.Room.BroadcastGoodReceived(CommonMethod.GoodsInfoList);
  185. for (int i = 0; i < CommonMethod.scenes.Count; i++)
  186. {
  187. SceneList.Add(CommonMethod.scenes[i]);
  188. }
  189. List<Peer> peerList = new List<Peer>();
  190. for (int i = 0; i < CommonMethod.PeerList.Count; i++)
  191. {
  192. peerList.Add(CommonMethod.PeerList[i]);
  193. }
  194. peerList.Add(CommonMethod.MyPeer);
  195. for (int i = 0; i < peerList.Count; i++)
  196. {
  197. Debug.LogWarning(peerList[i].PeerId);
  198. }
  199. OnUserChange?.Invoke(peerList, true);
  200. if (UserItemList.Instance != null)
  201. {
  202. UserItemList.Instance.Init(peerList);
  203. }
  204. if (ItemSenceList.Instance && ItemSenceSmallList.Instance)
  205. {
  206. ItemSenceList.Instance.Init(CommonMethod.scenes, CommonMethod.currentScene);
  207. ItemSenceSmallList.Instance.Init(CommonMethod.scenes, CommonMethod.currentScene);
  208. }
  209. CommonMethod.GoodsInfoList.Clear();
  210. CommonMethod.PeerList.Clear();
  211. CommonMethod.scenes.Clear();
  212. CommonMethod.IsReceive = false;
  213. }
  214. //private void roomChange(JsonData data)
  215. //{
  216. // roomId = data["data"]["roomId"].ToString();
  217. //}
  218. public void LoadHomeSence()
  219. {
  220. CommonMethod.ShowLoading();
  221. Invoke("AllowLoadSence", 0.1f);
  222. CommonMethod.LoadSence("Home");
  223. this.gameObject.SetActive(false);
  224. }
  225. public void LoadLoginSence()
  226. {
  227. CommonMethod.ShowLoading();
  228. Invoke("AllowLoadSence", 0.1f);
  229. CommonMethod.LoadSence("Login");
  230. this.gameObject.SetActive(false);
  231. }
  232. public void AllowLoadSence()
  233. {
  234. CommonMethod.HideLoading();
  235. CommonMethod.AllowLoadSence();
  236. }
  237. protected override void OnDestroy()
  238. {
  239. base.OnDestroy();
  240. ArtInfoMgr.Instance.ContainerCreate -= CreateSuccess;
  241. WSHandler.Room.OnOtherUserJoinRoom -= OtherUserJoinRoom;
  242. WSHandler.Room.OnOtherUserLeaveRoom -= OtherUserLeaveRoom;
  243. ArtInfoMgr.ContainerSelect -= OnContainerSelect;
  244. ArtInfoMgr.Instance.ContainerDel -= DeleteContainer;
  245. WSHandler.Room.onChangeScene -= ChangeScene;
  246. OnChangeRoom -= OnLocalChangeRoom;
  247. WSHandler.Room.OnClose -= Close;
  248. }
  249. public void CompareList(List<SceneConfig> aListA, List<SceneConfig> aListB, SceneConfig currentScene)
  250. {
  251. if (aListA.Count > aListB.Count)
  252. {
  253. OnChangeRoom?.Invoke("RemoveSence", ClearRepeatItem(aListA, aListB), currentScene);
  254. }
  255. else if (aListA.Count < aListB.Count)
  256. {
  257. OnChangeRoom?.Invoke("AddSence", ClearRepeatItem(aListB, aListA), currentScene);
  258. }
  259. else
  260. {
  261. OnChangeRoom?.Invoke("ChangeSence", ClearRepeatItem(aListB, aListA), currentScene);
  262. }
  263. }
  264. private List<SceneConfig> ClearRepeatItem(List<SceneConfig> bigList, List<SceneConfig> SmallList)
  265. {
  266. List<SceneConfig> intolist = bigList.Where(a => !SmallList.Select(b => b.Id).Contains(a.Id)).ToList();
  267. //Debug.Log(intolist.Count + "AAA");
  268. return intolist;
  269. }
  270. }