RoomMain.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  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.9f, 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. isSendAudio = CustomInfo.isSendAudio;
  115. isSendVideo = CustomInfo.isSendVideo;
  116. isCloseView = CustomInfo.isCloseView;
  117. if (isSendAudio)
  118. {
  119. TimerMgr.Instance.CreateTimer(() => {
  120. RemoteRtc.Instance.sendMic(true);
  121. }, 1f);
  122. }
  123. if (isSendVideo)
  124. {
  125. TimerMgr.Instance.CreateTimer(() => {
  126. RemoteRtc.Instance.startCamera();
  127. RemoteRtc.Instance.sendVideo(true);
  128. }, 1f);
  129. }
  130. else
  131. {
  132. RemoteRtc.Instance.meshRender.gameObject.SetActive(false);
  133. }
  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. 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. bigView.material.mainTexture = tex;
  159. }
  160. private string dcetype;
  161. private void onRtcState(string str)
  162. {
  163. if (!string.IsNullOrEmpty(RoomMainInfo.RoomOwner))
  164. {
  165. TitleRoomName.text = RoomMainInfo.RoomOwner;
  166. }
  167. TitleRoomPeopleCount.text = "房间人数:" + RoomMainInfo.roomPeopleNum + "/" + RoomMainInfo.roomMaxPeopleNum;
  168. TitleRoomNum.text = "房间号:" + RoomMainInfo.roomNum;
  169. // change();
  170. switch(str)
  171. {
  172. case "closeProducer":
  173. if (dcetype == "video")
  174. {
  175. RemoteRtc.Instance.me.cIdV = "";
  176. }
  177. else
  178. {
  179. RemoteRtc.Instance.me.cIdA = "";
  180. }
  181. break;
  182. }
  183. }
  184. private void OnEnable()
  185. {
  186. AgoraVideoAudioManager.Instance.JoinChannel();
  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. if (PopPeerView.Instance)
  224. {
  225. PopPeerView.Instance.list.position = new Vector3(0, 0, 0);
  226. PopPeerView.Instance.list.eulerAngles = new Vector3(0, 0, 0);
  227. PopPeerView.Instance.list.SetParent(PopPublic.Instance.transform);
  228. }
  229. if (PopUpInfo.Instance)
  230. {
  231. PopUpInfo.Instance.transform.position = new Vector3(0, 0, 0);
  232. PopUpInfo.Instance.transform.eulerAngles = new Vector3(0, 0, 0);
  233. PopUpInfo.Instance.transform.SetParent(PopPublic.Instance.transform);
  234. }
  235. //sendAudio(false);
  236. //sendVideo(false);
  237. WSHandler.roomRtcCloes();
  238. WSHandler.Office.ChangeUserType(UserInfo.BusyType);
  239. ScenesManager.Instance.showWindow(SceneType.ShowOffice);
  240. if (InviteDlg.Instance)
  241. {
  242. InviteDlg.Instance.InvitingUnionIdList.Clear();
  243. }
  244. if (ArrowList.Instance)
  245. {
  246. ArrowList.Instance.DeleteAll();
  247. }
  248. if (RoomFile.Instance)
  249. {
  250. RoomFile.Instance.ClearAllFileItem();
  251. }
  252. if (PrintscreenList.Instance)
  253. {
  254. PrintscreenList.Instance.DeleteAll();
  255. }
  256. if (PopPeerView.Instance)
  257. {
  258. PopPeerView.Instance.DestoryAll();
  259. }
  260. if (PopCall.Instance)
  261. {
  262. PopCall.Instance.gameObject.SetActive(false);
  263. }
  264. if (ShowRoom.Instance)
  265. {
  266. ShowRoom.Instance.ShowMainScreen();
  267. ShowRoom.Instance.transform.position = new Vector3(0, 0.9f, 0);
  268. ShowRoom.Instance.transform.eulerAngles = new Vector3(0, 0, 0);
  269. }
  270. if (GameStart.Instance && GameStart.Instance.systemMenu)
  271. {
  272. GameStart.Instance.systemMenu.ResetPattern();
  273. }
  274. API_GSXR_Slam.GSXR_Reset_Slam();
  275. AgoraVideoAudioManager.Instance.LeaveChannel();
  276. }
  277. public void CloseRoom()
  278. {
  279. PopUpInfo.Instance.showPublic(PopUpInfo.PopType.Pop, RtcStrConfig.roomPeopleLeave, "确定", () => { LeaveRoom(); }, "取消"
  280. );
  281. //if (RoomMainInfo.isCreator == "0")
  282. //{
  283. // PopUpInfo.Instance.showPublic(PopUpInfo.PopType.Pop, RtcStrConfig.roomCreatorLeave, "确定", () => { LeaveRoom(); }, "取消"
  284. // );
  285. //}
  286. //else
  287. //{
  288. // PopUpInfo.Instance.showPublic(PopUpInfo.PopType.Pop, RtcStrConfig.roomPeopleLeave, "确定", () => { LeaveRoom(); }, "取消"
  289. // );
  290. //}
  291. }
  292. public void ShowRoomissolvePop()
  293. {
  294. PopUpInfo.Instance.showPublic(PopUpInfo.PopType.PopOk, RtcStrConfig.roomdissolve, "知道了");
  295. }
  296. public void sendVideo(bool isSend)
  297. {
  298. //if (RemoteRtc.Instance.me.cIdV == "")
  299. //{
  300. // dcetype = "video";
  301. // Debug.Log("开启1111");
  302. // RemoteRtc.Instance.startCamera();
  303. // // videoBG.gameObject.SetActive(true);
  304. // // videoBG.material.mainTexture = RemoteRtc.Instance.rt;
  305. // RemoteRtc.Instance.sendVideo(true);
  306. // RemoteRtc.Instance.me.cIdV = "";
  307. // openVideoEffect();
  308. //}else if (RemoteRtc.Instance.me.cIdV != "")
  309. //{
  310. // dcetype = "video";
  311. // Debug.Log("关闭11111");
  312. // WSHandler.Rtc.closeProducer(RemoteRtc.Instance.me.cIdV);
  313. // RemoteRtc.Instance.stopCamera();
  314. // RemoteRtc.Instance.sendVideo(false);
  315. // closeVideoEffect();
  316. //}
  317. if(isSend)
  318. {
  319. dcetype = "video";
  320. Debug.Log("开启1111");
  321. openVideoEffect();
  322. }
  323. else
  324. {
  325. dcetype = "video";
  326. closeVideoEffect();
  327. }
  328. AgoraVideoAudioManager.Instance.EnableLocalVideo(isSend);
  329. }
  330. public void sendAudio(bool isSend)
  331. {
  332. //if (RemoteRtc.Instance.me.cIdA != "")
  333. //{
  334. // dcetype = "audio";
  335. // WSHandler.Rtc.closeProducer(RemoteRtc.Instance.me.cIdA);
  336. // RemoteRtc.Instance.sendMic(false);
  337. // RemoteRtc.Instance.me.cIdA = "";
  338. // closeAudioEffect();
  339. //}
  340. //else
  341. //{
  342. // dcetype = "audio";
  343. // RemoteRtc.Instance.sendMic(true);
  344. // // volume = RemoteRtc.Instance.me.volumn;
  345. // openAudioEffect();
  346. //}
  347. if (!isSend)
  348. {
  349. dcetype = "audio";
  350. closeAudioEffect();
  351. }
  352. else
  353. {
  354. dcetype = "audio";
  355. openAudioEffect();
  356. }
  357. AgoraVideoAudioManager.Instance.EnableLoacalAudio(isSend);
  358. }
  359. private void closeVideoEffect()
  360. {
  361. isSendVideo = false;
  362. videoOpenBtn.SetActive(true);
  363. videoCloseBtn.SetActive(false);
  364. }
  365. private void openVideoEffect()
  366. {
  367. isSendVideo = true;
  368. videoOpenBtn.SetActive(false);
  369. videoCloseBtn.SetActive(true);
  370. }
  371. private void closeAudioEffect()
  372. {
  373. isSendAudio = false;
  374. audioOpenBtn.SetActive(true);
  375. audioCloseBtn.SetActive(false);
  376. }
  377. private void openAudioEffect()
  378. {
  379. isSendAudio = true;
  380. audioOpenBtn.SetActive(false);
  381. audioCloseBtn.SetActive(true);
  382. }
  383. public void openEye()
  384. {
  385. isCloseView = false;
  386. changeViewOpenBtn.SetActive(false);
  387. changeViewCloseBtn.SetActive(true);
  388. RemoteRtc.Instance.changeViewOpen();
  389. }
  390. public void closeEye()
  391. {
  392. isCloseView = true;
  393. changeViewOpenBtn.SetActive(true);
  394. changeViewCloseBtn.SetActive(false);
  395. RemoteRtc.Instance.changeViewClose();
  396. }
  397. public void ClearAllArrow()
  398. {
  399. if (ArrowList.Instance)
  400. {
  401. ArrowList.Instance.DeleteAll();
  402. }
  403. }
  404. }