123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332 |
- using LitJson;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PeerView : BaseView
- {
- public GameObject audioGray;
- public GameObject audioColor;
- public GameObject videoGray;
- public GameObject videoColor;
- public GameObject kuang;
- public GameObject bigButton;
- public GameObject bigView;
- public GameObject MainQuad;
- public GameObject isVideoGM;
- public GameObject isAudioGM;
- public GameObject isVideoGM1;
- public GameObject isAudioGM1;
- public void Init()
- {
- Debug.Log("初始化");
- }
- // Start is called before the first frame update
- public void Start()
- {
- }
- CustomPeer cp;
- public void UpdateConfig(BaseConfig 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<MeshRenderer>().material.mainTexture = cp.tex;
- isVideoGM.SetActive(false);
- isVideoGM1.SetActive(false);
- }
- else
- {
- MainQuad.GetComponent<MeshRenderer>().material.mainTexture = CustomRTC.Instance.t2;
- isVideoGM.SetActive(true);
- isVideoGM1.SetActive(true);
- }
- if (cp.cIdV == "")
- {
- videoGray.SetActive(true);
- videoColor.SetActive(false);
- }
- else
- {
- videoGray.SetActive(false);
- videoColor.SetActive(true);
- }
- 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);
- isAudioGM1.SetActive(false);
- }
- else
- {
- isAudioGM.SetActive(true);
- isAudioGM1.SetActive(true);
- }
-
- Debug.Log("设置图像。。。。");
- // titleTextMesh.text = "用户名:"+cp.name;
- if (cp.cIdA == "")
- {
- audioGray.SetActive(true);
- audioColor.SetActive(false);
- }
- else
- {
- audioGray.SetActive(false);
- audioColor.SetActive(true);
- }
- 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.t2fang;
- }
- CustomRTC.Instance.bigNameID = cp.peerId;
- // CustomRTC.Instance.list.Refresh();
- bigButton.SetActive(false);
- kuang.SetActive(true);
- Debug.Log("改变大图像End");
- }
- public void 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);
- isVideoGM1.SetActive(false);
- }
- else
- {
- closeVideo();
- }
- videoGray.SetActive(false);
- videoColor.SetActive(true);
- }
- else
- {
- audioGray.SetActive(false);
- audioColor.SetActive(true);
- if (cp.isAudio)
- {
- isAudioGM.SetActive(false);
- isAudioGM1.SetActive(false);
- }
- else
- {
- closeAudio();
- }
- }
- }
- private void onChangeTexture()
- {
- if (cp.isVideo)
- {
- Debug.Log("onChangeTexture。。。。");
- MainQuad.GetComponent<MeshRenderer>().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<BigVideoManager>().cp = cp;
- newBigView.GetComponent<BigVideoManager>().init();
- }
- public void OnClick()
- {
- showBigVideo();
- }
- public 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<MeshRenderer>().material.mainTexture = cp.tex;
- // if (cidV != "")
- // SCRtcFactory.Instance.mSCRtcHandle.openRev(cidV);
- // Debug.Log("openVideo2" + cidV);
- isVideoGM.SetActive(false);
- isVideoGM1.SetActive(false);
- cp.isVideo = true;
- if (CustomRTC.Instance.bigNameID == cp.peerId)
- {
- CustomRTC.Instance.bigMr.material.mainTexture = cp.tex;
- //CustomRTC.Instance.showNextTexture();
- }
- }
- }
- public void closeVideo()
- {
- // Debug.Log("VVV");
- if (cp.cIdV != "")
- {
- SCRtcFactory.Instance.mSCRtcHandle.closeRev(cp.cIdV);
- Texture2D oVideo = cp.tex;
- MainQuad.GetComponent<MeshRenderer>().material.mainTexture = CustomRTC.Instance.t2;
- // Debug.Log("NNN");
- cp.isVideo = false;
- isVideoGM.SetActive(true);
- isVideoGM1.SetActive(true);
- if (CustomRTC.Instance.bigNameID == cp.peerId)
- {
- CustomRTC.Instance.bigMr.material.mainTexture = CustomRTC.Instance.t2fang;
- // CustomRTC.Instance.showNextTexture();
- }
- }
- }
- public void openAudio()
- {
- if (cp.cIdA != "")
- {
- cp.isAudio = true;
- SCRtcFactory.Instance.mSCRtcHandle.openRev(cp.cIdA);
- isAudioGM.SetActive(false);
- isAudioGM1.SetActive(false);
- }
- }
- public void closeAudio()
- {
- if (cp.cIdA != "")
- {
- cp.isAudio = false;
- SCRtcFactory.Instance.mSCRtcHandle.closeRev(cp.cIdA);
- isAudioGM.SetActive(true);
- isAudioGM1.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);
- }
- }
- }
|