PeerBigView.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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);
  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. }
  176. public void CloseVideo()
  177. {
  178. if (cPeer != null && cPeer.isVideo && cPeer.cIdV != "" && !cPeer.isCloseVideo)
  179. {
  180. RemoteRtc.Instance.closeRev(cPeer.cIdV);
  181. cPeer.isCloseVideo = true;
  182. // cPeer.setInfo("audio", cPeer.cIdA,true);
  183. }
  184. }
  185. public void openMic()
  186. {
  187. if (cPeer != null && cPeer.isAudio && cPeer.cIdA != "" && cPeer.isCloseAudio)
  188. {
  189. RemoteRtc.Instance.startRev(cPeer.cIdA);
  190. cPeer.isCloseAudio = false;
  191. // cPeer.setInfo("audio", cPeer.cIdA,true);
  192. }
  193. }
  194. public void closeMic()
  195. {
  196. if (cPeer != null && cPeer.isAudio && cPeer.cIdA != "" && !cPeer.isCloseAudio)
  197. {
  198. RemoteRtc.Instance.closeRev(cPeer.cIdA);
  199. cPeer.isCloseAudio = true;
  200. // cPeer.setInfo("audio", cPeer.cIdA, false);
  201. }
  202. }
  203. public void OnDrag(PointerEventData eventData)
  204. {
  205. }
  206. public void OnEndDrag(PointerEventData eventData)
  207. {
  208. if (!isMove)
  209. {
  210. float dic = Vector3.Distance(initPos, this.transform.position);
  211. if (dic > 0.1f)
  212. {
  213. PopPeerView.Instance.ViewOut(this);
  214. isMove = true;
  215. }
  216. }
  217. }
  218. }