using ShadowStudio.Mgr; using ShadowStudio.Model; using ShadowStudio.UI; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using Vuforia; using XRTool.Util; using XRTool.WorldUI; public class ItemUserView : MonoBehaviour { public Peer _peer; public MeshRenderer videoBG; public Text nametext; public XRIcon touxiang; public Button bigBtn; // Start is called before the first frame update void Start() { bigBtn.onClick.AddListener(OnClickBigBtn); if (_peer.IsSlef) // AgoraVideoAudioManager.Instance.JoinChannel(CommonMethod.roomConfig.Id); AgoraVideoAudioManager.Instance.OpenAgoraAudio(); } private void OnClickBigBtn() { if (ShowViewMgr.Instance) { PlayerViewComponent.CreateViewComponent(this._peer.PeerId, ShowViewMgr.Instance.Target); } } private void Update() { checkPeer(); if(videoBG.gameObject.activeSelf&& cPeer!=null&&!_peer.IsSlef) { videoBG.material.mainTexture = cPeer.tex; } } void checkPeer() { if (cPeer == null&& SCRtcFactory.Instance!=null&& SCRtcFactory.Instance.mSCRtcPeers!=null&& _peer!=null) { cPeer = (CustomPeer)SCRtcFactory.Instance.mSCRtcPeers.getPeerName(_peer.PeerId); _peer.CustomPeer = cPeer; if (cPeer != null) { cPeer.onChangeInfo -= OnChangeInfo; cPeer.onChangeInfo += OnChangeInfo; if (!_peer.IsSlef) { if (cPeer.isAudio && cPeer.cIdA != "") { openAudioEffect(); } else { closeAudioEffect(); } if (cPeer.isVideo&& cPeer.cIdV!="") { openVideoEffect(); } else { closeVideoEffect(); } } } } } CustomPeer cPeer; public void Init(Peer peer) { Debug.Log("123213Init213213"+ peer.Avatar); _peer = peer; nametext.text = peer.NickName; textMic.text = "0.02"; VolumnGo.SetActive(false); if (!string.IsNullOrEmpty(peer.Avatar)) { for (int i = 0; i < CommonMethod.UserAvatarsList.Count; i++) { if (peer.Avatar == CommonMethod.UserAvatarsList[i].Url) { string path = "Avatar/" + CommonMethod.UserAvatarsList[i].Id + "Avatar"; touxiang.icon = Resources.Load(path) as Texture2D; touxiang.AutoSetSprite(); } } } if (_peer.IsSlef) { nametext.text = "" + peer.NickName + ""; openAudio.GetComponent().color = new Color(255, 0, 0, 255); openVideo.GetComponent().color = new Color(255, 0, 0, 255); Invoke("checkAudio", 0.5f); // Invoke("checkVideo", 1f); } } private void checkVideo() { if (CustomInfo.isSendVideo&& (!CustomInfo.isSendAudio|| StudioRtc.Instance.me.cIdA != "")) { OpenVideo(); } else if(CustomInfo.isSendAudio&& CustomInfo.isSendVideo) { Invoke("checkVideo", 0.5f); } } private void checkAudio() { if (CustomInfo.isSendAudio) { openMic(); checkVideo(); } else { if (CustomInfo.isSendVideo) { OpenVideo(); } } } private void OnEnable() { if (_peer!=null&&_peer.IsSlef) { if (StudioRtc.Instance != null && StudioRtc.Instance.me != null && StudioRtc.Instance.me.cIdA != "") { openAudioEffect(); } else { closeAudioEffect(); } if (StudioRtc.Instance != null && StudioRtc.Instance.me != null && StudioRtc.Instance.me.cIdV != "") { openVideoEffect(); } else { closeVideoEffect(); } } } private void closeAudioEffect() { pauseCerAudio.SetActive(true); pauseAudio.SetActive(false); openAudio.SetActive(true); closeAudio.SetActive(false); VolumnGo.SetActive(false); if (this._peer.PeerId == CommonMethod.MyPeer.PeerId) AgoraVideoAudioManager.Instance.EnableLoacalAudio(false); //else // AgoraVideoAudioManager.Instance.MuteRemoteAudioStream(_peer.PeerId, false); } private void openAudioEffect() { openAudio.SetActive(false); closeAudio.SetActive(true); VolumnGo.SetActive(true); if (cPeer != null) { volume = cPeer.volumn; if (cPeer.isCloseAudio) { pauseCerAudio.SetActive(false); pauseAudio.SetActive(true); } } textMic.text = volume.ToString("F2"); if (this._peer.PeerId == CommonMethod.MyPeer.PeerId) AgoraVideoAudioManager.Instance.EnableLoacalAudio(true); //else // AgoraVideoAudioManager.Instance.MuteRemoteAudioStream(_peer.PeerId, true); } private void OnChangeInfo(string type, string id) { if (type == "video") { if (cPeer.isVideo) { openVideoEffect(); if (cPeer.isCloseVideo) { StudioRtc.Instance.closeRev(cPeer.cIdV); } } else { closeVideoEffect(); } } else { if (cPeer.isAudio) { openAudioEffect(); if (cPeer.isCloseAudio) { StudioRtc.Instance.closeRev(cPeer.cIdA); } } else { closeAudioEffect(); } } } public GameObject openAudio; public GameObject closeAudio; public GameObject VolumnGo; public void openMic() { if (_peer.IsSlef) { StudioRtc.Instance.sendMic(true); volume = StudioRtc.Instance.me.volumn; openAudioEffect(); } else { if (cPeer != null&&cPeer.isAudio&&cPeer.isCloseAudio) { pauseCerAudio.SetActive(true); pauseAudio.SetActive(false); StudioRtc.Instance.startRev(cPeer.cIdA); cPeer.isCloseAudio = false; // cPeer.setInfo("audio", cPeer.cIdA,true); AgoraVideoAudioManager.Instance.MuteRemoteAudioStream(_peer.PeerId, false); } } } public float volume = 0.2f; public Text textMic; public void addMic() { volume += 0.1f; if (_peer.IsSlef) { StudioRtc.Instance.setVolume(volume); } else { if (cPeer != null&& cPeer.cIdA!="") { StudioRtc.Instance.setVolume(cPeer.cIdA,volume); } } textMic.text = volume.ToString("F2"); } public void redMic() { volume -= 0.1f; if (_peer.IsSlef) { StudioRtc.Instance.setVolume(volume); } else { if (cPeer != null && cPeer.cIdA != "") { StudioRtc.Instance.setVolume(cPeer.cIdA, volume); } } textMic.text = volume.ToString("F2"); } public void closeMic() { if (_peer.IsSlef) { if(StudioRtc.Instance.me.cIdA!="") { WSHandler.Rtc.closeProducer(StudioRtc.Instance.me.cIdA); StudioRtc.Instance.sendMic(false); closeAudioEffect(); StudioRtc.Instance.me.cIdA = ""; } closeAudioEffect(); } else { if (cPeer != null && cPeer.isAudio && !cPeer.isCloseAudio) { pauseCerAudio.SetActive(false); pauseAudio.SetActive(true); StudioRtc.Instance.closeRev(cPeer.cIdA); cPeer.isCloseAudio = true; AgoraVideoAudioManager.Instance.MuteRemoteAudioStream(_peer.PeerId, true); // cPeer.setInfo("audio", cPeer.cIdA, false); } } } public GameObject pauseCerAudio; public GameObject pauseCerVideo; public GameObject pauseAudio; public GameObject pauseVideo; public GameObject openVideo; public GameObject closeVideo; public void OpenVideo() { if (_peer.IsSlef) { Debug.Log("OpenVideo==>" + StudioRtc.Instance.me.cIdV); StudioRtc.Instance.startCamera(); // videoBG.gameObject.SetActive(true); videoBG.material.mainTexture = StudioRtc.Instance.rt; StudioRtc.Instance.sendVideo(true); openVideoEffect(); } else { if (cPeer != null && cPeer.isVideo && cPeer.isCloseVideo) { pauseCerVideo.SetActive(true); pauseVideo.SetActive(false); StudioRtc.Instance.startRev(cPeer.cIdV); cPeer.isCloseVideo = false; // cPeer.setInfo("audio", cPeer.cIdA,true); } } } public void CloseVideo() { if (_peer.IsSlef) { if (StudioRtc.Instance.me.cIdV != "") { Debug.Log("CloseVideo==>" + StudioRtc.Instance.me.cIdV); WSHandler.Rtc.closeProducer(StudioRtc.Instance.me.cIdV); StudioRtc.Instance.stopCamera(); StudioRtc.Instance.sendVideo(false); closeVideoEffect(); StudioRtc.Instance.me.cIdV = ""; } closeVideoEffect(); } else { if (cPeer != null && cPeer.isVideo && cPeer.cIdV != "" && !cPeer.isCloseVideo) { pauseCerVideo.SetActive(false); pauseVideo.SetActive(true); StudioRtc.Instance.closeRev(cPeer.cIdV); cPeer.isCloseVideo = true; // cPeer.setInfo("audio", cPeer.cIdA,true); } } } private void closeVideoEffect() { openVideo.SetActive(true); closeVideo.SetActive(false); // videoBG.gameObject.SetActive(false); if (cPeer != null) { pauseCerVideo.SetActive(true); pauseVideo.SetActive(false); } if (this._peer.PeerId == CommonMethod.MyPeer.PeerId) AgoraVideoAudioManager.Instance.EnableLocalVideo(false); } private void openVideoEffect() { openVideo.SetActive(false); closeVideo.SetActive(true); if (cPeer != null) { // videoBG.gameObject.SetActive(true); if (cPeer.isCloseVideo) { pauseCerVideo.SetActive(false); pauseVideo.SetActive(true); } } if (this._peer.PeerId == CommonMethod.MyPeer.PeerId) AgoraVideoAudioManager.Instance.EnableLocalVideo(true); } }