ShowRoom.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. using System;
  2. using System.Collections.Generic;
  3. using LitJson;
  4. using SC.XR.Unity;
  5. using UnityEngine;
  6. using static ScenesManager;
  7. public class ShowRoom : RemoteSingleton<ShowRoom>
  8. {
  9. public List<FileConfig> fileConfiglist = new List<FileConfig>();
  10. public SCButton showMainScreenBtn;
  11. public override void Awake()
  12. {
  13. base.Awake();
  14. GameObject showMainScreenBtnObj = Resources.Load("ZhankaiBtn") as GameObject;
  15. showMainScreenBtnObj = Instantiate(showMainScreenBtnObj, this.transform);
  16. if (showMainScreenBtnObj)
  17. {
  18. showMainScreenBtn = showMainScreenBtnObj.transform.GetComponent<SCButton>();
  19. }
  20. }
  21. private void Start()
  22. {
  23. WSHandler.Office.OnRefuse += Refuse;
  24. WSHandler.Office.OnTimeout += TimeoutRefuse;
  25. if (showMainScreenBtn)
  26. {
  27. showMainScreenBtn.onClick.AddListener(ShowMainScreen);
  28. }
  29. if (ResetVideoPanal.DifferencePosition == Vector3.zero)
  30. {
  31. Vector3 vthis = transform.position;
  32. ResetVideoPanal.DifferencePosition = new Vector3(vthis.x, vthis.y, vthis.z);
  33. }
  34. }
  35. private void Refuse(JsonData data)
  36. {
  37. string peerId = data["data"]["peerId"].ToString();
  38. string nickName = data["data"]["nickName"].ToString();
  39. PopUpInfo.Instance.showPublic(PopUpInfo.PopType.Tip, nickName+"拒绝了你的邀请");
  40. if (!string.IsNullOrEmpty(peerId) && InviteDlg.Instance)
  41. {
  42. for (int i = InviteDlg.Instance.InvitingUnionIdList.Count - 1; i >= 0; i--)
  43. {
  44. if (peerId == InviteDlg.Instance.InvitingUnionIdList[i].UnionId)
  45. {
  46. InviteDlg.Instance.InvitingUnionIdList.Remove(InviteDlg.Instance.InvitingUnionIdList[i]);
  47. }
  48. }
  49. }
  50. RoomOtherUser.Instance.UpdateList();
  51. }
  52. private void TimeoutRefuse(JsonData data)
  53. {
  54. string peerId = data["data"]["peerId"].ToString();
  55. string nickName = data["data"]["nickName"].ToString();
  56. PopUpInfo.Instance.showPublic(PopUpInfo.PopType.Tip, nickName + "无应答");
  57. if (!string.IsNullOrEmpty(peerId) && InviteDlg.Instance)
  58. {
  59. for (int i = InviteDlg.Instance.InvitingUnionIdList.Count - 1; i >= 0; i--)
  60. {
  61. if (peerId == InviteDlg.Instance.InvitingUnionIdList[i].UnionId)
  62. {
  63. InviteDlg.Instance.InvitingUnionIdList.Remove(InviteDlg.Instance.InvitingUnionIdList[i]);
  64. }
  65. }
  66. }
  67. RoomOtherUser.Instance.UpdateList();
  68. }
  69. public void ShowMainScreen()
  70. {
  71. if (RoomInfo.Instance)
  72. {
  73. RoomInfo.Instance.gameObject.SetActive(true);
  74. }
  75. if (RoomMain.Instance)
  76. {
  77. RoomMain.Instance.gameObject.SetActive(true);
  78. }
  79. if (RoomOtherUser.Instance)
  80. {
  81. RoomOtherUser.Instance.gameObject.SetActive(true);
  82. }
  83. if (RoomFile.Instance)
  84. {
  85. RoomFile.Instance.gameObject.SetActive(true);
  86. }
  87. showMainScreenBtn.gameObject.SetActive(false);
  88. }
  89. public void HideMainScreen()
  90. {
  91. if (RoomInfo.Instance)
  92. {
  93. RoomInfo.Instance.gameObject.SetActive(false);
  94. }
  95. if (RoomMain.Instance)
  96. {
  97. RoomMain.Instance.gameObject.SetActive(false);
  98. }
  99. if (RoomOtherUser.Instance)
  100. {
  101. RoomOtherUser.Instance.gameObject.SetActive(false);
  102. }
  103. if (RoomFile.Instance)
  104. {
  105. RoomFile.Instance.gameObject.SetActive(false);
  106. }
  107. showMainScreenBtn.gameObject.SetActive(true);
  108. }
  109. public void ExitRoom()
  110. {
  111. if (PopPeerView.Instance && PopPublic.Instance && PopPeerView.Instance.list.parent != PopPublic.Instance.transform)
  112. {
  113. PopPeerView.Instance.list.position = new Vector3(0, 0.9f, 0);
  114. PopPeerView.Instance.list.eulerAngles = new Vector3(0, 0, 0);
  115. PopPeerView.Instance.list.SetParent(PopPublic.Instance.transform);
  116. }
  117. if (PopUpInfo.Instance && PopPublic.Instance && PopUpInfo.Instance.transform.parent != PopPublic.Instance.transform)
  118. {
  119. PopUpInfo.Instance.transform.position = new Vector3(0, 0.9f, 0);
  120. PopUpInfo.Instance.transform.eulerAngles = new Vector3(0, 0, 0);
  121. PopUpInfo.Instance.transform.SetParent(PopPublic.Instance.transform);
  122. }
  123. API_GSXR_Slam.GSXR_Reset_Slam();
  124. if (InviteDlg.Instance && InviteDlg.Instance.InvitingUnionIdList != null)
  125. {
  126. if (InviteDlg.Instance.InvitingUnionIdList.Count > 0)
  127. {
  128. InviteDlg.Instance.InvitingUnionIdList.Clear();
  129. }
  130. }
  131. if (RoomFile.Instance)
  132. {
  133. RoomFile.Instance.ClearAllFileItem();
  134. }
  135. if (ArrowList.Instance)
  136. {
  137. ArrowList.Instance.DeleteAll();
  138. }
  139. if (PrintscreenList.Instance)
  140. {
  141. PrintscreenList.Instance.DeleteAll();
  142. }
  143. if (PopPeerView.Instance)
  144. {
  145. PopPeerView.Instance.DestoryAll();
  146. }
  147. ShowMainScreen();
  148. if (PopCall.Instance)
  149. {
  150. // PopCall.Instance.gameObject.SetActive(false);
  151. }
  152. transform.position = new Vector3(0, 0.9f, 0);
  153. transform.eulerAngles = new Vector3(0, 0, 0);
  154. }
  155. public void NetErrorExitRoom()
  156. {
  157. if (InviteDlg.Instance && InviteDlg.Instance.InvitingUnionIdList != null)
  158. {
  159. if (InviteDlg.Instance.InvitingUnionIdList.Count > 0)
  160. {
  161. InviteDlg.Instance.InvitingUnionIdList.Clear();
  162. }
  163. }
  164. if (RoomFile.Instance)
  165. {
  166. RoomFile.Instance.ClearAllFileItem();
  167. }
  168. if (ArrowList.Instance)
  169. {
  170. ArrowList.Instance.DeleteAll();
  171. }
  172. if (PrintscreenList.Instance)
  173. {
  174. PrintscreenList.Instance.DeleteAll();
  175. }
  176. if (PopPeerView.Instance)
  177. {
  178. PopPeerView.Instance.DestoryAll();
  179. }
  180. ShowMainScreen();
  181. if (PopCall.Instance)
  182. {
  183. // PopCall.Instance.gameObject.SetActive(false);
  184. }
  185. }
  186. private void OnDestroy()
  187. {
  188. WSHandler.Office.OnRefuse -= Refuse;
  189. WSHandler.Office.OnTimeout -= TimeoutRefuse;
  190. }
  191. public override void initShow()
  192. {
  193. base.initShow();
  194. ScenesManager.Instance.initRoom();
  195. RoomOtherUser.Instance.UpdateList();
  196. window[4].SetActive(false);
  197. Reset();
  198. }
  199. public void Reset()
  200. {
  201. RoomFile.SetIsOnFalse?.Invoke();
  202. if (ArrowList.Instance)
  203. {
  204. ArrowList.Instance.DeleteAll();
  205. }
  206. if (PrintscreenList.Instance)
  207. {
  208. PrintscreenList.Instance.DeleteAll();
  209. }
  210. Vector3 pos = OpenXRCamera.Instance.head.position + new Vector3(-1*(OpenXRCamera.Instance.head.right*0.7f).x, 0.9f, (OpenXRCamera.Instance.head.forward * 1f).z);
  211. Debug.Log(" pos " + pos);
  212. // HttpsSendLog.Instance.SendLog("Reset" ," Pos " +pos.ToString());
  213. transform.position = new Vector3(pos.x, OpenXRCamera.Instance.head.position.y, pos.z);
  214. transform.eulerAngles = new Vector3(0, -30 + OpenXRCamera.Instance.head.eulerAngles.y, 0);
  215. ShowMainScreen();
  216. PopPeerView.CloseView?.Invoke();
  217. if (RoomFile.Instance)
  218. {
  219. RoomFile.Instance.ClearAllFilePrefab();
  220. RoomFile.Instance.ResetToggleValue();
  221. }
  222. if (RoomInfo.Instance)
  223. {
  224. RoomInfo.Instance.ResetChatText();
  225. }
  226. }
  227. public void ResetPosition()
  228. {
  229. if(transform.GetChild(0).gameObject.activeSelf) ShowMainScreen();
  230. //Debug.LogError("开始设置位置");
  231. // 视频面板-SDK(0)=差,视频面板=SDK+差
  232. // 第一次获取SDKSystem与视频面板的位置,并记录,点击重置按钮设置位置
  233. //Vector3 vSDKSystem = Camera.main.transform.position;
  234. //vSDKSystem.y -= 1; // 遂光比较特殊,其他版本不需要
  235. Vector3 vSDKSystem = OpenXRCamera.Instance.head.position;
  236. if (DeviceType.type == "Rhinox")
  237. vSDKSystem.y -= 1; // 遂光比较特殊,其他版本不需要
  238. transform.position= new Vector3(vSDKSystem.x+ ResetVideoPanal.DifferencePosition.x, vSDKSystem.y+ ResetVideoPanal.DifferencePosition.y, vSDKSystem.z+ ResetVideoPanal.DifferencePosition.z);
  239. Vector3 pos = OpenXRCamera.Instance.head.position + new Vector3(-1*(OpenXRCamera.Instance.head.right * 0.7f).x, 0.9f, (OpenXRCamera.Instance.head.forward*1f).z);
  240. Debug.Log(" pos " + pos);
  241. // HttpsSendLog.Instance.SendLog("Reset" ," Pos " +pos.ToString());
  242. transform.position = new Vector3(pos.x, OpenXRCamera.Instance.head.position.y, pos.z);
  243. transform.eulerAngles = new Vector3(0, -30 + OpenXRCamera.Instance.head.eulerAngles.y, 0);
  244. }
  245. }