PeerView.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  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 GameObject audioGray;
  9. public GameObject audioColor;
  10. public GameObject videoGray;
  11. public GameObject videoColor;
  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 GameObject isVideoGM1;
  19. public GameObject isAudioGM1;
  20. public void Init()
  21. {
  22. Debug.Log("初始化");
  23. }
  24. // Start is called before the first frame update
  25. public void Start()
  26. {
  27. }
  28. CustomPeer cp;
  29. public void UpdateConfig(BaseConfig config)
  30. {
  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. isVideoGM1.SetActive(false);
  48. }
  49. else
  50. {
  51. MainQuad.GetComponent<MeshRenderer>().material.mainTexture = CustomRTC.Instance.t2;
  52. isVideoGM.SetActive(true);
  53. isVideoGM1.SetActive(true);
  54. }
  55. if (cp.cIdV == "")
  56. {
  57. videoGray.SetActive(true);
  58. videoColor.SetActive(false);
  59. }
  60. else
  61. {
  62. videoGray.SetActive(false);
  63. videoColor.SetActive(true);
  64. }
  65. if ( CustomRTC.Instance.bigNameID == cp.peerId)
  66. {
  67. kuang.SetActive(true);
  68. bigButton.SetActive(false);
  69. }
  70. else
  71. {
  72. kuang.SetActive(false);
  73. bigButton.SetActive(true);
  74. }
  75. if (cp.cIdA != null && cp.cIdA != "" && cp.isAudio)
  76. {
  77. isAudioGM.SetActive(false);
  78. isAudioGM1.SetActive(false);
  79. }
  80. else
  81. {
  82. isAudioGM.SetActive(true);
  83. isAudioGM1.SetActive(true);
  84. }
  85. Debug.Log("设置图像。。。。");
  86. // titleTextMesh.text = "用户名:"+cp.name;
  87. if (cp.cIdA == "")
  88. {
  89. audioGray.SetActive(true);
  90. audioColor.SetActive(false);
  91. }
  92. else
  93. {
  94. audioGray.SetActive(false);
  95. audioColor.SetActive(true);
  96. }
  97. if(CustomRTC.Instance.bigNameID=="")
  98. {
  99. showBigVideo();
  100. }
  101. }
  102. }
  103. public void showBigVideo()
  104. {
  105. Debug.Log("改变大图像");
  106. if (cp.isVideo && cp.cIdV != "")
  107. {
  108. CustomRTC.Instance.bigMr.material.mainTexture = cp.tex;
  109. }
  110. else
  111. {
  112. CustomRTC.Instance.bigMr.material.mainTexture = CustomRTC.Instance.t2fang;
  113. }
  114. CustomRTC.Instance.bigNameID = cp.peerId;
  115. // CustomRTC.Instance.list.Refresh();
  116. bigButton.SetActive(false);
  117. kuang.SetActive(true);
  118. Debug.Log("改变大图像End");
  119. }
  120. public void OnDestroy()
  121. {
  122. if(cp!=null)
  123. {
  124. cp.onChangeTexture -= onChangeTexture;
  125. cp.onChangeInfo -= onChangeInfo;
  126. cp.onChangeName -= onChangeName;
  127. }
  128. }
  129. private void onChangeName(string n)
  130. {
  131. // titleTextMesh.text = "用户名:" + cp.name;
  132. }
  133. private void onChangeInfo(string type, string id)
  134. {
  135. Debug.Log("onChangeInfo。。。。");
  136. if (type == "video")
  137. {
  138. if(cp.isVideo)
  139. {
  140. isVideoGM.SetActive(false);
  141. isVideoGM1.SetActive(false);
  142. }
  143. else
  144. {
  145. closeVideo();
  146. }
  147. videoGray.SetActive(false);
  148. videoColor.SetActive(true);
  149. }
  150. else
  151. {
  152. audioGray.SetActive(false);
  153. audioColor.SetActive(true);
  154. if (cp.isAudio)
  155. {
  156. isAudioGM.SetActive(false);
  157. isAudioGM1.SetActive(false);
  158. }
  159. else
  160. {
  161. closeAudio();
  162. }
  163. }
  164. }
  165. private void onChangeTexture()
  166. {
  167. if (cp.isVideo)
  168. {
  169. Debug.Log("onChangeTexture。。。。");
  170. MainQuad.GetComponent<MeshRenderer>().material.mainTexture = cp.tex;
  171. cp.isVideo = true;
  172. if (CustomRTC.Instance.bigNameID == cp.peerId|| CustomRTC.Instance.bigNameID=="")
  173. {
  174. Debug.Log("onChangeTexture2222。。。。");
  175. showBigVideo();
  176. }
  177. }
  178. }
  179. public void showBigView()
  180. {
  181. GameObject newBigView = GameObject.Instantiate(bigView);
  182. newBigView.SetActive(true);
  183. newBigView.GetComponent<BigVideoManager>().cp = cp;
  184. newBigView.GetComponent<BigVideoManager>().init();
  185. }
  186. public void OnClick()
  187. {
  188. showBigVideo();
  189. }
  190. public void Update()
  191. {
  192. }
  193. public void chooseVideo()
  194. {
  195. if (isVideoGM.activeSelf)
  196. {
  197. openVideo();
  198. }
  199. else
  200. {
  201. closeVideo();
  202. }
  203. }
  204. public void chooseAudio()
  205. {
  206. if (isAudioGM.activeSelf)
  207. {
  208. openAudio();
  209. }
  210. else
  211. {
  212. closeAudio();
  213. }
  214. }
  215. public void openVideo()
  216. {
  217. if (cp.cIdV != "")
  218. {
  219. SCRtcFactory.Instance.mSCRtcHandle.openRev(cp.cIdV);
  220. MainQuad.GetComponent<MeshRenderer>().material.mainTexture = cp.tex;
  221. // if (cidV != "")
  222. // SCRtcFactory.Instance.mSCRtcHandle.openRev(cidV);
  223. // Debug.Log("openVideo2" + cidV);
  224. isVideoGM.SetActive(false);
  225. isVideoGM1.SetActive(false);
  226. cp.isVideo = true;
  227. if (CustomRTC.Instance.bigNameID == cp.peerId)
  228. {
  229. CustomRTC.Instance.bigMr.material.mainTexture = cp.tex;
  230. //CustomRTC.Instance.showNextTexture();
  231. }
  232. }
  233. }
  234. public void closeVideo()
  235. {
  236. // Debug.Log("VVV");
  237. if (cp.cIdV != "")
  238. {
  239. SCRtcFactory.Instance.mSCRtcHandle.closeRev(cp.cIdV);
  240. Texture2D oVideo = cp.tex;
  241. MainQuad.GetComponent<MeshRenderer>().material.mainTexture = CustomRTC.Instance.t2;
  242. // Debug.Log("NNN");
  243. cp.isVideo = false;
  244. isVideoGM.SetActive(true);
  245. isVideoGM1.SetActive(true);
  246. if (CustomRTC.Instance.bigNameID == cp.peerId)
  247. {
  248. CustomRTC.Instance.bigMr.material.mainTexture = CustomRTC.Instance.t2fang;
  249. // CustomRTC.Instance.showNextTexture();
  250. }
  251. }
  252. }
  253. public void openAudio()
  254. {
  255. if (cp.cIdA != "")
  256. {
  257. cp.isAudio = true;
  258. SCRtcFactory.Instance.mSCRtcHandle.openRev(cp.cIdA);
  259. isAudioGM.SetActive(false);
  260. isAudioGM1.SetActive(false);
  261. }
  262. }
  263. public void closeAudio()
  264. {
  265. if (cp.cIdA != "")
  266. {
  267. cp.isAudio = false;
  268. SCRtcFactory.Instance.mSCRtcHandle.closeRev(cp.cIdA);
  269. isAudioGM.SetActive(true);
  270. isAudioGM1.SetActive(true);
  271. }
  272. }
  273. double volumeD;
  274. public void setAudioAdd()
  275. {
  276. if (cp.cIdA != "")
  277. {
  278. volumeD += 0.1f;
  279. Debug.Log("setVolumePeer" + volumeD.ToString());
  280. //volume.text = volumeD.ToString();
  281. SCRtcFactory.Instance.mSCRtcHandle.audioPeerChange(cp.cIdA, volumeD);
  282. }
  283. }
  284. public void setAudioRed()
  285. {
  286. if (cp.cIdA != "")
  287. {
  288. volumeD -= 0.1f;
  289. Debug.Log("setVolumePeer" + volumeD.ToString());
  290. // volume.text = volumeD.ToString();
  291. SCRtcFactory.Instance.mSCRtcHandle.audioPeerChange(cp.cIdA, volumeD);
  292. }
  293. }
  294. }