ItemUserView.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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.Util;
  10. using XRTool.WorldUI;
  11. public class ItemUserView : MonoBehaviour
  12. {
  13. public Peer _peer;
  14. public MeshRenderer videoBG;
  15. public Text nametext;
  16. public XRIcon touxiang;
  17. public Button bigBtn;
  18. // Start is called before the first frame update
  19. void Start()
  20. {
  21. bigBtn.onClick.AddListener(OnClickBigBtn);
  22. }
  23. private void OnClickBigBtn()
  24. {
  25. if (ShowViewMgr.Instance)
  26. {
  27. PlayerViewComponent.CreateViewComponent(this._peer.PeerId, ShowViewMgr.Instance.Target);
  28. }
  29. }
  30. private void Update()
  31. {
  32. checkPeer();
  33. StateUpdata();
  34. }
  35. void checkPeer()
  36. {
  37. if (cPeer == null && _peer != null)
  38. {
  39. cPeer = AgoraRTCManager.Instance.GetCustomPeer(_peer.PeerId);
  40. _peer.AgoraCustomPeer = cPeer;
  41. }
  42. }
  43. void StateUpdata()
  44. {
  45. if (cPeer == null)
  46. return;
  47. // Debug.Log(cPeer.peerId + " " + cPeer.isVideo + cPeer.isOpenVideo + cPeer.isAudio + cPeer.isOpenAduio);
  48. if (cPeer.isVideo)
  49. {
  50. if (cPeer.isOpenVideo)
  51. {
  52. openVideo.SetActive(false);
  53. closeVideo.SetActive(false);
  54. pauseVideo.SetActive(true);
  55. }
  56. else
  57. {
  58. openVideo.SetActive(false);
  59. closeVideo.SetActive(true);
  60. pauseVideo.SetActive(false);
  61. }
  62. }
  63. else
  64. {
  65. openVideo.SetActive(true);
  66. closeVideo.SetActive(false);
  67. pauseVideo.SetActive(false);
  68. }
  69. if (cPeer.isAudio)
  70. {
  71. if (cPeer.isOpenAduio)
  72. {
  73. openAudio.SetActive(false);
  74. closeAudio.SetActive(false);
  75. pauseAudio.SetActive(true);
  76. }
  77. else
  78. {
  79. openAudio.SetActive(false);
  80. closeAudio.SetActive(true);
  81. pauseAudio.SetActive(false);
  82. }
  83. }
  84. else
  85. {
  86. openAudio.SetActive(true);
  87. closeAudio.SetActive(false);
  88. pauseAudio.SetActive(false);
  89. }
  90. }
  91. AgoraCustomPeer cPeer;
  92. public void Init(Peer peer)
  93. {
  94. Debug.Log("123213Init213213"+ peer.Avatar);
  95. _peer = peer;
  96. nametext.text = peer.NickName;
  97. textMic.text = "0.02";
  98. VolumnGo.SetActive(false);
  99. if (!string.IsNullOrEmpty(peer.Avatar))
  100. {
  101. for (int i = 0; i < CommonMethod.UserAvatarsList.Count; i++)
  102. {
  103. if (peer.Avatar == CommonMethod.UserAvatarsList[i].Url)
  104. {
  105. string path = "Avatar/" + CommonMethod.UserAvatarsList[i].Id + "Avatar";
  106. touxiang.icon = Resources.Load(path) as Texture2D;
  107. touxiang.AutoSetSprite();
  108. }
  109. }
  110. }
  111. if (_peer.IsSlef)
  112. {
  113. nametext.text = "<color=yellow>" + peer.NickName + "</color>";
  114. openAudio.GetComponent<UnityEngine.UI.Image>().color = new Color(255, 0, 0, 255);
  115. openVideo.GetComponent<UnityEngine.UI.Image>().color = new Color(255, 0, 0, 255);
  116. Invoke("checkAudio", 0.5f);
  117. // Invoke("checkVideo", 1f);
  118. }
  119. }
  120. public GameObject openAudio;
  121. public GameObject closeAudio;
  122. public GameObject VolumnGo;
  123. public float volume = 0.2f;
  124. public Text textMic;
  125. public void addMic()
  126. {
  127. volume += 0.1f;
  128. }
  129. public void redMic()
  130. {
  131. volume -= 0.1f;
  132. }
  133. public GameObject pauseCerAudio;
  134. public GameObject pauseCerVideo;
  135. public GameObject pauseAudio;
  136. public GameObject pauseVideo;
  137. public GameObject openVideo;
  138. public GameObject closeVideo;
  139. public void openMic()
  140. {
  141. if (_peer.IsSlef)
  142. {
  143. AgoraRTCManager.Instance.MuteLocalAudioStream(true);
  144. }
  145. else
  146. {
  147. AgoraRTCManager.Instance.MuteRemoteAudioStream(cPeer.peerId, true);
  148. }
  149. }
  150. public void closeMic()
  151. {
  152. if (_peer.IsSlef)
  153. {
  154. AgoraRTCManager.Instance.MuteLocalAudioStream(false);
  155. }
  156. else
  157. {
  158. AgoraRTCManager.Instance.MuteRemoteAudioStream(cPeer.peerId, false);
  159. }
  160. }
  161. public void OpenVideo()
  162. {
  163. if (_peer.IsSlef)
  164. {
  165. AgoraRTCManager.Instance.MuteLocalVideoStream(true);
  166. }
  167. else
  168. {
  169. AgoraRTCManager.Instance.MuteRemoteVideoStream(cPeer.peerId, true);
  170. }
  171. }
  172. public void CloseVideo()
  173. {
  174. if (_peer.IsSlef)
  175. {
  176. XRRGBCamera.Instance.stopCamera();
  177. AgoraRTCManager.Instance.MuteLocalVideoStream(false);
  178. }
  179. else
  180. {
  181. AgoraRTCManager.Instance.MuteRemoteVideoStream(cPeer.peerId, false);
  182. }
  183. }
  184. }