ShowViewMgr.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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. Debug.LogError("非房主进入房间");
  97. if (CommonMethod.roomConfig.Room_type == "1")
  98. {
  99. Debug.Log("公开浏览");
  100. GameObject.Find("CreateSenceBtn").GetComponent<Button>().enabled = false;
  101. }
  102. }
  103. else
  104. Debug.LogError("房主进入房间");
  105. }
  106. private void CreateSuccess(ArtContainer artContainer)
  107. {
  108. if (artContainer.GetGoodsInfo().art_id != "ArtId_GameObject")
  109. {
  110. Texture2D icon;
  111. if (artContainer.GetContainerIcon())
  112. {
  113. icon = artContainer.GetContainerIcon() as Texture2D;
  114. artContainerList.Add(artContainer);
  115. ItemFileList.Instance.AddFileIcon(icon, artContainer);
  116. }
  117. else
  118. {
  119. //icon = new Texture2D(100, 100);
  120. artContainer.GetContainerIcon((tex) =>
  121. {
  122. if (tex)
  123. {
  124. icon = tex as Texture2D;
  125. }
  126. else
  127. {
  128. icon = new Texture2D(64, 64);
  129. }
  130. artContainerList.Add(artContainer);
  131. ItemFileList.Instance.AddFileIcon(icon, artContainer);
  132. });
  133. }
  134. }
  135. }
  136. private void DeleteContainer(ArtContainer artContainer)
  137. {
  138. if (artContainer!=null&& artContainer.GetGoodsInfo().art_id != "ArtId_GameObject")
  139. {
  140. for (int i = 0; i < ItemFileList.Instance.Itemfilelist.Count; i++)
  141. {
  142. ItemFileView itemFileView = ItemFileList.Instance.Itemfilelist[i].transform.GetComponent<ItemFileView>();
  143. if (artContainer == itemFileView.artContainer)
  144. {
  145. DestroyImmediate(ItemFileList.Instance.Itemfilelist[i]);
  146. ItemFileList.Instance.Itemfilelist.RemoveAt(i);
  147. }
  148. }
  149. artContainerList.Remove(artContainer);
  150. //FileListDlg.Instance.fileCountText.text = LanguageMgr.Instance.GetMessage("1069").Message + artContainerList.Count + LanguageMgr.Instance.GetMessage("1070").Message;
  151. }
  152. }
  153. private void OnContainerSelect(ArtContainer artContainer, bool isSelect)
  154. {
  155. if (artContainer.GetGoodsInfo().art_id != "ArtId_GameObject"&& artContainer.GetGoodsInfo().art_id != "ArtId_PlayerView")
  156. {
  157. FileListDlg.ChooseFileAction?.Invoke(artContainer,isSelect);
  158. }
  159. }
  160. private void OtherUserJoinRoom(JsonData data)
  161. {
  162. List<Peer> peerList = new List<Peer>();
  163. Peer peer = new Peer();
  164. peer.PeerId = data["data"]["peerId"].ToString();
  165. peer.NickName = data["data"]["nickName"].ToString();
  166. peer.Avatar = data["data"]["avatar"].ToString();
  167. peerList.Add(peer);
  168. if (UserItemList.Instance != null)
  169. {
  170. UserItemList.Instance.AddUserItem(peer);
  171. }
  172. OnUserChange?.Invoke(peerList, true);
  173. }
  174. public void SelfLeaveRoom()
  175. {
  176. List<Peer> peerList = new List<Peer>();
  177. peerList.Add(CommonMethod.MyPeer);
  178. OnUserChange?.Invoke(peerList, false);
  179. }
  180. private void OtherUserLeaveRoom(JsonData data)
  181. {
  182. List<Peer> peerList = new List<Peer>();
  183. Peer peer = new Peer();
  184. peer.PeerId = data["data"]["peerId"].ToString();
  185. peer.NickName = data["data"]["nickName"].ToString();
  186. peerList.Add(peer);
  187. if (UserItemList.Instance != null)
  188. {
  189. UserItemList.Instance.DeleteUserItem(peer.PeerId);
  190. }
  191. OnUserChange?.Invoke(peerList, false);
  192. }
  193. public void Init()
  194. {
  195. OnRoomPageChange?.Invoke(CommonMethod.scenes.Count, CommonMethod.currentScene.Id);
  196. WSHandler.Room.BroadcastGoodReceived(CommonMethod.GoodsInfoList);
  197. for (int i = 0; i < CommonMethod.scenes.Count; i++)
  198. {
  199. SceneList.Add(CommonMethod.scenes[i]);
  200. }
  201. List<Peer> peerList = new List<Peer>();
  202. for (int i = 0; i < CommonMethod.PeerList.Count; i++)
  203. {
  204. peerList.Add(CommonMethod.PeerList[i]);
  205. }
  206. peerList.Add(CommonMethod.MyPeer);
  207. for (int i = 0; i < peerList.Count; i++)
  208. {
  209. Debug.LogWarning(peerList[i].PeerId);
  210. }
  211. OnUserChange?.Invoke(peerList, true);
  212. if (UserItemList.Instance != null)
  213. {
  214. UserItemList.Instance.Init(peerList);
  215. }
  216. if (ItemSenceList.Instance && ItemSenceSmallList.Instance)
  217. {
  218. ItemSenceList.Instance.Init(CommonMethod.scenes, CommonMethod.currentScene);
  219. ItemSenceSmallList.Instance.Init(CommonMethod.scenes, CommonMethod.currentScene);
  220. }
  221. CommonMethod.GoodsInfoList.Clear();
  222. CommonMethod.PeerList.Clear();
  223. CommonMethod.scenes.Clear();
  224. CommonMethod.IsReceive = false;
  225. }
  226. //private void roomChange(JsonData data)
  227. //{
  228. // roomId = data["data"]["roomId"].ToString();
  229. //}
  230. public void LoadHomeSence()
  231. {
  232. CommonMethod.ShowLoading();
  233. Invoke("AllowLoadSence", 0.1f);
  234. CommonMethod.LoadSence("Home");
  235. this.gameObject.SetActive(false);
  236. }
  237. public void LoadLoginSence()
  238. {
  239. CommonMethod.ShowLoading();
  240. Invoke("AllowLoadSence", 0.1f);
  241. CommonMethod.LoadSence("Login");
  242. this.gameObject.SetActive(false);
  243. }
  244. public void AllowLoadSence()
  245. {
  246. CommonMethod.HideLoading();
  247. CommonMethod.AllowLoadSence();
  248. }
  249. protected override void OnDestroy()
  250. {
  251. base.OnDestroy();
  252. ArtInfoMgr.Instance.ContainerCreate -= CreateSuccess;
  253. WSHandler.Room.OnOtherUserJoinRoom -= OtherUserJoinRoom;
  254. WSHandler.Room.OnOtherUserLeaveRoom -= OtherUserLeaveRoom;
  255. ArtInfoMgr.ContainerSelect -= OnContainerSelect;
  256. ArtInfoMgr.Instance.ContainerDel -= DeleteContainer;
  257. WSHandler.Room.onChangeScene -= ChangeScene;
  258. OnChangeRoom -= OnLocalChangeRoom;
  259. WSHandler.Room.OnClose -= Close;
  260. }
  261. public void CompareList(List<SceneConfig> aListA, List<SceneConfig> aListB, SceneConfig currentScene)
  262. {
  263. if (aListA.Count > aListB.Count)
  264. {
  265. OnChangeRoom?.Invoke("RemoveSence", ClearRepeatItem(aListA, aListB), currentScene);
  266. }
  267. else if (aListA.Count < aListB.Count)
  268. {
  269. OnChangeRoom?.Invoke("AddSence", ClearRepeatItem(aListB, aListA), currentScene);
  270. }
  271. else
  272. {
  273. OnChangeRoom?.Invoke("ChangeSence", ClearRepeatItem(aListB, aListA), currentScene);
  274. }
  275. }
  276. private List<SceneConfig> ClearRepeatItem(List<SceneConfig> bigList, List<SceneConfig> SmallList)
  277. {
  278. List<SceneConfig> intolist = bigList.Where(a => !SmallList.Select(b => b.Id).Contains(a.Id)).ToList();
  279. //Debug.Log(intolist.Count + "AAA");
  280. return intolist;
  281. }
  282. }