ItemUserView.cs 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. using ShadowStudio.Mgr;
  2. using ShadowStudio.Model;
  3. using ShadowStudio.UI;
  4. using System;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using UnityEngine;
  8. using UnityEngine.UI;
  9. using XRTool.WorldUI;
  10. public class ItemUserView : MonoBehaviour
  11. {
  12. public Peer _peer;
  13. public MeshRenderer videoBG;
  14. public Text nametext;
  15. public XRIcon touxiang;
  16. public Button bigBtn;
  17. // Start is called before the first frame update
  18. void Start()
  19. {
  20. bigBtn.onClick.AddListener(OnClickBigBtn);
  21. }
  22. private void OnClickBigBtn()
  23. {
  24. }
  25. private void Update()
  26. {
  27. checkPeer();
  28. if(videoBG.gameObject.activeSelf&& cPeer!=null&&!_peer.IsSlef)
  29. {
  30. videoBG.material.mainTexture = cPeer.tex;
  31. }
  32. }
  33. void checkPeer()
  34. {
  35. if (cPeer == null&& SCRtcFactory.Instance!=null&& SCRtcFactory.Instance.mSCRtcPeers!=null&& _peer!=null)
  36. {
  37. cPeer = (CustomPeer)SCRtcFactory.Instance.mSCRtcPeers.getPeerName(_peer.PeerId);
  38. _peer.CustomPeer = cPeer;
  39. if (cPeer != null)
  40. {
  41. cPeer.onChangeInfo -= OnChangeInfo;
  42. cPeer.onChangeInfo += OnChangeInfo;
  43. if (!_peer.IsSlef)
  44. {
  45. if (cPeer.isAudio && cPeer.cIdA != "")
  46. {
  47. openAudioEffect();
  48. }
  49. else
  50. {
  51. closeAudioEffect();
  52. }
  53. if (cPeer.isVideo&& cPeer.cIdV!="")
  54. {
  55. openVideoEffect();
  56. }
  57. else
  58. {
  59. closeVideoEffect();
  60. }
  61. }
  62. }
  63. }
  64. }
  65. CustomPeer cPeer;
  66. public void Init(Peer peer)
  67. {
  68. _peer = peer;
  69. nametext.text = peer.NickName;
  70. textMic.text = "0.02";
  71. VolumnGo.SetActive(false);
  72. if (_peer.IsSlef)
  73. {
  74. nametext.text = "<color=yellow>" + peer.NickName + "</color>";
  75. openAudio.GetComponent<UnityEngine.UI.Image>().color = new Color(255, 0, 0, 255);
  76. openVideo.GetComponent<UnityEngine.UI.Image>().color = new Color(255, 0, 0, 255);
  77. }
  78. if (RemoteRtc.Instance.me!=null&& RemoteRtc.Instance.me.cIdA != "")
  79. {
  80. openAudioEffect();
  81. }
  82. closeVideoEffect();
  83. }
  84. private void OnEnable()
  85. {
  86. if(_peer!=null&&_peer.IsSlef)
  87. {
  88. if (RemoteRtc.Instance != null && RemoteRtc.Instance.me != null && RemoteRtc.Instance.me.cIdA != "")
  89. {
  90. openAudioEffect();
  91. }
  92. else
  93. {
  94. closeAudioEffect();
  95. }
  96. if (RemoteRtc.Instance != null && RemoteRtc.Instance.me != null && RemoteRtc.Instance.me.cIdV != "")
  97. {
  98. openVideoEffect();
  99. }
  100. else
  101. {
  102. closeAudioEffect();
  103. }
  104. }
  105. }
  106. private void closeAudioEffect()
  107. {
  108. pauseCerAudio.SetActive(true);
  109. pauseAudio.SetActive(false);
  110. openAudio.SetActive(true);
  111. closeAudio.SetActive(false);
  112. VolumnGo.SetActive(false);
  113. }
  114. private void openAudioEffect()
  115. {
  116. openAudio.SetActive(false);
  117. closeAudio.SetActive(true);
  118. VolumnGo.SetActive(true);
  119. if (cPeer != null)
  120. {
  121. volume = cPeer.volumn;
  122. if (cPeer.isCloseAudio)
  123. {
  124. pauseCerAudio.SetActive(false);
  125. pauseAudio.SetActive(true);
  126. }
  127. }
  128. textMic.text = volume.ToString("F2");
  129. }
  130. private void OnChangeInfo(string type, string id)
  131. {
  132. if (type == "video")
  133. {
  134. if (cPeer.isVideo)
  135. {
  136. openVideoEffect();
  137. if (cPeer.isCloseVideo)
  138. {
  139. RemoteRtc.Instance.closeRev(cPeer.cIdV);
  140. }
  141. }
  142. else
  143. {
  144. closeVideoEffect();
  145. }
  146. }
  147. else
  148. {
  149. if (cPeer.isAudio)
  150. {
  151. openAudioEffect();
  152. if (cPeer.isCloseAudio)
  153. {
  154. RemoteRtc.Instance.closeRev(cPeer.cIdA);
  155. }
  156. }
  157. else
  158. {
  159. closeAudioEffect();
  160. }
  161. }
  162. }
  163. public GameObject openAudio;
  164. public GameObject closeAudio;
  165. public GameObject VolumnGo;
  166. public void openMic()
  167. {
  168. if (_peer.IsSlef)
  169. {
  170. RemoteRtc.Instance.sendMic(true);
  171. volume = RemoteRtc.Instance.me.volumn;
  172. openAudioEffect();
  173. }
  174. else
  175. {
  176. if (cPeer != null&&cPeer.isAudio&& cPeer.cIdA!=""&&cPeer.isCloseAudio)
  177. {
  178. pauseCerAudio.SetActive(true);
  179. pauseAudio.SetActive(false);
  180. RemoteRtc.Instance.startRev(cPeer.cIdA);
  181. cPeer.isCloseAudio = false;
  182. // cPeer.setInfo("audio", cPeer.cIdA,true);
  183. }
  184. }
  185. }
  186. public float volume = 0.2f;
  187. public Text textMic;
  188. public void addMic()
  189. {
  190. volume += 0.1f;
  191. if (_peer.IsSlef)
  192. {
  193. RemoteRtc.Instance.setVolume(volume);
  194. }
  195. else
  196. {
  197. if (cPeer != null&& cPeer.cIdA!="")
  198. {
  199. RemoteRtc.Instance.setVolume(cPeer.cIdA,volume);
  200. }
  201. }
  202. textMic.text = volume.ToString("F2");
  203. }
  204. public void redMic()
  205. {
  206. volume -= 0.1f;
  207. if (_peer.IsSlef)
  208. {
  209. RemoteRtc.Instance.setVolume(volume);
  210. }
  211. else
  212. {
  213. if (cPeer != null && cPeer.cIdA != "")
  214. {
  215. RemoteRtc.Instance.setVolume(cPeer.cIdA, volume);
  216. }
  217. }
  218. textMic.text = volume.ToString("F2");
  219. }
  220. public void closeMic()
  221. {
  222. if (_peer.IsSlef)
  223. {
  224. if(RemoteRtc.Instance.me.cIdA!="")
  225. {
  226. WSHandler.Rtc.closeProducer(RemoteRtc.Instance.me.cIdA);
  227. RemoteRtc.Instance.sendMic(false);
  228. closeAudioEffect();
  229. }
  230. }
  231. else
  232. {
  233. if (cPeer != null && cPeer.isAudio && cPeer.cIdA != "" && !cPeer.isCloseAudio)
  234. {
  235. pauseCerAudio.SetActive(false);
  236. pauseAudio.SetActive(true);
  237. RemoteRtc.Instance.closeRev(cPeer.cIdA);
  238. cPeer.isCloseAudio = true;
  239. // cPeer.setInfo("audio", cPeer.cIdA, false);
  240. }
  241. }
  242. }
  243. public GameObject pauseCerAudio;
  244. public GameObject pauseCerVideo;
  245. public GameObject pauseAudio;
  246. public GameObject pauseVideo;
  247. public GameObject openVideo;
  248. public GameObject closeVideo;
  249. public void OpenVideo()
  250. {
  251. if (_peer.IsSlef)
  252. {
  253. RemoteRtc.Instance.startCamera();
  254. videoBG.gameObject.SetActive(true);
  255. videoBG.material.mainTexture = RemoteRtc.Instance.rt;
  256. RemoteRtc.Instance.sendVideo(true);
  257. openVideoEffect();
  258. }
  259. else
  260. {
  261. if (cPeer != null && cPeer.isVideo && cPeer.cIdV != "" && cPeer.isCloseVideo)
  262. {
  263. pauseCerVideo.SetActive(true);
  264. pauseVideo.SetActive(false);
  265. RemoteRtc.Instance.startRev(cPeer.cIdV);
  266. cPeer.isCloseVideo = false;
  267. // cPeer.setInfo("audio", cPeer.cIdA,true);
  268. }
  269. }
  270. }
  271. public void CloseVideo()
  272. {
  273. if (_peer.IsSlef)
  274. {
  275. if (RemoteRtc.Instance.me.cIdV != "")
  276. {
  277. WSHandler.Rtc.closeProducer(RemoteRtc.Instance.me.cIdV);
  278. RemoteRtc.Instance.stopCamera();
  279. RemoteRtc.Instance.sendVideo(false);
  280. closeVideoEffect();
  281. }
  282. }
  283. else
  284. {
  285. if (cPeer != null && cPeer.isVideo && cPeer.cIdV != "" && !cPeer.isCloseVideo)
  286. {
  287. pauseCerVideo.SetActive(false);
  288. pauseVideo.SetActive(true);
  289. RemoteRtc.Instance.closeRev(cPeer.cIdV);
  290. cPeer.isCloseVideo = true;
  291. // cPeer.setInfo("audio", cPeer.cIdA,true);
  292. }
  293. }
  294. }
  295. private void closeVideoEffect()
  296. {
  297. openVideo.SetActive(true);
  298. closeVideo.SetActive(false);
  299. videoBG.gameObject.SetActive(false);
  300. if (cPeer != null)
  301. {
  302. pauseCerVideo.SetActive(true);
  303. pauseVideo.SetActive(false);
  304. }
  305. }
  306. private void openVideoEffect()
  307. {
  308. openVideo.SetActive(false);
  309. closeVideo.SetActive(true);
  310. if (cPeer != null)
  311. {
  312. videoBG.gameObject.SetActive(true);
  313. if (cPeer.isCloseVideo)
  314. {
  315. pauseCerVideo.SetActive(false);
  316. pauseVideo.SetActive(true);
  317. }
  318. }
  319. }
  320. }