RoomMain.cs 13 KB

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