using LitJson; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; using XRTool.Util; public class PeerBigView : MonoBehaviour,IDragHandler,IEndDragHandler { public bool isMove; public Text tName; public MeshRenderer mViewTexture; public SysEnterManager sysEenter; public CustomPeer cPeer; private BoundingBox boundBox; private Vector3 initPos; public GameObject AudioEffect; public RawImage agoraRawImage; private void Start() { if (!boundBox) { boundBox = GetComponent(); if (!boundBox) { UnityLog.LogError(gameObject.name + "this is no XBoundingBox"); } else { boundBox.ScaleStopped.AddListener(OnScaleStopped); } } PopPeerView.CloseView += closeView; WSHandler.Rtc.OnActiveSpeaker += ActiveSpeaker; // AgoraVideoAudioManager.Instance.AddListShowView(cPeer.peerId, agoraRawImage, false); } private void OnDestroy() { PopPeerView.CloseView -= closeView; WSHandler.Rtc.OnActiveSpeaker -= ActiveSpeaker; } SCRtcPeer p; private void ActiveSpeaker(JsonData data) { if (this.gameObject.activeSelf) { if (data["data"]["peerId"] != null) { string peerId = data["data"]["peerId"].ToString(); if (!string.IsNullOrEmpty(peerId)) { p = SCRtcFactory.Instance.mSCRtcPeers.getPeer(peerId); if (p != null) { p.changeVolumn(int.Parse(data["data"]["volume"].ToString())); } if (cPeer != null && peerId == cPeer.peerId) { AudioEffect.SetActive(true); } else { AudioEffect.SetActive(false); } } } } } public void OnScaleStopped() { if (transform.localScale.x < 1f) { transform.localScale = Vector3.one; } } private void Update() { } public void initView() { initPos = this.transform.position; sysEenter.cPeer = cPeer; cPeer.isShow = true; if(cPeer.isCloseVideo||!cPeer.isVideo) { mViewTexture.material.mainTexture = RemoteRtc.Instance.NoView; } else { mViewTexture.material.mainTexture = cPeer.tex; } tName.text = cPeer.name; cPeer.onChangeInfo -= OnChangeInfo; cPeer.onChangeInfo += OnChangeInfo; cPeer.onChangeTexture -= onChangeTexture; cPeer.onChangeTexture += onChangeTexture; cPeer.onChangeName -= onChangeName; cPeer.onChangeName += onChangeName; RoomOtherUser.Instance.UpdateList(); checkPeer(); } void onChangeTexture() { if (cPeer.isCloseVideo || !cPeer.isVideo) { mViewTexture.material.mainTexture = RemoteRtc.Instance.NoView; } else { mViewTexture.material.mainTexture = cPeer.tex; } } void onChangeName(string cName) { tName.text = cName; } void checkPeer() { } public void closeView() { cPeer.onChangeInfo -= OnChangeInfo; cPeer.onChangeTexture -= onChangeTexture; cPeer.onChangeName -= onChangeName; PopPeerView.Instance.bigList.Remove(this); cPeer.isShow = false; RoomOtherUser.Instance.UpdateList(); PopPeerView.Instance.closeView(this); } private void OnChangeInfo(string type, string id) { if (type == "video") { if (cPeer.isVideo) { if (cPeer.isCloseVideo) { RemoteRtc.Instance.closeRev(cPeer.cIdV); } } else { } } else { if (cPeer.isAudio) { if (cPeer.isCloseAudio) { RemoteRtc.Instance.closeRev(cPeer.cIdA); } } else { } } if (cPeer.isCloseVideo || !cPeer.isVideo) { mViewTexture.material.mainTexture = RemoteRtc.Instance.NoView; } else { mViewTexture.material.mainTexture = cPeer.tex; } } public void OpenVideo() { //if (cPeer != null && cPeer.isVideo && cPeer.cIdV != "" && cPeer.isCloseVideo) //{ // RemoteRtc.Instance.startRev(cPeer.cIdV); // cPeer.isCloseVideo = false; // // cPeer.setInfo("audio", cPeer.cIdA,true); //} // AgoraVideoAudioManager.Instance.MuteRemoteVideoStream(cPeer.peerId, true); //agoraRawImage.gameObject.SetActive(true); // RoomMain.Instance.agoraRawImage.gameObject.SetActive(true); } public void CloseVideo() { //if (cPeer != null && cPeer.isVideo && cPeer.cIdV != "" && !cPeer.isCloseVideo) //{ // RemoteRtc.Instance.closeRev(cPeer.cIdV); // cPeer.isCloseVideo = true; // // cPeer.setInfo("audio", cPeer.cIdA,true); //} // AgoraVideoAudioManager.Instance.MuteRemoteVideoStream(cPeer.peerId, false); // agoraRawImage.gameObject.SetActive(false); // RoomMain.Instance.agoraRawImage.gameObject.SetActive(false); } public void openMic() { //if (cPeer != null && cPeer.isAudio && cPeer.cIdA != "" && cPeer.isCloseAudio) //{ // RemoteRtc.Instance.startRev(cPeer.cIdA); // cPeer.isCloseAudio = false; // // cPeer.setInfo("audio", cPeer.cIdA,true); //} // cPeer.isCloseAudio = false; // AgoraVideoAudioManager.Instance.MuteRemoteAudioStream(cPeer.peerId, true); } public void closeMic() { //if (cPeer != null && cPeer.isAudio && cPeer.cIdA != "" && !cPeer.isCloseAudio) //{ // RemoteRtc.Instance.closeRev(cPeer.cIdA); // cPeer.isCloseAudio = true; // // cPeer.setInfo("audio", cPeer.cIdA, false); //} // cPeer.isCloseAudio = true; // AgoraVideoAudioManager.Instance.MuteRemoteAudioStream(cPeer.peerId, false); } public void OnDrag(PointerEventData eventData) { } public void OnEndDrag(PointerEventData eventData) { if (!isMove) { float dic = Vector3.Distance(initPos, this.transform.position); if (dic > 0.1f) { PopPeerView.Instance.ViewOut(this); isMove = true; } } } }