RemoteRtc.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. using SUIFW;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. using XRTool.Util;
  7. public class RemoteRtc : SCRtcManager
  8. {
  9. public Texture2D NoView;
  10. public Texture2D NoUser;
  11. public Camera cam;
  12. public RawImage meshRender;
  13. public static RemoteRtc Instance;
  14. public List<FileConfig> fileConfiglist = new List<FileConfig>();
  15. // Start is called before the first frame update
  16. void Start()
  17. {
  18. WSHandler.Rtc.onRtcState += onRtcState;
  19. DontDestroyOnLoad(this.gameObject);
  20. Instance = this;
  21. }
  22. void onRtcState(string state)
  23. {
  24. if (state == "joinRoom")
  25. {
  26. string baseUIFormsName = UIManager.GetInstance().GetCurrentShowUIForms();
  27. if (baseUIFormsName != "")
  28. {
  29. UIManager.GetInstance().CloseOrReturnUIForms(baseUIFormsName);
  30. UIManager.GetInstance().ShowUIForms(SysConst.RoomMainForms);
  31. }
  32. }
  33. if (state == "joined" || state == "closed")
  34. {
  35. if (RoomOtherUser.Instance)
  36. {
  37. RoomOtherUser.Instance.UpdateList();
  38. }
  39. }
  40. }
  41. public void setVolume(float f)
  42. {
  43. // SCRtcFactory.Instance.mSCRtcHandle.audioMeChange(f);
  44. }
  45. public void setVolume(string cid, float f)
  46. {
  47. // SCRtcFactory.Instance.mSCRtcHandle.audioPeerChange(cid, f);
  48. }
  49. public void sendMic(bool boo)
  50. {
  51. SCRtcFactory.Instance.mSCRtcHandle.sendMic(boo);
  52. }
  53. public void sendVideo(bool boo)
  54. {
  55. SCRtcFactory.Instance.mSCRtcHandle.sendVideo(boo);
  56. }
  57. public void muteVideo(bool boo)
  58. {
  59. SCRtcFactory.Instance.mSCRtcHandle.sendVideo(boo);
  60. }
  61. public void muteAudio(bool boo)
  62. {
  63. SCRtcFactory.Instance.mSCRtcHandle.sendVideo(boo);
  64. }
  65. public void closeRev(string id)
  66. {
  67. SCRtcFactory.Instance.mSCRtcHandle.closeRev(id);
  68. }
  69. public void startRev(string id)
  70. {
  71. SCRtcFactory.Instance.mSCRtcHandle.openRev(id);
  72. }
  73. public RenderTexture rt;
  74. public void startCamera()
  75. {
  76. if (rt == null)
  77. {
  78. rt = new RenderTexture(CustomInfo.mWidth, CustomInfo.mHight, 1);
  79. }
  80. cam.targetTexture = rt;
  81. me.setMyCamera(rt);
  82. meshRender.gameObject.SetActive(true);
  83. }
  84. public void stopCamera()
  85. {
  86. meshRender.gameObject.SetActive(false);
  87. }
  88. public void openSpeaker()
  89. {
  90. SCRtcFactory.Instance.mSCRtcHandle.openSpeaker();
  91. }
  92. public CustomMe me;
  93. public CustomPeerList customPeerList;
  94. public void start(string roomID)
  95. {
  96. CustomInfo.RoomId = roomID;
  97. InitListener();
  98. SCRtcConfig sconfig = new SCRtcConfig();
  99. sconfig.Url = CustomInfo.url;
  100. sconfig.Post = CustomInfo.POST;
  101. sconfig.RoomId = CustomInfo.RoomId;
  102. sconfig.Token = UserInfo.User_Token;
  103. sconfig.disPlayName = UserInfo.Account;
  104. sconfig.roomPwd = CustomInfo.roomPwd;
  105. sconfig.isRevAllAudio = true;
  106. sconfig.isRevAllVideo = true;
  107. sconfig.isSendAudio = false;
  108. sconfig.isSendVideo = false;
  109. sconfig.mWidth = CustomInfo.mWidth;
  110. sconfig.mHight = CustomInfo.mHight;
  111. sconfig.FPS = CustomInfo.FPS;
  112. me = new CustomMe();
  113. customPeerList = new CustomPeerList();
  114. SCRtcFactory.Instance.init(sconfig, this, me, customPeerList);
  115. }
  116. //关闭RTC
  117. public void Close()
  118. {
  119. SCRtcFactory.Instance.Close();
  120. if (SCRtcFactory.Instance != null && SCRtcFactory.Instance.mSCRtcPeers != null)
  121. {
  122. SCRtcFactory.Instance.mSCRtcPeers.initPeers();
  123. }
  124. }
  125. void Update()
  126. {
  127. SCRtcFactory.Instance.Update();
  128. }
  129. //public void changeViewClose()
  130. //{
  131. // CustomInfo.isCloseView = true;
  132. // cam.cullingMask = 1 << 9;
  133. // WSHandler.Rtc.onRtcState("changeView");
  134. //}
  135. //public void changeViewOpen()
  136. //{
  137. // CustomInfo.isCloseView = false;
  138. // cam.cullingMask = -1;
  139. // WSHandler.Rtc.onRtcState("changeView");
  140. //}
  141. private void OnDestroy()
  142. {
  143. WSHandler.Rtc.onRtcState -= onRtcState;
  144. }
  145. }