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