RoomMain.cs 13 KB

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