ShowViewMgr.cs 10 KB

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