RoomMain.cs 13 KB

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