RoomMain.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  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. public override void Awake()
  34. {
  35. base.Awake();
  36. WSHandler.Rtc.onRtcState -= onRtcState;
  37. WSHandler.Rtc.onRtcState += onRtcState;
  38. WSHandler.Rtc.OnChangeOwner += ChangeOwner;
  39. if (manipulationHandler)
  40. {
  41. manipulationHandler.Target = ShowRoom.Instance.transform;
  42. }
  43. heidMainScreenBtn.onClick.AddListener(ShowRoom.Instance.HideMainScreen);
  44. slider.beiginDrag = OnSliderBeginDrag;
  45. slider.endDrag = OnSliderEndDrag;
  46. InviteBtn.onClick.AddListener(()=>{
  47. if (ShowRoom.Instance)
  48. {
  49. ShowRoom.Instance.window[4].SetActive(true);
  50. if (InviteDlg.Instance)
  51. {
  52. InviteDlg.Instance.ShowHistory();
  53. }
  54. }
  55. });
  56. }
  57. private void ChangeOwner(JsonData data)
  58. {
  59. string peerId = data["data"]["peerId"].ToString();
  60. string nickName = data["data"]["nickName"].ToString();
  61. string isCreator = data["data"]["isCreator"].ToString();
  62. if (peerId == UserInfo.UnionId && isCreator == "1")
  63. {
  64. RoomMainInfo.isCreator = "0";
  65. RoomMainInfo.RoomOwner = "用户" + nickName + "的房间";
  66. if (FileList.Instance && RoomFile.Instance)
  67. {
  68. if (FileList.Instance.transform.childCount > 0)
  69. {
  70. RoomFile.Instance.ShowClearBtn();
  71. }
  72. }
  73. }
  74. TitleRoomName.text = "用户" + nickName + "的房间";
  75. TitleRoomPeopleCount.text = "房间人数:" + RoomMainInfo.roomPeopleNum + "/" + 10;
  76. RoomOtherUser.Instance.UpdateList();
  77. }
  78. /// <summary>
  79. /// 进度条开始拖动
  80. /// </summary>
  81. public void OnSliderBeginDrag()
  82. {
  83. }
  84. /// <summary>
  85. ///结束
  86. /// </summary>
  87. public void OnSliderEndDrag()
  88. {
  89. float num = float.Parse(slider.value.ToString("f2"));
  90. //Debug.Log(num + "AAA");
  91. RemoteRtc.Instance.setVolume(num);
  92. }
  93. public void OnDestroy()
  94. {
  95. WSHandler.Rtc.OnChangeOwner -= ChangeOwner;
  96. WSHandler.Rtc.onRtcState -= onRtcState;
  97. }
  98. public override void initShow()
  99. {
  100. base.initShow();
  101. if (PopPeerView.Instance)
  102. {
  103. PopPeerView.Instance.list.SetParent(ShowRoom.Instance.transform);
  104. }
  105. if (PopUpInfo.Instance)
  106. {
  107. PopUpInfo.Instance.transform.SetParent(ShowRoom.Instance.transform);
  108. PopUpInfo.Instance.HideNetErrorPanel();
  109. }
  110. if (ShowRoom.Instance)
  111. {
  112. ShowRoom.Instance.transform.position = new Vector3(-0.2f, 0, 0.3f); // 要设置ShowRoom LocalPosition为0,因为Canvas PosZ=0.3,所以为0.3f
  113. ShowRoom.Instance.transform.eulerAngles = new Vector3(0, -30, 0);
  114. }
  115. if (PopCall.Instance)
  116. {
  117. PopCall.Instance.gameObject.SetActive(true);
  118. }
  119. setBigView(RemoteRtc.Instance.NoUser, NOUSER);
  120. if (!string.IsNullOrEmpty(RoomMainInfo.RoomOwner))
  121. {
  122. TitleRoomName.text = RoomMainInfo.RoomOwner;
  123. }
  124. TitleRoomPeopleCount.text ="房间人数:"+ RoomMainInfo.roomPeopleNum + "/"+ RoomMainInfo.roomMaxPeopleNum;
  125. TitleRoomNum.text ="房间号:"+ RoomMainInfo.roomNum;
  126. AgoraVideoAudioManager.Instance.SetChinnelName(RoomMainInfo.roomNum);
  127. AgoraVideoAudioManager.Instance.JoinChannel();
  128. isSendAudio = CustomInfo.isSendAudio;
  129. isSendVideo = CustomInfo.isSendVideo;
  130. isCloseView = CustomInfo.isCloseView;
  131. sendAudio(isSendAudio);
  132. sendVideo(isSendAudio);
  133. //if(isCloseView)
  134. //{
  135. RemoteRtc.Instance.changeViewOpen();
  136. // isCloseView = false;
  137. //}
  138. //else
  139. //{
  140. // RemoteRtc.Instance.changeViewClose();
  141. isCloseView = true;
  142. // }
  143. change();
  144. }
  145. bool isStartBigView = true;
  146. public void setBigView(Texture tex,string id)
  147. {
  148. if (id!= NOUSER)
  149. {
  150. CustomPeer cPeer = (CustomPeer)RemoteRtc.Instance.customPeerList.getPeer(id);
  151. if (cPeer.isCloseVideo||!cPeer.isVideo)
  152. {
  153. tex = RemoteRtc.Instance.NoView;
  154. }
  155. RoomOtherUser.ShowAction?.Invoke(id);
  156. }
  157. userId = id;
  158. if(isStartBigView)
  159. {
  160. isStartBigView = false;
  161. bigView.material.mainTexture = tex;
  162. }
  163. }
  164. private string dcetype;
  165. private void onRtcState(string str)
  166. {
  167. if (!string.IsNullOrEmpty(RoomMainInfo.RoomOwner))
  168. {
  169. TitleRoomName.text = RoomMainInfo.RoomOwner;
  170. }
  171. TitleRoomPeopleCount.text = "房间人数:" + RoomMainInfo.roomPeopleNum + "/" + RoomMainInfo.roomMaxPeopleNum;
  172. TitleRoomNum.text = "房间号:" + RoomMainInfo.roomNum;
  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. //private void OnEnable()
  189. //{
  190. // AgoraVideoAudioManager.Instance.JoinChannel();
  191. //}
  192. void change()
  193. {
  194. if (isSendVideo)
  195. {
  196. videoOpenBtn.SetActive(false);
  197. videoCloseBtn.SetActive(true);
  198. }
  199. else
  200. {
  201. videoOpenBtn.SetActive(true);
  202. videoCloseBtn.SetActive(false);
  203. }
  204. if (isSendAudio)
  205. {
  206. audioOpenBtn.SetActive(false);
  207. audioCloseBtn.SetActive(true);
  208. }
  209. else
  210. {
  211. audioOpenBtn.SetActive(true);
  212. audioCloseBtn.SetActive(false);
  213. }
  214. if (isCloseView)
  215. {
  216. changeViewOpenBtn.SetActive(false);
  217. // changeViewCloseBtn.SetActive(true);
  218. }
  219. else
  220. {
  221. // changeViewOpenBtn.SetActive(true);
  222. changeViewCloseBtn.SetActive(false);
  223. }
  224. }
  225. public void LeaveRoom()
  226. {
  227. if (PopPeerView.Instance)
  228. {
  229. PopPeerView.Instance.list.SetParent(PopPublic.Instance.transform);
  230. PopPeerView.Instance.list.localPosition = new Vector3(0, 0, 0);
  231. PopPeerView.Instance.list.localEulerAngles = new Vector3(0, 0, 0);
  232. }
  233. if (PopUpInfo.Instance)
  234. {
  235. PopUpInfo.Instance.transform.SetParent(PopPublic.Instance.transform);
  236. PopUpInfo.Instance.transform.localPosition = new Vector3(0, 0, 0);
  237. PopUpInfo.Instance.transform.localEulerAngles = new Vector3(0, 0, 0);
  238. }
  239. //sendAudio(false);
  240. //sendVideo(false);
  241. WSHandler.roomRtcCloes();
  242. WSHandler.Office.ChangeUserType(UserInfo.BusyType);
  243. ScenesManager.Instance.showWindow(SceneType.ShowChoose);
  244. if (InviteDlg.Instance)
  245. {
  246. InviteDlg.Instance.InvitingUnionIdList.Clear();
  247. }
  248. if (ArrowList.Instance)
  249. {
  250. ArrowList.Instance.DeleteAll();
  251. }
  252. if (RoomFile.Instance)
  253. {
  254. RoomFile.Instance.ClearAllFileItem();
  255. }
  256. if (PrintscreenList.Instance)
  257. {
  258. PrintscreenList.Instance.DeleteAll();
  259. }
  260. if (PopPeerView.Instance)
  261. {
  262. PopPeerView.Instance.DestoryAll();
  263. }
  264. if (PopCall.Instance)
  265. {
  266. PopCall.Instance.gameObject.SetActive(false);
  267. }
  268. if (ShowRoom.Instance)
  269. {
  270. ShowRoom.Instance.ShowMainScreen();
  271. ShowRoom.Instance.transform.localPosition = new Vector3(0, 0, 0);
  272. ShowRoom.Instance.transform.localEulerAngles = new Vector3(0, 0, 0);
  273. }
  274. API_GSXR_Slam.GSXR_Reset_Slam();
  275. AgoraVideoAudioManager.Instance.LeaveChannel();
  276. RemoteRtc.Instance.FiltrationCamera(true);
  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. // RemoteRtc.Instance.FiltrationCamera(true);
  391. Filtration(true);
  392. }
  393. public void closeEye()
  394. {
  395. isCloseView = true;
  396. // changeViewOpenBtn.SetActive(true);
  397. changeViewCloseBtn.SetActive(false);
  398. //RemoteRtc.Instance.changeViewClose();
  399. // RemoteRtc.Instance.FiltrationCamera(false);
  400. Filtration(false);
  401. }
  402. private void Filtration(bool state)
  403. {
  404. ArrowList.Instance.gameObject.SetActive(state);
  405. PngJpgList.Instance.gameObject.SetActive(state);
  406. ModelList.Instance.gameObject.SetActive(state);
  407. PdfList.Instance.gameObject.SetActive(state);
  408. Mp4List.Instance.gameObject.SetActive(state);
  409. }
  410. public void ClearAllArrow()
  411. {
  412. if (ArrowList.Instance)
  413. {
  414. ArrowList.Instance.DeleteAll();
  415. }
  416. }
  417. }