BigVideoManager.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. public class BigVideoManager : MonoBehaviour
  6. {
  7. public GameObject audioGray;
  8. public GameObject audioColor;
  9. public GameObject videoGray;
  10. public GameObject videoColor;
  11. public TextMesh titleName;
  12. public CustomPeer cp;
  13. public MeshRenderer mr;
  14. public GameObject isVideoGM;
  15. public GameObject isAudioGM;
  16. public void init()
  17. {
  18. cp.isBig = true;
  19. cp.bigView = this.gameObject;
  20. CustomRTC.Instance.list.initList(CustomRTC.Instance.cpl);
  21. cp.onChangeTexture += onChangeTexture;
  22. cp.onChangeInfo += onChangeInfo;
  23. mr.material.mainTexture = cp.tex;
  24. if (cp.cIdV != null && cp.cIdV != ""&& cp.isVideo)
  25. isVideoGM.SetActive(false);
  26. else
  27. {
  28. mr.material.mainTexture = CustomRTC.Instance.t2fang;
  29. isVideoGM.SetActive(true);
  30. }
  31. if (cp.cIdA != null && cp.cIdA != "" && cp.isAudio)
  32. isAudioGM.SetActive(false);
  33. else
  34. isAudioGM.SetActive(true);
  35. titleName.text = "用户名:" + cp.name;
  36. if (cp.cIdV == "")
  37. {
  38. Debug.Log("A");
  39. videoGray.SetActive(true);
  40. videoColor.SetActive(false);
  41. }
  42. else
  43. {
  44. Debug.Log("A1");
  45. videoGray.SetActive(false);
  46. videoColor.SetActive(true);
  47. }
  48. if (cp.cIdA == "")
  49. {
  50. Debug.Log("B");
  51. audioGray.SetActive(true);
  52. audioColor.SetActive(false);
  53. }
  54. else
  55. {
  56. Debug.Log("B1");
  57. audioGray.SetActive(false);
  58. audioColor.SetActive(true);
  59. }
  60. }
  61. public void onChangeCloseInfo()
  62. {
  63. Debug.Log("onChangeInfo。。。。");
  64. if (cp.cIdV == "")
  65. {
  66. if (cp.isVideo)
  67. {
  68. isVideoGM.SetActive(false);
  69. }
  70. else
  71. {
  72. isVideoGM.SetActive(true);
  73. }
  74. mr.material.mainTexture = CustomRTC.Instance.t2fang;
  75. Debug.Log("A11");
  76. videoGray.SetActive(true);
  77. videoColor.SetActive(false);
  78. }
  79. if(cp.cIdA=="")
  80. {
  81. if (cp.isAudio)
  82. {
  83. isAudioGM.SetActive(false);
  84. }
  85. else
  86. {
  87. isAudioGM.SetActive(true);
  88. }
  89. Debug.Log("B11");
  90. audioGray.SetActive(true);
  91. audioColor.SetActive(false);
  92. }
  93. }
  94. private void onChangeTexture()
  95. {
  96. if (cp.isVideo)
  97. {
  98. mr.material.mainTexture = cp.tex;
  99. }
  100. }
  101. private void onChangeInfo(string type, string id)
  102. {
  103. Debug.Log("onChangeInfo。。。。");
  104. if (type == "video")
  105. {
  106. if (cp.isVideo)
  107. {
  108. isVideoGM.SetActive(false);
  109. }
  110. else
  111. {
  112. closeVideo();
  113. //isVideoGM.SetActive(true);
  114. }
  115. videoGray.SetActive(false);
  116. videoColor.SetActive(true);
  117. Debug.Log("A111");
  118. }
  119. else
  120. {
  121. if (cp.isAudio)
  122. {
  123. isAudioGM.SetActive(false);
  124. }
  125. else
  126. {
  127. closeAudio();
  128. //isAudioGM.SetActive(true);
  129. }
  130. Debug.Log("B111");
  131. audioGray.SetActive(false);
  132. audioColor.SetActive(true);
  133. }
  134. }
  135. private void OnDestroy()
  136. {
  137. cp.onChangeTexture -= onChangeTexture;
  138. cp.onChangeInfo -= onChangeInfo;
  139. }
  140. public void close()
  141. {
  142. cp.isBig = false;
  143. CustomRTC.Instance.list.initList(CustomRTC.Instance.cpl);
  144. Destroy(this.gameObject);
  145. }
  146. public void closeRemove()
  147. {
  148. cp.isBig = false;
  149. // CustomRTC.Instance.list.initList(CustomRTC.Instance.cpl);
  150. Destroy(this.gameObject);
  151. }
  152. public void chooseVideo()
  153. {
  154. if (isVideoGM.activeSelf)
  155. {
  156. openVideo();
  157. }
  158. else
  159. {
  160. closeVideo();
  161. }
  162. }
  163. public void chooseAudio()
  164. {
  165. if (isAudioGM.activeSelf)
  166. {
  167. openAudio();
  168. }
  169. else
  170. {
  171. closeAudio();
  172. }
  173. }
  174. public void openVideo()
  175. {
  176. if (cp.cIdV != "")
  177. {
  178. cp.isVideo = true;
  179. SCRtcFactory.Instance.mSCRtcHandle.openRev(cp.cIdV);
  180. mr.material.mainTexture = cp.tex;
  181. // if (cidV != "")
  182. // SCRtcFactory.Instance.mSCRtcHandle.openRev(cidV);
  183. // Debug.Log("openVideo2" + cidV);
  184. isVideoGM.SetActive(false);
  185. if (CustomRTC.Instance.bigNameID == "")
  186. {
  187. CustomRTC.Instance.showNextTexture();
  188. }
  189. }
  190. }
  191. public void closeVideo()
  192. {
  193. if (cp.cIdV != "")
  194. {
  195. cp.isVideo = false;
  196. SCRtcFactory.Instance.mSCRtcHandle.closeRev(cp.cIdV);
  197. Texture2D oVideo = cp.tex;
  198. mr.material.mainTexture = CustomRTC.Instance.t2fang;
  199. isVideoGM.SetActive(true);
  200. if (CustomRTC.Instance.bigNameID == cp.peerId)
  201. {
  202. CustomRTC.Instance.showNextTexture();
  203. }
  204. }
  205. }
  206. public void openAudio()
  207. {
  208. if (cp.cIdA != "")
  209. {
  210. cp.isAudio = true;
  211. SCRtcFactory.Instance.mSCRtcHandle.openRev(cp.cIdA);
  212. isAudioGM.SetActive(false);
  213. }
  214. }
  215. public void closeAudio()
  216. {
  217. if (cp.cIdA != "")
  218. {
  219. cp.isAudio = false;
  220. SCRtcFactory.Instance.mSCRtcHandle.closeRev(cp.cIdA);
  221. isAudioGM.SetActive(true);
  222. }
  223. }
  224. }