PeerBigView.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. using LitJson;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.EventSystems;
  6. using UnityEngine.UI;
  7. using XRTool.Util;
  8. public class PeerBigView : MonoBehaviour,IDragHandler,IEndDragHandler
  9. {
  10. public bool isMove;
  11. public Text tName;
  12. public MeshRenderer mViewTexture;
  13. public SysEnterManager sysEenter;
  14. public CustomPeer cPeer;
  15. private BoundingBox boundBox;
  16. private Vector3 initPos;
  17. public GameObject AudioEffect;
  18. public RawImage agoraRawImage;
  19. private void Start()
  20. {
  21. if (!boundBox)
  22. {
  23. boundBox = GetComponent<BoundingBox>();
  24. if (!boundBox)
  25. {
  26. UnityLog.LogError(gameObject.name + "this is no XBoundingBox");
  27. }
  28. else
  29. {
  30. boundBox.ScaleStopped.AddListener(OnScaleStopped);
  31. }
  32. }
  33. PopPeerView.CloseView += closeView;
  34. WSHandler.Rtc.OnActiveSpeaker += ActiveSpeaker;
  35. // AgoraVideoAudioManager.Instance.AddListShowView(cPeer.peerId, agoraRawImage, false);
  36. }
  37. private void OnDestroy()
  38. {
  39. PopPeerView.CloseView -= closeView;
  40. WSHandler.Rtc.OnActiveSpeaker -= ActiveSpeaker;
  41. }
  42. SCRtcPeer p;
  43. private void ActiveSpeaker(JsonData data)
  44. {
  45. if (this.gameObject.activeSelf)
  46. {
  47. if (data["data"]["peerId"] != null)
  48. {
  49. string peerId = data["data"]["peerId"].ToString();
  50. if (!string.IsNullOrEmpty(peerId))
  51. {
  52. p = SCRtcFactory.Instance.mSCRtcPeers.getPeer(peerId);
  53. if (p != null)
  54. {
  55. p.changeVolumn(int.Parse(data["data"]["volume"].ToString()));
  56. }
  57. if (cPeer != null && peerId == cPeer.peerId)
  58. {
  59. AudioEffect.SetActive(true);
  60. }
  61. else
  62. {
  63. AudioEffect.SetActive(false);
  64. }
  65. }
  66. }
  67. }
  68. }
  69. public void OnScaleStopped()
  70. {
  71. if (transform.localScale.x < 1f)
  72. {
  73. transform.localScale = Vector3.one;
  74. }
  75. }
  76. private void Update()
  77. {
  78. }
  79. public void initView()
  80. {
  81. initPos = this.transform.position;
  82. sysEenter.cPeer = cPeer;
  83. cPeer.isShow = true;
  84. if(cPeer.isCloseVideo||!cPeer.isVideo)
  85. {
  86. mViewTexture.material.mainTexture = RemoteRtc.Instance.NoView;
  87. }
  88. else
  89. {
  90. mViewTexture.material.mainTexture = cPeer.tex;
  91. }
  92. tName.text = cPeer.name;
  93. cPeer.onChangeInfo -= OnChangeInfo;
  94. cPeer.onChangeInfo += OnChangeInfo;
  95. cPeer.onChangeTexture -= onChangeTexture;
  96. cPeer.onChangeTexture += onChangeTexture;
  97. cPeer.onChangeName -= onChangeName;
  98. cPeer.onChangeName += onChangeName;
  99. RoomOtherUser.Instance.UpdateList();
  100. checkPeer();
  101. }
  102. void onChangeTexture()
  103. {
  104. if (cPeer.isCloseVideo || !cPeer.isVideo)
  105. {
  106. mViewTexture.material.mainTexture = RemoteRtc.Instance.NoView;
  107. }
  108. else
  109. {
  110. mViewTexture.material.mainTexture = cPeer.tex;
  111. }
  112. }
  113. void onChangeName(string cName)
  114. {
  115. tName.text = cName;
  116. }
  117. void checkPeer()
  118. {
  119. }
  120. public void closeView()
  121. {
  122. cPeer.onChangeInfo -= OnChangeInfo;
  123. cPeer.onChangeTexture -= onChangeTexture;
  124. cPeer.onChangeName -= onChangeName;
  125. PopPeerView.Instance.bigList.Remove(this);
  126. cPeer.isShow = false;
  127. RoomOtherUser.Instance.UpdateList();
  128. PopPeerView.Instance.closeView(this);
  129. }
  130. private void OnChangeInfo(string type, string id)
  131. {
  132. if (type == "video")
  133. {
  134. if (cPeer.isVideo)
  135. {
  136. if (cPeer.isCloseVideo)
  137. {
  138. RemoteRtc.Instance.closeRev(cPeer.cIdV);
  139. }
  140. }
  141. else
  142. {
  143. }
  144. }
  145. else
  146. {
  147. if (cPeer.isAudio)
  148. {
  149. if (cPeer.isCloseAudio)
  150. {
  151. RemoteRtc.Instance.closeRev(cPeer.cIdA);
  152. }
  153. }
  154. else
  155. {
  156. }
  157. }
  158. if (cPeer.isCloseVideo || !cPeer.isVideo)
  159. {
  160. mViewTexture.material.mainTexture = RemoteRtc.Instance.NoView;
  161. }
  162. else
  163. {
  164. mViewTexture.material.mainTexture = cPeer.tex;
  165. }
  166. }
  167. public void OpenVideo()
  168. {
  169. //if (cPeer != null && cPeer.isVideo && cPeer.cIdV != "" && cPeer.isCloseVideo)
  170. //{
  171. // RemoteRtc.Instance.startRev(cPeer.cIdV);
  172. // cPeer.isCloseVideo = false;
  173. // // cPeer.setInfo("audio", cPeer.cIdA,true);
  174. //}
  175. // AgoraVideoAudioManager.Instance.MuteRemoteVideoStream(cPeer.peerId, true);
  176. //agoraRawImage.gameObject.SetActive(true);
  177. // RoomMain.Instance.agoraRawImage.gameObject.SetActive(true);
  178. }
  179. public void CloseVideo()
  180. {
  181. //if (cPeer != null && cPeer.isVideo && cPeer.cIdV != "" && !cPeer.isCloseVideo)
  182. //{
  183. // RemoteRtc.Instance.closeRev(cPeer.cIdV);
  184. // cPeer.isCloseVideo = true;
  185. // // cPeer.setInfo("audio", cPeer.cIdA,true);
  186. //}
  187. // AgoraVideoAudioManager.Instance.MuteRemoteVideoStream(cPeer.peerId, false);
  188. // agoraRawImage.gameObject.SetActive(false);
  189. // RoomMain.Instance.agoraRawImage.gameObject.SetActive(false);
  190. }
  191. public void openMic()
  192. {
  193. //if (cPeer != null && cPeer.isAudio && cPeer.cIdA != "" && cPeer.isCloseAudio)
  194. //{
  195. // RemoteRtc.Instance.startRev(cPeer.cIdA);
  196. // cPeer.isCloseAudio = false;
  197. // // cPeer.setInfo("audio", cPeer.cIdA,true);
  198. //}
  199. // cPeer.isCloseAudio = false;
  200. // AgoraVideoAudioManager.Instance.MuteRemoteAudioStream(cPeer.peerId, true);
  201. }
  202. public void closeMic()
  203. {
  204. //if (cPeer != null && cPeer.isAudio && cPeer.cIdA != "" && !cPeer.isCloseAudio)
  205. //{
  206. // RemoteRtc.Instance.closeRev(cPeer.cIdA);
  207. // cPeer.isCloseAudio = true;
  208. // // cPeer.setInfo("audio", cPeer.cIdA, false);
  209. //}
  210. // cPeer.isCloseAudio = true;
  211. // AgoraVideoAudioManager.Instance.MuteRemoteAudioStream(cPeer.peerId, false);
  212. }
  213. public void OnDrag(PointerEventData eventData)
  214. {
  215. }
  216. public void OnEndDrag(PointerEventData eventData)
  217. {
  218. if (!isMove)
  219. {
  220. float dic = Vector3.Distance(initPos, this.transform.position);
  221. if (dic > 0.1f)
  222. {
  223. PopPeerView.Instance.ViewOut(this);
  224. isMove = true;
  225. }
  226. }
  227. }
  228. }