using LitJson; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class PeerView : BaseView { public MeshRenderer videoMr; public MeshRenderer audioMr; public Material gray; public Material color; public GameObject kuang; public GameObject bigButton; public GameObject bigView; public GameObject MainQuad; public GameObject isVideoGM; public GameObject isAudioGM; public override void Init() { base.Init(); Debug.Log("初始化"); } // Start is called before the first frame update public override void Start() { } CustomPeer cp; public override void UpdateConfig(BaseConfig config) { base.UpdateConfig(config); if(config!=null) { if(cp!=null) { cp.onChangeTexture -= onChangeTexture; cp.onChangeInfo -= onChangeInfo; cp.onChangeName -= onChangeName; } cp = (config as CustomPeer); cp.onChangeTexture += onChangeTexture; cp.onChangeInfo += onChangeInfo; cp.onChangeName += onChangeName; if (cp.cIdV != null && cp.cIdV != "" && cp.isVideo) { MainQuad.GetComponent().material.mainTexture = cp.tex; isVideoGM.SetActive(false); } else { MainQuad.GetComponent().material.mainTexture = CustomRTC.Instance.t2; isVideoGM.SetActive(true); } if (cp.cIdV == "") { videoMr.material = gray; } else { videoMr.material = color; } if ( CustomRTC.Instance.bigNameID == cp.peerId) { kuang.SetActive(true); bigButton.SetActive(false); } else { kuang.SetActive(false); bigButton.SetActive(true); } if (cp.cIdA != null && cp.cIdA != "" && cp.isAudio) isAudioGM.SetActive(false); else isAudioGM.SetActive(true); Debug.Log("设置图像。。。。"); titleTextMesh.text = "用户名:"+cp.name; if (cp.cIdA == "") { audioMr.material = gray; } else { audioMr.material = color; } if(CustomRTC.Instance.bigNameID=="") { showBigVideo(); } } } public void showBigVideo() { Debug.Log("改变大图像"); if (cp.isVideo && cp.cIdV != "") { CustomRTC.Instance.bigMr.material.mainTexture = cp.tex; } else { CustomRTC.Instance.bigMr.material.mainTexture = CustomRTC.Instance.t2; } CustomRTC.Instance.bigNameID = cp.peerId; CustomRTC.Instance.list.Refresh(); bigButton.SetActive(false); kuang.SetActive(true); Debug.Log("改变大图像End"); } public override void OnDestroy() { base.OnDestroy(); if(cp!=null) { cp.onChangeTexture -= onChangeTexture; cp.onChangeInfo -= onChangeInfo; cp.onChangeName -= onChangeName; } } private void onChangeName(string n) { titleTextMesh.text = "用户名:" + cp.name; } private void onChangeInfo(string type, string id) { Debug.Log("onChangeInfo。。。。"); if (type == "video") { if(cp.isVideo) { isVideoGM.SetActive(false); } videoMr.material = color; } else { audioMr.material = color; if (cp.isAudio) { isAudioGM.SetActive(false); } } } private void onChangeTexture() { if (cp.isVideo) { Debug.Log("onChangeTexture。。。。"); MainQuad.GetComponent().material.mainTexture = cp.tex; cp.isVideo = true; if (CustomRTC.Instance.bigNameID == cp.peerId|| CustomRTC.Instance.bigNameID=="") { Debug.Log("onChangeTexture2222。。。。"); showBigVideo(); } } } public void showBigView() { GameObject newBigView = GameObject.Instantiate(bigView); newBigView.SetActive(true); newBigView.GetComponent().cp = cp; newBigView.GetComponent().init(); } public override void OnClick() { base.OnClick(); showBigVideo(); } public override void Update() { } public void chooseVideo() { if (isVideoGM.activeSelf) { openVideo(); } else { closeVideo(); } } public void chooseAudio() { if (isAudioGM.activeSelf) { openAudio(); } else { closeAudio(); } } public void openVideo() { if (cp.cIdV != "") { SCRtcFactory.Instance.mSCRtcHandle.openRev(cp.cIdV); MainQuad.GetComponent().material.mainTexture = cp.tex; // if (cidV != "") // SCRtcFactory.Instance.mSCRtcHandle.openRev(cidV); // Debug.Log("openVideo2" + cidV); isVideoGM.SetActive(false); cp.isVideo = true; if (CustomRTC.Instance.bigNameID == "") { CustomRTC.Instance.showNextTexture(); } } } public void closeVideo() { if (cp.cIdV != "") { SCRtcFactory.Instance.mSCRtcHandle.closeRev(cp.cIdV); Texture2D oVideo = cp.tex; MainQuad.GetComponent().material.mainTexture = CustomRTC.Instance.t2; cp.isVideo = false; isVideoGM.SetActive(true); if (CustomRTC.Instance.bigNameID == cp.peerId) { CustomRTC.Instance.showNextTexture(); } } } public void openAudio() { if (cp.cIdA != "") { cp.isAudio = true; SCRtcFactory.Instance.mSCRtcHandle.openRev(cp.cIdA); isAudioGM.SetActive(false); } } public void closeAudio() { if (cp.cIdA != "") { cp.isAudio = false; SCRtcFactory.Instance.mSCRtcHandle.closeRev(cp.cIdA); isAudioGM.SetActive(true); } } double volumeD; public void setAudioAdd() { if (cp.cIdA != "") { volumeD += 0.1f; Debug.Log("setVolumePeer" + volumeD.ToString()); //volume.text = volumeD.ToString(); SCRtcFactory.Instance.mSCRtcHandle.audioPeerChange(cp.cIdA, volumeD); } } public void setAudioRed() { if (cp.cIdA != "") { volumeD -= 0.1f; Debug.Log("setVolumePeer" + volumeD.ToString()); // volume.text = volumeD.ToString(); SCRtcFactory.Instance.mSCRtcHandle.audioPeerChange(cp.cIdA, volumeD); } } }