BigVideoManager.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. public class BigVideoManager : MonoBehaviour
  6. {
  7. public MeshRenderer videoMr;
  8. public MeshRenderer audioMr;
  9. public Material gray;
  10. public Material color;
  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.t2;
  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. videoMr.material = gray;
  39. }
  40. else
  41. {
  42. videoMr.material = color;
  43. }
  44. if (cp.cIdA == "")
  45. {
  46. audioMr.material = gray;
  47. }
  48. else
  49. {
  50. audioMr.material = color;
  51. }
  52. }
  53. public void onChangeCloseInfo()
  54. {
  55. Debug.Log("onChangeInfo。。。。");
  56. if (cp.cIdV == "")
  57. {
  58. if (cp.isVideo)
  59. {
  60. isVideoGM.SetActive(false);
  61. }
  62. else
  63. {
  64. isVideoGM.SetActive(true);
  65. }
  66. mr.material.mainTexture = CustomRTC.Instance.t2;
  67. videoMr.material = gray;
  68. }
  69. else if(cp.cIdA=="")
  70. {
  71. audioMr.material = gray;
  72. if (cp.isAudio)
  73. {
  74. isAudioGM.SetActive(false);
  75. }
  76. else
  77. {
  78. isAudioGM.SetActive(true);
  79. }
  80. }
  81. }
  82. private void onChangeTexture()
  83. {
  84. if (cp.isVideo)
  85. {
  86. mr.material.mainTexture = cp.tex;
  87. }
  88. }
  89. private void onChangeInfo(string type, string id)
  90. {
  91. Debug.Log("onChangeInfo。。。。");
  92. if (type == "video")
  93. {
  94. if (cp.isVideo)
  95. {
  96. isVideoGM.SetActive(false);
  97. }
  98. else
  99. {
  100. isVideoGM.SetActive(true);
  101. }
  102. videoMr.material = color;
  103. }
  104. else
  105. {
  106. audioMr.material = color;
  107. if (cp.isAudio)
  108. {
  109. isAudioGM.SetActive(false);
  110. }
  111. else
  112. {
  113. isAudioGM.SetActive(true);
  114. }
  115. }
  116. }
  117. private void OnDestroy()
  118. {
  119. cp.onChangeTexture -= onChangeTexture;
  120. cp.onChangeInfo -= onChangeInfo;
  121. }
  122. public void close()
  123. {
  124. cp.isBig = false;
  125. CustomRTC.Instance.list.initList(CustomRTC.Instance.cpl);
  126. Destroy(this.gameObject);
  127. }
  128. public void closeRemove()
  129. {
  130. cp.isBig = false;
  131. // CustomRTC.Instance.list.initList(CustomRTC.Instance.cpl);
  132. Destroy(this.gameObject);
  133. }
  134. public void chooseVideo()
  135. {
  136. if (isVideoGM.activeSelf)
  137. {
  138. openVideo();
  139. }
  140. else
  141. {
  142. closeVideo();
  143. }
  144. }
  145. public void chooseAudio()
  146. {
  147. if (isAudioGM.activeSelf)
  148. {
  149. openAudio();
  150. }
  151. else
  152. {
  153. closeAudio();
  154. }
  155. }
  156. public void openVideo()
  157. {
  158. if (cp.cIdV != "")
  159. {
  160. cp.isVideo = true;
  161. SCRtcFactory.Instance.mSCRtcHandle.openRev(cp.cIdV);
  162. mr.material.mainTexture = cp.tex;
  163. // if (cidV != "")
  164. // SCRtcFactory.Instance.mSCRtcHandle.openRev(cidV);
  165. // Debug.Log("openVideo2" + cidV);
  166. isVideoGM.SetActive(false);
  167. if (CustomRTC.Instance.bigNameID == "")
  168. {
  169. CustomRTC.Instance.showNextTexture();
  170. }
  171. }
  172. }
  173. public void closeVideo()
  174. {
  175. if (cp.cIdV != "")
  176. {
  177. cp.isVideo = false;
  178. SCRtcFactory.Instance.mSCRtcHandle.closeRev(cp.cIdV);
  179. Texture2D oVideo = cp.tex;
  180. mr.material.mainTexture = CustomRTC.Instance.t2;
  181. isVideoGM.SetActive(true);
  182. if (CustomRTC.Instance.bigNameID == cp.peerId)
  183. {
  184. CustomRTC.Instance.showNextTexture();
  185. }
  186. }
  187. }
  188. public void openAudio()
  189. {
  190. if (cp.cIdA != "")
  191. {
  192. cp.isAudio = true;
  193. SCRtcFactory.Instance.mSCRtcHandle.openRev(cp.cIdA);
  194. isAudioGM.SetActive(false);
  195. }
  196. }
  197. public void closeAudio()
  198. {
  199. if (cp.cIdA != "")
  200. {
  201. cp.isAudio = false;
  202. SCRtcFactory.Instance.mSCRtcHandle.closeRev(cp.cIdA);
  203. isAudioGM.SetActive(true);
  204. }
  205. }
  206. }