RoomMain.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. using System;
  2. using LitJson;
  3. using SC.XR.Unity;
  4. using SC.XR.Unity.Module_InputSystem;
  5. using UnityEngine;
  6. using UnityEngine.UI;
  7. using XRTool.Util;
  8. using static ScenesManager;
  9. public class RoomMain : RemoteSingleton<RoomMain>
  10. {
  11. public static string NOUSER="nouser";
  12. public bool isSendAudio = true;
  13. public bool isSendVideo = true;
  14. public bool isCloseView = true;
  15. public MeshRenderer bigView;
  16. public GameObject audioOpenBtn;
  17. public GameObject audioCloseBtn;
  18. public GameObject videoOpenBtn;
  19. public GameObject videoCloseBtn;
  20. public GameObject changeViewOpenBtn;
  21. public GameObject changeViewCloseBtn;
  22. public string userId;
  23. public Text TitleRoomName;
  24. public Text TitleRoomNum;
  25. public Text TitleRoomPeopleCount;
  26. public SCButton heidMainScreenBtn;
  27. public ManipulationHandler manipulationHandler;
  28. public MySlider slider;
  29. public RawImage agoraRawImage;
  30. public override void Awake()
  31. {
  32. base.Awake();
  33. WSHandler.Rtc.onRtcState -= onRtcState;
  34. WSHandler.Rtc.onRtcState += onRtcState;
  35. WSHandler.Rtc.OnChangeOwner += ChangeOwner;
  36. if (manipulationHandler)
  37. {
  38. manipulationHandler.Target = ShowRoom.Instance.transform;
  39. }
  40. heidMainScreenBtn.onClick.AddListener(ShowRoom.Instance.HideMainScreen);
  41. slider.beiginDrag = OnSliderBeginDrag;
  42. slider.endDrag = OnSliderEndDrag;
  43. }
  44. private void ChangeOwner(JsonData data)
  45. {
  46. string peerId = data["data"]["peerId"].ToString();
  47. string nickName = data["data"]["nickName"].ToString();
  48. string isCreator = data["data"]["isCreator"].ToString();
  49. if (peerId == UserInfo.UnionId && isCreator == "1")
  50. {
  51. RoomMainInfo.isCreator = "0";
  52. RoomMainInfo.RoomOwner = "用户" + nickName + "的房间";
  53. if (FileList.Instance && RoomFile.Instance)
  54. {
  55. if (FileList.Instance.transform.childCount > 0)
  56. {
  57. RoomFile.Instance.ShowClearBtn();
  58. }
  59. }
  60. }
  61. TitleRoomName.text = "用户" + nickName + "的房间";
  62. TitleRoomPeopleCount.text = "房间人数:" + RoomMainInfo.roomPeopleNum + "/" + 10;
  63. RoomOtherUser.Instance.UpdateList();
  64. }
  65. /// <summary>
  66. /// 进度条开始拖动
  67. /// </summary>
  68. public void OnSliderBeginDrag()
  69. {
  70. }
  71. /// <summary>
  72. ///结束
  73. /// </summary>
  74. public void OnSliderEndDrag()
  75. {
  76. float num = float.Parse(slider.value.ToString("f2"));
  77. //Debug.Log(num + "AAA");
  78. RemoteRtc.Instance.setVolume(num);
  79. }
  80. public void OnDestroy()
  81. {
  82. WSHandler.Rtc.OnChangeOwner -= ChangeOwner;
  83. WSHandler.Rtc.onRtcState -= onRtcState;
  84. }
  85. public override void initShow()
  86. {
  87. base.initShow();
  88. if (PopPeerView.Instance)
  89. {
  90. PopPeerView.Instance.list.SetParent(ShowRoom.Instance.transform);
  91. }
  92. if (PopUpInfo.Instance)
  93. {
  94. PopUpInfo.Instance.transform.SetParent(ShowRoom.Instance.transform);
  95. PopUpInfo.Instance.HideNetErrorPanel();
  96. }
  97. if (ShowRoom.Instance)
  98. {
  99. ShowRoom.Instance.transform.position = new Vector3(-0.2f, 0, 0.3f); // 要设置ShowRoom LocalPosition为0,因为Canvas PosZ=0.3,所以为0.3f
  100. ShowRoom.Instance.transform.eulerAngles = new Vector3(0, -30, 0);
  101. }
  102. if (PopCall.Instance)
  103. {
  104. PopCall.Instance.gameObject.SetActive(true);
  105. }
  106. setBigView(RemoteRtc.Instance.NoUser, NOUSER);
  107. if (!string.IsNullOrEmpty(RoomMainInfo.RoomOwner))
  108. {
  109. TitleRoomName.text = RoomMainInfo.RoomOwner;
  110. }
  111. TitleRoomPeopleCount.text ="房间人数:"+ RoomMainInfo.roomPeopleNum + "/"+ RoomMainInfo.roomMaxPeopleNum;
  112. TitleRoomNum.text ="房间号:"+ RoomMainInfo.roomNum;
  113. AgoraVideoAudioManager.Instance.SetChinnelName(RoomMainInfo.roomNum);
  114. AgoraVideoAudioManager.Instance.JoinChannel();
  115. isSendAudio = CustomInfo.isSendAudio;
  116. isSendVideo = CustomInfo.isSendVideo;
  117. isCloseView = CustomInfo.isCloseView;
  118. sendAudio(isSendAudio);
  119. sendVideo(isSendAudio);
  120. //if(isCloseView)
  121. //{
  122. RemoteRtc.Instance.changeViewOpen();
  123. // isCloseView = false;
  124. //}
  125. //else
  126. //{
  127. // RemoteRtc.Instance.changeViewClose();
  128. isCloseView = true;
  129. // }
  130. change();
  131. }
  132. bool isStartBigView = true;
  133. public void setBigView(Texture tex,string id)
  134. {
  135. if (id!= NOUSER)
  136. {
  137. CustomPeer cPeer = (CustomPeer)RemoteRtc.Instance.customPeerList.getPeer(id);
  138. if (cPeer.isCloseVideo||!cPeer.isVideo)
  139. {
  140. tex = RemoteRtc.Instance.NoView;
  141. }
  142. RoomOtherUser.ShowAction?.Invoke(id);
  143. }
  144. userId = id;
  145. if(isStartBigView)
  146. {
  147. isStartBigView = false;
  148. bigView.material.mainTexture = tex;
  149. }
  150. }
  151. private string dcetype;
  152. private void onRtcState(string str)
  153. {
  154. if (!string.IsNullOrEmpty(RoomMainInfo.RoomOwner))
  155. {
  156. TitleRoomName.text = RoomMainInfo.RoomOwner;
  157. }
  158. TitleRoomPeopleCount.text = "房间人数:" + RoomMainInfo.roomPeopleNum + "/" + RoomMainInfo.roomMaxPeopleNum;
  159. TitleRoomNum.text = "房间号:" + RoomMainInfo.roomNum;
  160. // change();
  161. switch(str)
  162. {
  163. case "closeProducer":
  164. if (dcetype == "video")
  165. {
  166. RemoteRtc.Instance.me.cIdV = "";
  167. }
  168. else
  169. {
  170. RemoteRtc.Instance.me.cIdA = "";
  171. }
  172. break;
  173. }
  174. }
  175. //private void OnEnable()
  176. //{
  177. // AgoraVideoAudioManager.Instance.JoinChannel();
  178. //}
  179. void change()
  180. {
  181. if (isSendVideo)
  182. {
  183. videoOpenBtn.SetActive(false);
  184. videoCloseBtn.SetActive(true);
  185. }
  186. else
  187. {
  188. videoOpenBtn.SetActive(true);
  189. videoCloseBtn.SetActive(false);
  190. }
  191. if (isSendAudio)
  192. {
  193. audioOpenBtn.SetActive(false);
  194. audioCloseBtn.SetActive(true);
  195. }
  196. else
  197. {
  198. audioOpenBtn.SetActive(true);
  199. audioCloseBtn.SetActive(false);
  200. }
  201. if (isCloseView)
  202. {
  203. changeViewOpenBtn.SetActive(false);
  204. changeViewCloseBtn.SetActive(true);
  205. }
  206. else
  207. {
  208. changeViewOpenBtn.SetActive(true);
  209. changeViewCloseBtn.SetActive(false);
  210. }
  211. }
  212. public void LeaveRoom()
  213. {
  214. if (PopPeerView.Instance)
  215. {
  216. PopPeerView.Instance.list.SetParent(PopPublic.Instance.transform);
  217. PopPeerView.Instance.list.localPosition = new Vector3(0, 0, 0);
  218. PopPeerView.Instance.list.localEulerAngles = new Vector3(0, 0, 0);
  219. }
  220. if (PopUpInfo.Instance)
  221. {
  222. PopUpInfo.Instance.transform.SetParent(PopPublic.Instance.transform);
  223. PopUpInfo.Instance.transform.localPosition = new Vector3(0, 0, 0);
  224. PopUpInfo.Instance.transform.localEulerAngles = new Vector3(0, 0, 0);
  225. }
  226. //sendAudio(false);
  227. //sendVideo(false);
  228. WSHandler.roomRtcCloes();
  229. WSHandler.Office.ChangeUserType(UserInfo.BusyType);
  230. ScenesManager.Instance.showWindow(SceneType.ShowOffice);
  231. if (InviteDlg.Instance)
  232. {
  233. InviteDlg.Instance.InvitingUnionIdList.Clear();
  234. }
  235. if (ArrowList.Instance)
  236. {
  237. ArrowList.Instance.DeleteAll();
  238. }
  239. if (RoomFile.Instance)
  240. {
  241. RoomFile.Instance.ClearAllFileItem();
  242. }
  243. if (PrintscreenList.Instance)
  244. {
  245. PrintscreenList.Instance.DeleteAll();
  246. }
  247. if (PopPeerView.Instance)
  248. {
  249. PopPeerView.Instance.DestoryAll();
  250. }
  251. if (PopCall.Instance)
  252. {
  253. PopCall.Instance.gameObject.SetActive(false);
  254. }
  255. if (ShowRoom.Instance)
  256. {
  257. ShowRoom.Instance.ShowMainScreen();
  258. ShowRoom.Instance.transform.localPosition = new Vector3(0, 0, 0);
  259. ShowRoom.Instance.transform.localEulerAngles = new Vector3(0, 0, 0);
  260. }
  261. if (GameStart.Instance && GameStart.Instance.systemMenu)
  262. {
  263. GameStart.Instance.systemMenu.ResetPattern();
  264. }
  265. API_GSXR_Slam.GSXR_Reset_Slam();
  266. AgoraVideoAudioManager.Instance.LeaveChannel();
  267. RemoteRtc.Instance.FiltrationCamera(true);
  268. }
  269. public void CloseRoom()
  270. {
  271. Debug.Log("退出房间");
  272. PopUpInfo.Instance.showPublic(PopUpInfo.PopType.Pop, RtcStrConfig.roomPeopleLeave, "确定", () => { LeaveRoom(); }, "取消"
  273. );
  274. //if (RoomMainInfo.isCreator == "0")
  275. //{
  276. // PopUpInfo.Instance.showPublic(PopUpInfo.PopType.Pop, RtcStrConfig.roomCreatorLeave, "确定", () => { LeaveRoom(); }, "取消"
  277. // );
  278. //}
  279. //else
  280. //{
  281. // PopUpInfo.Instance.showPublic(PopUpInfo.PopType.Pop, RtcStrConfig.roomPeopleLeave, "确定", () => { LeaveRoom(); }, "取消"
  282. // );
  283. //}
  284. }
  285. public void ShowRoomissolvePop()
  286. {
  287. PopUpInfo.Instance.showPublic(PopUpInfo.PopType.PopOk, RtcStrConfig.roomdissolve, "知道了");
  288. }
  289. public void sendVideo(bool isSend)
  290. {
  291. //if (RemoteRtc.Instance.me.cIdV == "")
  292. //{
  293. // dcetype = "video";
  294. // Debug.Log("开启1111");
  295. // RemoteRtc.Instance.startCamera();
  296. // // videoBG.gameObject.SetActive(true);
  297. // // videoBG.material.mainTexture = RemoteRtc.Instance.rt;
  298. // RemoteRtc.Instance.sendVideo(true);
  299. // RemoteRtc.Instance.me.cIdV = "";
  300. // openVideoEffect();
  301. //}else if (RemoteRtc.Instance.me.cIdV != "")
  302. //{
  303. // dcetype = "video";
  304. // Debug.Log("关闭11111");
  305. // WSHandler.Rtc.closeProducer(RemoteRtc.Instance.me.cIdV);
  306. // RemoteRtc.Instance.stopCamera();
  307. // RemoteRtc.Instance.sendVideo(false);
  308. // closeVideoEffect();
  309. //}
  310. if(isSend)
  311. {
  312. dcetype = "video";
  313. Debug.Log("开启1111");
  314. openVideoEffect();
  315. }
  316. else
  317. {
  318. dcetype = "video";
  319. closeVideoEffect();
  320. }
  321. AgoraVideoAudioManager.Instance.EnableLocalVideo(isSend);
  322. }
  323. public void sendAudio(bool isSend)
  324. {
  325. //if (RemoteRtc.Instance.me.cIdA != "")
  326. //{
  327. // dcetype = "audio";
  328. // WSHandler.Rtc.closeProducer(RemoteRtc.Instance.me.cIdA);
  329. // RemoteRtc.Instance.sendMic(false);
  330. // RemoteRtc.Instance.me.cIdA = "";
  331. // closeAudioEffect();
  332. //}
  333. //else
  334. //{
  335. // dcetype = "audio";
  336. // RemoteRtc.Instance.sendMic(true);
  337. // // volume = RemoteRtc.Instance.me.volumn;
  338. // openAudioEffect();
  339. //}
  340. if (!isSend)
  341. {
  342. dcetype = "audio";
  343. closeAudioEffect();
  344. }
  345. else
  346. {
  347. dcetype = "audio";
  348. openAudioEffect();
  349. }
  350. AgoraVideoAudioManager.Instance.EnableLoacalAudio(isSend);
  351. }
  352. private void closeVideoEffect()
  353. {
  354. isSendVideo = false;
  355. videoOpenBtn.SetActive(true);
  356. videoCloseBtn.SetActive(false);
  357. }
  358. private void openVideoEffect()
  359. {
  360. isSendVideo = true;
  361. videoOpenBtn.SetActive(false);
  362. videoCloseBtn.SetActive(true);
  363. }
  364. private void closeAudioEffect()
  365. {
  366. isSendAudio = false;
  367. audioOpenBtn.SetActive(true);
  368. audioCloseBtn.SetActive(false);
  369. }
  370. private void openAudioEffect()
  371. {
  372. isSendAudio = true;
  373. audioOpenBtn.SetActive(false);
  374. audioCloseBtn.SetActive(true);
  375. }
  376. public void openEye()
  377. {
  378. isCloseView = false;
  379. changeViewOpenBtn.SetActive(false);
  380. changeViewCloseBtn.SetActive(true);
  381. //RemoteRtc.Instance.changeViewOpen();
  382. // RemoteRtc.Instance.FiltrationCamera(true);
  383. Filtration(true);
  384. }
  385. public void closeEye()
  386. {
  387. isCloseView = true;
  388. changeViewOpenBtn.SetActive(true);
  389. changeViewCloseBtn.SetActive(false);
  390. //RemoteRtc.Instance.changeViewClose();
  391. // RemoteRtc.Instance.FiltrationCamera(false);
  392. Filtration(false);
  393. }
  394. private void Filtration(bool state)
  395. {
  396. ArrowList.Instance.gameObject.SetActive(state);
  397. PngJpgList.Instance.gameObject.SetActive(state);
  398. ModelList.Instance.gameObject.SetActive(state);
  399. PdfList.Instance.gameObject.SetActive(state);
  400. Mp4List.Instance.gameObject.SetActive(state);
  401. }
  402. public void ClearAllArrow()
  403. {
  404. if (ArrowList.Instance)
  405. {
  406. ArrowList.Instance.DeleteAll();
  407. }
  408. }
  409. }