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