PeerView.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. using LitJson;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. public class PeerView : BaseView
  7. {
  8. public MeshRenderer videoMr;
  9. public MeshRenderer audioMr;
  10. public Material gray;
  11. public Material color;
  12. public GameObject kuang;
  13. public GameObject bigButton;
  14. public GameObject bigView;
  15. public GameObject MainQuad;
  16. public GameObject isVideoGM;
  17. public GameObject isAudioGM;
  18. public override void Init()
  19. {
  20. base.Init();
  21. Debug.Log("初始化");
  22. }
  23. // Start is called before the first frame update
  24. public override void Start()
  25. {
  26. }
  27. CustomPeer cp;
  28. public override void UpdateConfig(BaseConfig config)
  29. {
  30. base.UpdateConfig(config);
  31. if(config!=null)
  32. {
  33. if(cp!=null)
  34. {
  35. cp.onChangeTexture -= onChangeTexture;
  36. cp.onChangeInfo -= onChangeInfo;
  37. cp.onChangeName -= onChangeName;
  38. }
  39. cp = (config as CustomPeer);
  40. cp.onChangeTexture += onChangeTexture;
  41. cp.onChangeInfo += onChangeInfo;
  42. cp.onChangeName += onChangeName;
  43. if (cp.cIdV != null && cp.cIdV != "" && cp.isVideo)
  44. {
  45. MainQuad.GetComponent<MeshRenderer>().material.mainTexture = cp.tex;
  46. isVideoGM.SetActive(false);
  47. }
  48. else
  49. {
  50. MainQuad.GetComponent<MeshRenderer>().material.mainTexture = CustomRTC.Instance.t2;
  51. isVideoGM.SetActive(true);
  52. }
  53. if (cp.cIdV == "")
  54. {
  55. videoMr.material = gray;
  56. }
  57. else
  58. {
  59. videoMr.material = color;
  60. }
  61. if ( CustomRTC.Instance.bigNameID == cp.peerId)
  62. {
  63. kuang.SetActive(true);
  64. bigButton.SetActive(false);
  65. }
  66. else
  67. {
  68. kuang.SetActive(false);
  69. bigButton.SetActive(true);
  70. }
  71. if (cp.cIdA != null && cp.cIdA != "" && cp.isAudio)
  72. isAudioGM.SetActive(false);
  73. else
  74. isAudioGM.SetActive(true);
  75. Debug.Log("设置图像。。。。");
  76. titleTextMesh.text = "用户名:"+cp.name;
  77. if (cp.cIdA == "")
  78. {
  79. audioMr.material = gray;
  80. }
  81. else
  82. {
  83. audioMr.material = color;
  84. }
  85. if(CustomRTC.Instance.bigNameID=="")
  86. {
  87. showBigVideo();
  88. }
  89. }
  90. }
  91. public void showBigVideo()
  92. {
  93. Debug.Log("改变大图像");
  94. if (cp.isVideo && cp.cIdV != "")
  95. {
  96. CustomRTC.Instance.bigMr.material.mainTexture = cp.tex;
  97. }
  98. else
  99. {
  100. CustomRTC.Instance.bigMr.material.mainTexture = CustomRTC.Instance.t2;
  101. }
  102. CustomRTC.Instance.bigNameID = cp.peerId;
  103. CustomRTC.Instance.list.Refresh();
  104. bigButton.SetActive(false);
  105. kuang.SetActive(true);
  106. Debug.Log("改变大图像End");
  107. }
  108. public override void OnDestroy()
  109. {
  110. base.OnDestroy();
  111. if(cp!=null)
  112. {
  113. cp.onChangeTexture -= onChangeTexture;
  114. cp.onChangeInfo -= onChangeInfo;
  115. cp.onChangeName -= onChangeName;
  116. }
  117. }
  118. private void onChangeName(string n)
  119. {
  120. titleTextMesh.text = "用户名:" + cp.name;
  121. }
  122. private void onChangeInfo(string type, string id)
  123. {
  124. Debug.Log("onChangeInfo。。。。");
  125. if (type == "video")
  126. {
  127. if(cp.isVideo)
  128. {
  129. isVideoGM.SetActive(false);
  130. }
  131. videoMr.material = color;
  132. }
  133. else
  134. {
  135. audioMr.material = color;
  136. if (cp.isAudio)
  137. {
  138. isAudioGM.SetActive(false);
  139. }
  140. }
  141. }
  142. private void onChangeTexture()
  143. {
  144. if (cp.isVideo)
  145. {
  146. Debug.Log("onChangeTexture。。。。");
  147. MainQuad.GetComponent<MeshRenderer>().material.mainTexture = cp.tex;
  148. cp.isVideo = true;
  149. if (CustomRTC.Instance.bigNameID == cp.peerId|| CustomRTC.Instance.bigNameID=="")
  150. {
  151. Debug.Log("onChangeTexture2222。。。。");
  152. showBigVideo();
  153. }
  154. }
  155. }
  156. public void showBigView()
  157. {
  158. GameObject newBigView = GameObject.Instantiate(bigView);
  159. newBigView.SetActive(true);
  160. newBigView.GetComponent<BigVideoManager>().cp = cp;
  161. newBigView.GetComponent<BigVideoManager>().init();
  162. }
  163. public override void OnClick()
  164. {
  165. base.OnClick();
  166. showBigVideo();
  167. }
  168. public override void Update()
  169. {
  170. }
  171. public void chooseVideo()
  172. {
  173. if (isVideoGM.activeSelf)
  174. {
  175. openVideo();
  176. }
  177. else
  178. {
  179. closeVideo();
  180. }
  181. }
  182. public void chooseAudio()
  183. {
  184. if (isAudioGM.activeSelf)
  185. {
  186. openAudio();
  187. }
  188. else
  189. {
  190. closeAudio();
  191. }
  192. }
  193. public void openVideo()
  194. {
  195. if (cp.cIdV != "")
  196. {
  197. SCRtcFactory.Instance.mSCRtcHandle.openRev(cp.cIdV);
  198. MainQuad.GetComponent<MeshRenderer>().material.mainTexture = cp.tex;
  199. // if (cidV != "")
  200. // SCRtcFactory.Instance.mSCRtcHandle.openRev(cidV);
  201. // Debug.Log("openVideo2" + cidV);
  202. isVideoGM.SetActive(false);
  203. cp.isVideo = true;
  204. if (CustomRTC.Instance.bigNameID == "")
  205. {
  206. CustomRTC.Instance.showNextTexture();
  207. }
  208. }
  209. }
  210. public void closeVideo()
  211. {
  212. if (cp.cIdV != "")
  213. {
  214. SCRtcFactory.Instance.mSCRtcHandle.closeRev(cp.cIdV);
  215. Texture2D oVideo = cp.tex;
  216. MainQuad.GetComponent<MeshRenderer>().material.mainTexture = CustomRTC.Instance.t2;
  217. cp.isVideo = false;
  218. isVideoGM.SetActive(true);
  219. if (CustomRTC.Instance.bigNameID == cp.peerId)
  220. {
  221. CustomRTC.Instance.showNextTexture();
  222. }
  223. }
  224. }
  225. public void openAudio()
  226. {
  227. if (cp.cIdA != "")
  228. {
  229. cp.isAudio = true;
  230. SCRtcFactory.Instance.mSCRtcHandle.openRev(cp.cIdA);
  231. isAudioGM.SetActive(false);
  232. }
  233. }
  234. public void closeAudio()
  235. {
  236. if (cp.cIdA != "")
  237. {
  238. cp.isAudio = false;
  239. SCRtcFactory.Instance.mSCRtcHandle.closeRev(cp.cIdA);
  240. isAudioGM.SetActive(true);
  241. }
  242. }
  243. double volumeD;
  244. public void setAudioAdd()
  245. {
  246. if (cp.cIdA != "")
  247. {
  248. volumeD += 0.1f;
  249. Debug.Log("setVolumePeer" + volumeD.ToString());
  250. //volume.text = volumeD.ToString();
  251. SCRtcFactory.Instance.mSCRtcHandle.audioPeerChange(cp.cIdA, volumeD);
  252. }
  253. }
  254. public void setAudioRed()
  255. {
  256. if (cp.cIdA != "")
  257. {
  258. volumeD -= 0.1f;
  259. Debug.Log("setVolumePeer" + volumeD.ToString());
  260. // volume.text = volumeD.ToString();
  261. SCRtcFactory.Instance.mSCRtcHandle.audioPeerChange(cp.cIdA, volumeD);
  262. }
  263. }
  264. }