RoomMain.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  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. if (isSendAudio)
  119. {
  120. TimerMgr.Instance.CreateTimer(() => {
  121. RemoteRtc.Instance.sendMic(true);
  122. }, 1f);
  123. }
  124. if (isSendVideo)
  125. {
  126. TimerMgr.Instance.CreateTimer(() => {
  127. RemoteRtc.Instance.startCamera();
  128. RemoteRtc.Instance.sendVideo(true);
  129. }, 1f);
  130. }
  131. else
  132. {
  133. RemoteRtc.Instance.startCamera();
  134. // RemoteRtc.Instance.meshRender.gameObject.SetActive(false);
  135. }
  136. //if(isCloseView)
  137. //{
  138. RemoteRtc.Instance.changeViewOpen();
  139. // isCloseView = false;
  140. //}
  141. //else
  142. //{
  143. // RemoteRtc.Instance.changeViewClose();
  144. isCloseView = true;
  145. // }
  146. change();
  147. }
  148. bool isStartBigView = true;
  149. public void setBigView(Texture tex,string id)
  150. {
  151. if (id!= NOUSER)
  152. {
  153. CustomPeer cPeer = (CustomPeer)RemoteRtc.Instance.customPeerList.getPeer(id);
  154. if (cPeer.isCloseVideo||!cPeer.isVideo)
  155. {
  156. tex = RemoteRtc.Instance.NoView;
  157. }
  158. RoomOtherUser.ShowAction?.Invoke(id);
  159. }
  160. userId = id;
  161. if(isStartBigView)
  162. {
  163. isStartBigView = false;
  164. bigView.material.mainTexture = tex;
  165. }
  166. }
  167. private string dcetype;
  168. private void onRtcState(string str)
  169. {
  170. if (!string.IsNullOrEmpty(RoomMainInfo.RoomOwner))
  171. {
  172. TitleRoomName.text = RoomMainInfo.RoomOwner;
  173. }
  174. TitleRoomPeopleCount.text = "房间人数:" + RoomMainInfo.roomPeopleNum + "/" + RoomMainInfo.roomMaxPeopleNum;
  175. TitleRoomNum.text = "房间号:" + RoomMainInfo.roomNum;
  176. // change();
  177. switch(str)
  178. {
  179. case "closeProducer":
  180. if (dcetype == "video")
  181. {
  182. RemoteRtc.Instance.me.cIdV = "";
  183. }
  184. else
  185. {
  186. RemoteRtc.Instance.me.cIdA = "";
  187. }
  188. break;
  189. }
  190. }
  191. //private void OnEnable()
  192. //{
  193. // AgoraVideoAudioManager.Instance.JoinChannel();
  194. //}
  195. void change()
  196. {
  197. if (isSendVideo)
  198. {
  199. videoOpenBtn.SetActive(false);
  200. videoCloseBtn.SetActive(true);
  201. }
  202. else
  203. {
  204. videoOpenBtn.SetActive(true);
  205. videoCloseBtn.SetActive(false);
  206. }
  207. if (isSendAudio)
  208. {
  209. audioOpenBtn.SetActive(false);
  210. audioCloseBtn.SetActive(true);
  211. }
  212. else
  213. {
  214. audioOpenBtn.SetActive(true);
  215. audioCloseBtn.SetActive(false);
  216. }
  217. if (isCloseView)
  218. {
  219. changeViewOpenBtn.SetActive(false);
  220. changeViewCloseBtn.SetActive(true);
  221. }
  222. else
  223. {
  224. changeViewOpenBtn.SetActive(true);
  225. changeViewCloseBtn.SetActive(false);
  226. }
  227. }
  228. public void LeaveRoom()
  229. {
  230. if (PopPeerView.Instance)
  231. {
  232. PopPeerView.Instance.list.position = new Vector3(0, 0, 0);
  233. PopPeerView.Instance.list.eulerAngles = new Vector3(0, 0, 0);
  234. PopPeerView.Instance.list.SetParent(PopPublic.Instance.transform);
  235. }
  236. if (PopUpInfo.Instance)
  237. {
  238. PopUpInfo.Instance.transform.position = new Vector3(0, 0, 0);
  239. PopUpInfo.Instance.transform.eulerAngles = new Vector3(0, 0, 0);
  240. PopUpInfo.Instance.transform.SetParent(PopPublic.Instance.transform);
  241. }
  242. //sendAudio(false);
  243. //sendVideo(false);
  244. WSHandler.roomRtcCloes();
  245. WSHandler.Office.ChangeUserType(UserInfo.BusyType);
  246. ScenesManager.Instance.showWindow(SceneType.ShowOffice);
  247. if (InviteDlg.Instance)
  248. {
  249. InviteDlg.Instance.InvitingUnionIdList.Clear();
  250. }
  251. if (ArrowList.Instance)
  252. {
  253. ArrowList.Instance.DeleteAll();
  254. }
  255. if (RoomFile.Instance)
  256. {
  257. RoomFile.Instance.ClearAllFileItem();
  258. }
  259. if (PrintscreenList.Instance)
  260. {
  261. PrintscreenList.Instance.DeleteAll();
  262. }
  263. if (PopPeerView.Instance)
  264. {
  265. PopPeerView.Instance.DestoryAll();
  266. }
  267. if (PopCall.Instance)
  268. {
  269. PopCall.Instance.gameObject.SetActive(false);
  270. }
  271. if (ShowRoom.Instance)
  272. {
  273. ShowRoom.Instance.ShowMainScreen();
  274. ShowRoom.Instance.transform.position = new Vector3(0, 0, 0);
  275. ShowRoom.Instance.transform.eulerAngles = new Vector3(0, 0, 0);
  276. }
  277. if (GameStart.Instance && GameStart.Instance.systemMenu)
  278. {
  279. GameStart.Instance.systemMenu.ResetPattern();
  280. }
  281. API_GSXR_Slam.GSXR_Reset_Slam();
  282. AgoraVideoAudioManager.Instance.LeaveChannel();
  283. RemoteRtc.Instance.FiltrationCamera(true);
  284. }
  285. public void CloseRoom()
  286. {
  287. PopUpInfo.Instance.showPublic(PopUpInfo.PopType.Pop, RtcStrConfig.roomPeopleLeave, "确定", () => { LeaveRoom(); }, "取消"
  288. );
  289. //if (RoomMainInfo.isCreator == "0")
  290. //{
  291. // PopUpInfo.Instance.showPublic(PopUpInfo.PopType.Pop, RtcStrConfig.roomCreatorLeave, "确定", () => { LeaveRoom(); }, "取消"
  292. // );
  293. //}
  294. //else
  295. //{
  296. // PopUpInfo.Instance.showPublic(PopUpInfo.PopType.Pop, RtcStrConfig.roomPeopleLeave, "确定", () => { LeaveRoom(); }, "取消"
  297. // );
  298. //}
  299. }
  300. public void ShowRoomissolvePop()
  301. {
  302. PopUpInfo.Instance.showPublic(PopUpInfo.PopType.PopOk, RtcStrConfig.roomdissolve, "知道了");
  303. }
  304. public void sendVideo(bool isSend)
  305. {
  306. //if (RemoteRtc.Instance.me.cIdV == "")
  307. //{
  308. // dcetype = "video";
  309. // Debug.Log("开启1111");
  310. // RemoteRtc.Instance.startCamera();
  311. // // videoBG.gameObject.SetActive(true);
  312. // // videoBG.material.mainTexture = RemoteRtc.Instance.rt;
  313. // RemoteRtc.Instance.sendVideo(true);
  314. // RemoteRtc.Instance.me.cIdV = "";
  315. // openVideoEffect();
  316. //}else if (RemoteRtc.Instance.me.cIdV != "")
  317. //{
  318. // dcetype = "video";
  319. // Debug.Log("关闭11111");
  320. // WSHandler.Rtc.closeProducer(RemoteRtc.Instance.me.cIdV);
  321. // RemoteRtc.Instance.stopCamera();
  322. // RemoteRtc.Instance.sendVideo(false);
  323. // closeVideoEffect();
  324. //}
  325. if(isSend)
  326. {
  327. dcetype = "video";
  328. Debug.Log("开启1111");
  329. openVideoEffect();
  330. }
  331. else
  332. {
  333. dcetype = "video";
  334. closeVideoEffect();
  335. }
  336. AgoraVideoAudioManager.Instance.EnableLocalVideo(isSend);
  337. }
  338. public void sendAudio(bool isSend)
  339. {
  340. //if (RemoteRtc.Instance.me.cIdA != "")
  341. //{
  342. // dcetype = "audio";
  343. // WSHandler.Rtc.closeProducer(RemoteRtc.Instance.me.cIdA);
  344. // RemoteRtc.Instance.sendMic(false);
  345. // RemoteRtc.Instance.me.cIdA = "";
  346. // closeAudioEffect();
  347. //}
  348. //else
  349. //{
  350. // dcetype = "audio";
  351. // RemoteRtc.Instance.sendMic(true);
  352. // // volume = RemoteRtc.Instance.me.volumn;
  353. // openAudioEffect();
  354. //}
  355. if (!isSend)
  356. {
  357. dcetype = "audio";
  358. closeAudioEffect();
  359. }
  360. else
  361. {
  362. dcetype = "audio";
  363. openAudioEffect();
  364. }
  365. AgoraVideoAudioManager.Instance.EnableLoacalAudio(isSend);
  366. }
  367. private void closeVideoEffect()
  368. {
  369. isSendVideo = false;
  370. videoOpenBtn.SetActive(true);
  371. videoCloseBtn.SetActive(false);
  372. }
  373. private void openVideoEffect()
  374. {
  375. isSendVideo = true;
  376. videoOpenBtn.SetActive(false);
  377. videoCloseBtn.SetActive(true);
  378. }
  379. private void closeAudioEffect()
  380. {
  381. isSendAudio = false;
  382. audioOpenBtn.SetActive(true);
  383. audioCloseBtn.SetActive(false);
  384. }
  385. private void openAudioEffect()
  386. {
  387. isSendAudio = true;
  388. audioOpenBtn.SetActive(false);
  389. audioCloseBtn.SetActive(true);
  390. }
  391. public void openEye()
  392. {
  393. isCloseView = false;
  394. changeViewOpenBtn.SetActive(false);
  395. changeViewCloseBtn.SetActive(true);
  396. //RemoteRtc.Instance.changeViewOpen();
  397. // RemoteRtc.Instance.FiltrationCamera(true);
  398. Filtration(true);
  399. }
  400. public void closeEye()
  401. {
  402. isCloseView = true;
  403. changeViewOpenBtn.SetActive(true);
  404. changeViewCloseBtn.SetActive(false);
  405. //RemoteRtc.Instance.changeViewClose();
  406. // RemoteRtc.Instance.FiltrationCamera(false);
  407. Filtration(false);
  408. }
  409. private void Filtration(bool state)
  410. {
  411. ArrowList.Instance.gameObject.SetActive(state);
  412. PngJpgList.Instance.gameObject.SetActive(state);
  413. ModelList.Instance.gameObject.SetActive(state);
  414. PdfList.Instance.gameObject.SetActive(state);
  415. Mp4List.Instance.gameObject.SetActive(state);
  416. }
  417. public void ClearAllArrow()
  418. {
  419. if (ArrowList.Instance)
  420. {
  421. ArrowList.Instance.DeleteAll();
  422. }
  423. }
  424. }