PeerView.cs 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class PeerView : BaseView
  6. {
  7. public Text tName;
  8. public RawImage mViewTexture;
  9. public Button mainBtn;
  10. public GameObject user;
  11. //public GameObject add;
  12. public SysEnterManager sysEenter;
  13. public CustomPeer cPeer;
  14. //public Button addBtn;
  15. private InviteUserConfig inviteUserConfig;
  16. private float alltime = 30f;
  17. private bool istime = false;
  18. public Texture texture;
  19. public GameObject ChooseKuang;
  20. private void ShowChooseKuang(string id)
  21. {
  22. if (id == cPeer.peerId)
  23. {
  24. ChooseKuang.SetActive(true);
  25. if (ShowUserMsg.Instance)
  26. {
  27. ShowUserMsg.Instance.Init(this.cPeer);
  28. }
  29. }
  30. else
  31. {
  32. ChooseKuang.SetActive(false);
  33. }
  34. }
  35. private void Update()
  36. {
  37. if (istime)
  38. {
  39. alltime -= Time.deltaTime;
  40. if (alltime <= 0)
  41. {
  42. istime = false;
  43. alltime = 30f;
  44. if (this.inviteUserConfig != null)
  45. {
  46. //if (InviteDlg.Instance && InviteDlg.Instance.InvitingUnionIdList.Contains(this.inviteUserConfig))
  47. //{
  48. // PopUpInfo.Instance.showPublic(PopUpInfo.PopType.Tip, this.inviteUserConfig.NickName + "无应答");
  49. // InviteDlg.Instance.InvitingUnionIdList.Remove(this.inviteUserConfig);
  50. // RoomOtherUser.Instance.UpdateList();
  51. //}
  52. }
  53. }
  54. }
  55. else
  56. {
  57. alltime = 30f;
  58. }
  59. }
  60. public override void Init(int i, BaseConfig c, int vi)
  61. {
  62. base.Init(i, c, vi);
  63. mainBtn.onClick.RemoveAllListeners();
  64. mainBtn.onClick.AddListener(setBigView);
  65. if (c is PeerConfig)
  66. {
  67. if (this.inviteUserConfig != null)
  68. {
  69. this.inviteUserConfig = null;
  70. }
  71. user.SetActive(true);
  72. //add.SetActive(false);
  73. sysEenter.gameObject.SetActive(true);
  74. cPeer = (c as PeerConfig).peer;
  75. sysEenter.cPeer = cPeer;
  76. tName.text = cPeer.name;
  77. if (!cPeer.isSn)
  78. {
  79. if (!string.IsNullOrEmpty(cPeer.avater))
  80. {
  81. NetWorkHeaders.Instance.getNetTexture(cPeer.avater, null, (Texture tex) => {
  82. mViewTexture.texture = tex;
  83. });
  84. }
  85. else
  86. {
  87. if (UserInfo.defaulttextIcon != null)
  88. {
  89. mViewTexture.texture = UserInfo.defaulttextIcon;
  90. }
  91. }
  92. }
  93. else
  94. {
  95. NetWorkHeaders.GetUserAvater((aData) =>
  96. {
  97. for (int j = 0; j < aData["data"]["sn"].Count; j++)
  98. {
  99. NetWorkHeaders.Instance.getNetTexture(aData["data"]["sn"][j].ToString(), null, (Texture tex) => {
  100. mViewTexture.texture = tex;
  101. });
  102. }
  103. });
  104. }
  105. cPeer.onChangeInfo -= OnChangeInfo;
  106. cPeer.onChangeInfo += OnChangeInfo;
  107. cPeer.onChangeTexture -= onChangeTexture;
  108. cPeer.onChangeTexture += onChangeTexture;
  109. cPeer.onChangeName -= onChangeName;
  110. cPeer.onChangeName += onChangeName;
  111. RoomOtherUser.ShowAction -= ShowChooseKuang;
  112. RoomOtherUser.ShowAction += ShowChooseKuang;
  113. if (RoomMainForms.userId == RoomMainForms.NOUSER)
  114. {
  115. RoomMainForms.Instance.setBigView(cPeer.tex, cPeer.peerId);
  116. }
  117. alltime = 30f;
  118. istime = false;
  119. }
  120. else if (c is InviteUserConfig)
  121. {
  122. if (cPeer != null)
  123. {
  124. cPeer = null;
  125. }
  126. this.inviteUserConfig = c as InviteUserConfig;
  127. user.SetActive(true);
  128. //add.SetActive(false);
  129. tName.text = "等待进入...";
  130. sysEenter.gameObject.SetActive(false);
  131. if (this.inviteUserConfig != null && !string.IsNullOrEmpty(inviteUserConfig.Avatar))
  132. {
  133. NetWorkHeaders.Instance.getNetTexture(inviteUserConfig.Avatar, null, (Texture tex) => {
  134. mViewTexture.texture = tex;
  135. });
  136. }
  137. else
  138. {
  139. if (UserInfo.defaulttextIcon != null)
  140. {
  141. mViewTexture.texture = UserInfo.defaulttextIcon;
  142. }
  143. }
  144. alltime = 30f;
  145. istime = true;
  146. }
  147. //else
  148. //{
  149. // user.SetActive(false);
  150. // add.SetActive(true);
  151. // alltime = 30f;
  152. // istime = false;
  153. //}
  154. AgoraVideoAudioManager.Instance.listCustomPeer.Add(cPeer);
  155. }
  156. void onChangeTexture()
  157. {
  158. if (RoomMainForms.userId == cPeer.peerId)
  159. {
  160. RoomMainForms.Instance.setBigView(cPeer.tex, cPeer.peerId);
  161. }
  162. }
  163. void onChangeName(string cName)
  164. {
  165. tName.text = cName;
  166. }
  167. public void setBigView()
  168. {
  169. if (cPeer == null)
  170. {
  171. return;
  172. }
  173. RoomMainForms.Instance.setBigView(cPeer.tex, cPeer.peerId);
  174. RoomMainForms.Instance.ClickOnCloseCoordinate();
  175. //RoomOtherUser.ShowAction?.Invoke(cPeer.peerId);
  176. // AgoraVideoAudioManager.Instance.AddListShowView(cPeer.peerId, RoomMainForms.Instance.bigView);
  177. }
  178. private void ClickAdd()
  179. {
  180. //if (ShowRoom.Instance)
  181. //{
  182. // ShowRoom.Instance.window[4].SetActive(true);
  183. // if (InviteDlg.Instance)
  184. // {
  185. // InviteDlg.Instance.ShowHistory();
  186. // }
  187. //}
  188. }
  189. private void OnChangeInfo(string type, string id)
  190. {
  191. if (type == "video")
  192. {
  193. if (cPeer.isVideo)
  194. {
  195. if (cPeer.isCloseVideo)
  196. {
  197. RemoteRtc.Instance.closeRev(cPeer.cIdV);
  198. }
  199. }
  200. if (RoomMainForms.userId == cPeer.peerId)
  201. {
  202. Debug.Log("开启大视频");
  203. RoomMainForms.Instance.setBigView(cPeer.tex, cPeer.peerId);
  204. }
  205. }
  206. else
  207. {
  208. if (cPeer.isAudio)
  209. {
  210. if (cPeer.isCloseAudio)
  211. {
  212. RemoteRtc.Instance.closeRev(cPeer.cIdA);
  213. }
  214. }
  215. }
  216. }
  217. public void OpenVideo()
  218. {
  219. if (cPeer != null && cPeer.isVideo && cPeer.cIdV != "" && cPeer.isCloseVideo)
  220. {
  221. RemoteRtc.Instance.startRev(cPeer.cIdV);
  222. //cPeer.isCloseVideo = false;
  223. }
  224. cPeer.isCloseVideo = false;
  225. AgoraVideoAudioManager.Instance.MuteRemoteVideoStream(cPeer.peerId, false);
  226. }
  227. public void CloseVideo()
  228. {
  229. if (cPeer != null && cPeer.isVideo && cPeer.cIdV != "" && !cPeer.isCloseVideo)
  230. {
  231. RemoteRtc.Instance.closeRev(cPeer.cIdV);
  232. // cPeer.isCloseVideo = true;
  233. }
  234. cPeer.isCloseVideo = true;
  235. AgoraVideoAudioManager.Instance.MuteRemoteVideoStream(cPeer.peerId, true);
  236. }
  237. public void openMic()
  238. {
  239. if (cPeer != null && cPeer.isAudio && cPeer.cIdA != "" && cPeer.isCloseAudio)
  240. {
  241. RemoteRtc.Instance.startRev(cPeer.cIdA);
  242. cPeer.isCloseAudio = false;
  243. }
  244. AgoraVideoAudioManager.Instance.MuteRemoteAudioStream(cPeer.peerId, false);
  245. cPeer.isCloseAudio = false;
  246. }
  247. public void closeMic()
  248. {
  249. if (cPeer != null && cPeer.isAudio && cPeer.cIdA != "" && !cPeer.isCloseAudio)
  250. {
  251. RemoteRtc.Instance.closeRev(cPeer.cIdA);
  252. cPeer.isCloseAudio = true;
  253. }
  254. AgoraVideoAudioManager.Instance.MuteRemoteAudioStream(cPeer.peerId, true);
  255. cPeer.isCloseAudio = true;
  256. }
  257. public void ChangeVideo( bool isVideo)
  258. {
  259. cPeer.isVideo = isVideo;
  260. }
  261. public void ChangeAudio(bool isAudio)
  262. {
  263. cPeer.isAudio = isAudio;
  264. }
  265. }