123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351 |
- using ShadowStudio.Mgr;
- using ShadowStudio.Model;
- using ShadowStudio.UI;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- 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);
- }
- private void OnClickBigBtn()
- {
- }
- 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)
- {
- _peer = peer;
- nametext.text = peer.NickName;
- textMic.text = "0.02";
- VolumnGo.SetActive(false);
- 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);
- }
- if (RemoteRtc.Instance.me!=null&& RemoteRtc.Instance.me.cIdA != "")
- {
- openAudioEffect();
- }
- closeVideoEffect();
- }
- private void OnEnable()
- {
- if(_peer!=null&&_peer.IsSlef)
- {
- if (RemoteRtc.Instance != null && RemoteRtc.Instance.me != null && RemoteRtc.Instance.me.cIdA != "")
- {
- openAudioEffect();
- }
- else
- {
- closeAudioEffect();
- }
- if (RemoteRtc.Instance != null && RemoteRtc.Instance.me != null && RemoteRtc.Instance.me.cIdV != "")
- {
- openVideoEffect();
- }
- else
- {
- closeAudioEffect();
- }
- }
- }
- private void closeAudioEffect()
- {
- pauseCerAudio.SetActive(true);
- pauseAudio.SetActive(false);
- openAudio.SetActive(true);
- closeAudio.SetActive(false);
- VolumnGo.SetActive(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");
- }
- private void OnChangeInfo(string type, string id)
- {
- if (type == "video")
- {
- if (cPeer.isVideo)
- {
- openVideoEffect();
- if (cPeer.isCloseVideo)
- {
- RemoteRtc.Instance.closeRev(cPeer.cIdV);
- }
- }
- else
- {
- closeVideoEffect();
- }
- }
- else
- {
- if (cPeer.isAudio)
- {
- openAudioEffect();
- if (cPeer.isCloseAudio)
- {
- RemoteRtc.Instance.closeRev(cPeer.cIdA);
- }
- }
- else
- {
- closeAudioEffect();
- }
- }
- }
- public GameObject openAudio;
- public GameObject closeAudio;
- public GameObject VolumnGo;
- public void openMic()
- {
- if (_peer.IsSlef)
- {
- RemoteRtc.Instance.sendMic(true);
- volume = RemoteRtc.Instance.me.volumn;
- openAudioEffect();
- }
- else
- {
-
- if (cPeer != null&&cPeer.isAudio&& cPeer.cIdA!=""&&cPeer.isCloseAudio)
- {
- pauseCerAudio.SetActive(true);
- pauseAudio.SetActive(false);
- RemoteRtc.Instance.startRev(cPeer.cIdA);
- cPeer.isCloseAudio = false;
- // cPeer.setInfo("audio", cPeer.cIdA,true);
- }
- }
- }
- public float volume = 0.2f;
- public Text textMic;
- public void addMic()
- {
- volume += 0.1f;
- if (_peer.IsSlef)
- {
- RemoteRtc.Instance.setVolume(volume);
- }
- else
- {
- if (cPeer != null&& cPeer.cIdA!="")
- {
- RemoteRtc.Instance.setVolume(cPeer.cIdA,volume);
- }
- }
- textMic.text = volume.ToString("F2");
- }
- public void redMic()
- {
- volume -= 0.1f;
- if (_peer.IsSlef)
- {
- RemoteRtc.Instance.setVolume(volume);
- }
- else
- {
- if (cPeer != null && cPeer.cIdA != "")
- {
- RemoteRtc.Instance.setVolume(cPeer.cIdA, volume);
- }
- }
- textMic.text = volume.ToString("F2");
- }
- public void closeMic()
- {
- if (_peer.IsSlef)
- {
- if(RemoteRtc.Instance.me.cIdA!="")
- {
- WSHandler.Rtc.closeProducer(RemoteRtc.Instance.me.cIdA);
- RemoteRtc.Instance.sendMic(false);
- closeAudioEffect();
- }
- }
- else
- {
-
- if (cPeer != null && cPeer.isAudio && cPeer.cIdA != "" && !cPeer.isCloseAudio)
- {
- pauseCerAudio.SetActive(false);
- pauseAudio.SetActive(true);
- RemoteRtc.Instance.closeRev(cPeer.cIdA);
- cPeer.isCloseAudio = 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)
- {
- RemoteRtc.Instance.startCamera();
- videoBG.gameObject.SetActive(true);
- videoBG.material.mainTexture = RemoteRtc.Instance.rt;
- RemoteRtc.Instance.sendVideo(true);
- openVideoEffect();
- }
- else
- {
- if (cPeer != null && cPeer.isVideo && cPeer.cIdV != "" && cPeer.isCloseVideo)
- {
- pauseCerVideo.SetActive(true);
- pauseVideo.SetActive(false);
- RemoteRtc.Instance.startRev(cPeer.cIdV);
- cPeer.isCloseVideo = false;
- // cPeer.setInfo("audio", cPeer.cIdA,true);
- }
- }
- }
- public void CloseVideo()
- {
- if (_peer.IsSlef)
- {
- if (RemoteRtc.Instance.me.cIdV != "")
- {
- WSHandler.Rtc.closeProducer(RemoteRtc.Instance.me.cIdV);
- RemoteRtc.Instance.stopCamera();
- RemoteRtc.Instance.sendVideo(false);
- closeVideoEffect();
- }
- }
- else
- {
- if (cPeer != null && cPeer.isVideo && cPeer.cIdV != "" && !cPeer.isCloseVideo)
- {
- pauseCerVideo.SetActive(false);
- pauseVideo.SetActive(true);
- RemoteRtc.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);
- }
- }
- 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);
- }
- }
- }
- }
|