123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423 |
- 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 = "<color=yellow>" + peer.NickName + "</color>";
- openAudio.GetComponent<UnityEngine.UI.Image>().color = new Color(255, 0, 0, 255);
- openVideo.GetComponent<UnityEngine.UI.Image>().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);
- }
- }
|