123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251 |
- 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<BoundingBox>();
- 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;
- }
- }
- }
- }
|