AgoraRTCManager.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. using agora_gaming_rtc;
  2. using SC.XR.Unity;
  3. using ShadowStudio.Model;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using UnityEngine;
  7. using UnityEngine.Rendering;
  8. using UnityEngine.Serialization;
  9. using UnityEngine.UI;
  10. using XRTool.Util;
  11. using static agora_gaming_rtc.ExternalVideoFrame;
  12. public class AgoraRTCManager : SingletonMono<AgoraRTCManager>
  13. {
  14. [Header("_____________Basic Configuration_____________")]
  15. [FormerlySerializedAs("APP_ID")]
  16. [SerializeField]
  17. private string _appID = "";
  18. [FormerlySerializedAs("TOKEN")]
  19. [SerializeField]
  20. private string _token = "";
  21. [FormerlySerializedAs("CHANNEL_NAME")]
  22. [SerializeField]
  23. private string _channelName = "";
  24. private uint uid;
  25. private string peerid;
  26. internal IRtcEngine RtcEngine = null;
  27. private AgoraCustomPeer myPeer;
  28. private Dictionary<string, uint> dicPeeridAndUid;
  29. private List<AgoraCustomPeer> listCustomPeer;
  30. public bool isSwitchCamera;
  31. public uint Uid
  32. {
  33. get { return uid; }
  34. set { uid = value; }
  35. }
  36. public AgoraCustomPeer MyPeer
  37. {
  38. get { return myPeer; }
  39. set { if(value!=null) myPeer = value; }
  40. }
  41. public string ChannelName
  42. {
  43. get { return _channelName; }
  44. set { if (value != null) _channelName = value; }
  45. }
  46. public string PeerId
  47. {
  48. get { return peerid; }
  49. set { if (value != null) peerid = value; }
  50. }
  51. private void Start()
  52. {
  53. LoadAssetData();
  54. //if (_appID.Length > 10)
  55. //{
  56. //}
  57. InitEngine();
  58. dicPeeridAndUid = new Dictionary<string, uint>();
  59. isSwitchCamera = false;
  60. listCustomPeer = new List<AgoraCustomPeer>();
  61. }
  62. private void Update()
  63. {
  64. }
  65. //Show data in AgoraBasicProfile
  66. [ContextMenu("ShowAgoraBasicProfileData")]
  67. private void LoadAssetData()
  68. {
  69. }
  70. private void InitEngine()
  71. {
  72. RtcEngine = IRtcEngine.GetEngine(_token);
  73. RtcEngine.DisableVideo();
  74. }
  75. public void JoinChannel()
  76. {
  77. Debug.Log(" JoinChannel " + _channelName);
  78. RtcEngine.EnableAudio();
  79. if(DeviceType.type!="LeiNiao")
  80. {
  81. RtcEngine.DisableVideo();
  82. }
  83. RtcEngine.SetChannelProfile(CHANNEL_PROFILE.CHANNEL_PROFILE_COMMUNICATION);
  84. RtcEngine.SetClientRole(CLIENT_ROLE_TYPE.CLIENT_ROLE_BROADCASTER);
  85. RtcEngine.JoinChannel(_channelName, "", uid);
  86. RtcEngine.DisableVideo();
  87. RtcEngine.DisableVideoObserver();
  88. StartCoroutine(InitVideoAndAduio(1f));
  89. if (!RTCINIT)
  90. {
  91. RTCINIT = true;
  92. if (DeviceType.type != "LeiNiao")
  93. {
  94. //StartCoroutine(RenderTexturesScreenCapture());
  95. }
  96. }
  97. }
  98. static bool RTCINIT;
  99. Texture2D screenShot;
  100. IEnumerator RenderTexturesScreenCapture()
  101. {
  102. Debug.Log("RenderTexturesScreenCapture����ͼƬ1");
  103. yield return new WaitForEndOfFrame();
  104. if (screenShot == null)
  105. {
  106. screenShot = new Texture2D(1280, 720, TextureFormat.RGBA32, false);
  107. StartCoroutine(GetRenederFPS());
  108. }
  109. while (true)
  110. {
  111. // if (isSendVideo)
  112. // continue;
  113. // img.texture = RemoteRtc.Instance.cam.activeTexture;
  114. // RenderTexture.active = ca.activeTexture;
  115. // screenShot.ReadPixels(new Rect(0, 0, ca.activeTexture.width, ca.activeTexture.height), 0, 0);
  116. // screenShot.Apply();
  117. //Camera.main.targetTexture = null;
  118. // RenderTexture.active = null;
  119. yield return new WaitForSeconds(0.05f);
  120. if (bts != null)
  121. {
  122. // screenShot = HorizontalFlipTexture(screenShot2);
  123. var timetick = System.DateTime.Now.Ticks / 10000;
  124. ExternalVideoFrame externalVideoFrame = new ExternalVideoFrame();
  125. externalVideoFrame.type = VIDEO_BUFFER_TYPE.VIDEO_BUFFER_RAW_DATA;
  126. externalVideoFrame.format = VIDEO_PIXEL_FORMAT.VIDEO_PIXEL_RGBA;
  127. externalVideoFrame.buffer = bts;// screenShot.GetRawTextureData();
  128. externalVideoFrame.stride = (int)screenShot.width;
  129. externalVideoFrame.height = (int)screenShot.height;
  130. externalVideoFrame.rotation = 180;
  131. externalVideoFrame.cropLeft = 1;
  132. externalVideoFrame.cropRight = 1;
  133. externalVideoFrame.timestamp = timetick;
  134. RtcEngine.PushVideoFrame(externalVideoFrame);
  135. // Debug.Log("��������������");
  136. }
  137. }
  138. }
  139. public Camera cam2;
  140. byte[] bts;
  141. IEnumerator GetRenederFPS()
  142. {
  143. while (true)
  144. {
  145. var req = AsyncGPUReadback.Request(cam2.activeTexture);
  146. yield return new WaitUntil(() => req.done);
  147. if (!req.hasError)
  148. {
  149. if (bts == null)
  150. {
  151. bts = new byte[req.layerDataSize];
  152. }
  153. req.GetData<byte>().CopyTo(bts);
  154. // screenShot.LoadRawTextureData(bts);
  155. // screenShot.Apply();
  156. // tex.SetPixels32(req.GetData<Color32>().ToArray());
  157. // img.texture = screenShot;
  158. }
  159. else
  160. {
  161. Debug.LogError("Error AsyncGPUReadbackRequest.hasError");
  162. }
  163. }
  164. }
  165. public void LeaveChannel()
  166. {
  167. Debug.Log("LeaveChannel ");
  168. int msg = RtcEngine.LeaveChannel();
  169. switch (msg)
  170. {
  171. case 0:
  172. Debug.Log( "成功退出频道: " + _channelName);
  173. break;
  174. default:
  175. Debug.Log("退出频道失败: " + msg);
  176. break;
  177. }
  178. }
  179. public void ClearDatas()
  180. {
  181. myPeer = null;
  182. dicPeeridAndUid.Clear();
  183. dicPeeridAndUid = new Dictionary<string, uint>();
  184. listCustomPeer.Clear();
  185. listCustomPeer = new List<AgoraCustomPeer>();
  186. }
  187. private IEnumerator InitVideoAndAduio(float times)
  188. {
  189. yield return new WaitForSeconds(times);
  190. // MuteLocalVideoStream(CustomInfo.isSendVideo);
  191. MuteLocalAudioStream(CustomInfo.isSendAudio);
  192. MyPeer.isAudio = true;
  193. // MyPeer.isVideo = true;
  194. }
  195. public void AddDicPeerData(string peerid, uint uid)
  196. {
  197. if (dicPeeridAndUid.ContainsKey(peerid))
  198. return;
  199. dicPeeridAndUid.Add(peerid, uid);
  200. AgoraCustomPeer peer = new AgoraCustomPeer();
  201. peer.AgoraInit(peerid);
  202. listCustomPeer.Add(peer);
  203. if (peerid == PeerId)
  204. MyPeer = peer;
  205. }
  206. public void RemDicPeerData(string peerid)
  207. {
  208. Debug.Log(" RemAtPeeridUid " + peerid + " " + uid);
  209. dicPeeridAndUid.Remove(peerid);
  210. for (int i = 0; i < listCustomPeer.Count; i++)
  211. {
  212. if (listCustomPeer[i].peerId == peerid)
  213. listCustomPeer.Remove(listCustomPeer[i]);
  214. }
  215. }
  216. public void SetCustomPeerName(string peerid, string name)
  217. {
  218. Debug.Log("SetListCustomPeer " + peerid + " " + name);
  219. for (int i = 0; i < listCustomPeer.Count; i++)
  220. {
  221. if (peerid == listCustomPeer[i].peerId)
  222. {
  223. listCustomPeer[i].SetName(name);
  224. break;
  225. }
  226. }
  227. }
  228. public AgoraCustomPeer GetCustomPeer(string peerid)
  229. {
  230. Debug.Log("GetListCustomPeer " + peerid);
  231. for (int i = 0; i < listCustomPeer.Count; i++)
  232. {
  233. if (listCustomPeer[i].peerId == peerid)
  234. return listCustomPeer[i];
  235. }
  236. return null;
  237. }
  238. public void AgoarRawImageVideoView(string peerId, RawImage rawImage)
  239. {
  240. Debug.Log(" AgoarRawImageVideoView " + peerId);
  241. try
  242. {
  243. if (peerId == CommonMethod.MyPeer.PeerId)
  244. {
  245. rawImage.gameObject.SetActive(true);
  246. rawImage.rectTransform.localEulerAngles = new Vector3(0, 180, 180);
  247. MakeVideoView(0, rawImage);
  248. }
  249. else if (dicPeeridAndUid.ContainsKey(peerId))
  250. {
  251. // list_ShowView.Add(peerId, rawImage);
  252. rawImage.gameObject.SetActive(true);
  253. rawImage.rectTransform.localEulerAngles = new Vector3(0, 0, 180);
  254. MakeVideoView(dicPeeridAndUid[peerId], rawImage, this._channelName);
  255. }
  256. }
  257. catch (System.Exception e)
  258. {
  259. HttpsSendLog.Instance.SendLog("Agora", e.ToString());
  260. }
  261. }
  262. public void MuteLocalAudioStream(bool isAudio)
  263. {
  264. int msg = RtcEngine.MuteLocalAudioStream(!isAudio);
  265. // int msg = RtcEngine.EnableLocalAudio(isAudio);
  266. switch (msg)
  267. {
  268. case 0:
  269. Debug.Log(isAudio ? "打开本地音频成功" : "关闭本地音频成功 ");
  270. MyPeer.isOpenAduio = !isAudio;
  271. break;
  272. default:
  273. Debug.LogError("开关本地音频失败: " + msg);
  274. break;
  275. }
  276. }
  277. public void MuteRemoteAudioStream(string peerid, bool isAudio)
  278. {
  279. Debug.Log(peerid);
  280. if (!dicPeeridAndUid.ContainsKey(peerid))
  281. return;
  282. int msg = RtcEngine.MuteRemoteAudioStream(dicPeeridAndUid[peerid], !isAudio);
  283. switch (msg)
  284. {
  285. case 0:
  286. Debug.Log(isAudio ? "订阅远端音频成功" : "取订远端音频成功 ");
  287. break;
  288. default:
  289. Debug.LogError("开关本地音频失败: " + msg);
  290. break;
  291. }
  292. }
  293. public void MuteLocalVideoStream(bool isVideo)
  294. {
  295. return;
  296. if(isVideo)
  297. {
  298. XRRGBCamera.Instance.playCamera(CustomInfo.mWidth, CustomInfo.mHight);
  299. }
  300. else
  301. {
  302. XRRGBCamera.Instance.stopCamera();
  303. }
  304. int msg = RtcEngine.MuteLocalVideoStream(!isVideo);
  305. //RtcEngine.EnableVideo();
  306. //int msg = RtcEngine.EnableLocalVideo(isVideo);
  307. switch (msg)
  308. {
  309. case 0:
  310. Debug.Log(isVideo ? "打开本地视频成功 " : "关闭本地视频成功 ");
  311. // myPeer.isCloseVideo = !isVideo;
  312. MyPeer.isOpenVideo = !isVideo;
  313. break;
  314. default:
  315. Debug.LogError("开关本地视频失败: " + msg);
  316. break;
  317. }
  318. }
  319. public void MuteRemoteVideoStream(string peerid, bool isVideo)
  320. {
  321. // Debug.Log(peerid);
  322. if (!dicPeeridAndUid.ContainsKey(peerid))
  323. return;
  324. int msg = RtcEngine.MuteRemoteVideoStream(dicPeeridAndUid[peerid], !isVideo);
  325. switch (msg)
  326. {
  327. case 0:
  328. Debug.Log(isVideo ? "订阅远端视频成功" : "取订远端视频成功 ");
  329. break;
  330. default:
  331. Debug.LogError("开关本地音频失败: " + msg);
  332. break;
  333. }
  334. }
  335. public void RemoteVideoStateChanged(uint uid, REMOTE_VIDEO_STATE state, REMOTE_VIDEO_STATE_REASON
  336. reason)
  337. {
  338. Debug.Log(uid + " " + state + " " + reason);
  339. Debug.Log("RemoteVideoStateChanged " + uid);
  340. if (!dicPeeridAndUid.ContainsValue(uid))
  341. return;
  342. for (int i = 0; i < listCustomPeer.Count; i++)
  343. {
  344. if (dicPeeridAndUid[listCustomPeer[i].peerId] == uid)
  345. {
  346. switch (state)
  347. {
  348. case REMOTE_VIDEO_STATE.REMOTE_VIDEO_STATE_STOPPED:
  349. // listCustomPeer[i].isVideo = false;
  350. break;
  351. case REMOTE_VIDEO_STATE.REMOTE_VIDEO_STATE_STARTING:
  352. listCustomPeer[i].isVideo = true;
  353. break;
  354. case REMOTE_VIDEO_STATE.REMOTE_VIDEO_STATE_DECODING:
  355. listCustomPeer[i].isOpenVideo = false;
  356. break;
  357. case REMOTE_VIDEO_STATE.REMOTE_VIDEO_STATE_FROZEN:
  358. break;
  359. case REMOTE_VIDEO_STATE.REMOTE_VIDEO_STATE_FAILED:
  360. // listCustomPeer[i].isVideo = false;
  361. break;
  362. default:
  363. break;
  364. }
  365. switch (reason)
  366. {
  367. case REMOTE_VIDEO_STATE_REASON.REMOTE_VIDEO_STATE_REASON_INTERNAL:
  368. break;
  369. case REMOTE_VIDEO_STATE_REASON.REMOTE_VIDEO_STATE_REASON_NETWORK_CONGESTION://网络阻塞�?
  370. // listCustomPeer[i].isVideo = false;
  371. break;
  372. case REMOTE_VIDEO_STATE_REASON.REMOTE_VIDEO_STATE_REASON_NETWORK_RECOVERY:// 网络恢复正常�?
  373. // listCustomPeer[i].isVideo = true;
  374. break;
  375. case REMOTE_VIDEO_STATE_REASON.REMOTE_VIDEO_STATE_REASON_LOCAL_MUTED://本地用户停止接收远端视频流或本地用户禁用视频模块
  376. listCustomPeer[i].isOpenVideo = true;
  377. break;
  378. case REMOTE_VIDEO_STATE_REASON.REMOTE_VIDEO_STATE_REASON_LOCAL_UNMUTED://本地用户恢复接收远端视频流或本地用户启动视频模块
  379. listCustomPeer[i].isOpenVideo = false;
  380. break;
  381. case REMOTE_VIDEO_STATE_REASON.REMOTE_VIDEO_STATE_REASON_REMOTE_MUTED://远端用户停止发送视频流或远端用户禁用视频模块�?
  382. listCustomPeer[i].isVideo = false;
  383. // CloseAgoraMainImage(listCustomPeer[i].peerId, false);
  384. break;
  385. case REMOTE_VIDEO_STATE_REASON.REMOTE_VIDEO_STATE_REASON_REMOTE_UNMUTED://远端用户恢复发送视频流或远端用户启用视频模块�?
  386. listCustomPeer[i].isVideo = true;
  387. // CloseAgoraMainImage(listCustomPeer[i].peerId, true);
  388. break;
  389. case REMOTE_VIDEO_STATE_REASON.REMOTE_VIDEO_STATE_REASON_REMOTE_OFFLINE: //远端用户离开频道�?
  390. listCustomPeer[i].isVideo = false;
  391. break;
  392. case REMOTE_VIDEO_STATE_REASON.REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK:
  393. break;
  394. case REMOTE_VIDEO_STATE_REASON.REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK_RECOVERY:
  395. break;
  396. default:
  397. break;
  398. }
  399. break;
  400. }
  401. }
  402. }
  403. public void RemoteAudioStateChanged(uint uid, REMOTE_AUDIO_STATE state, REMOTE_AUDIO_STATE_REASON reason)
  404. {
  405. Debug.Log(uid + " " + state + " " + reason);
  406. // Debug.Log("RemoteAudioStateChanged " + uid);
  407. if (!dicPeeridAndUid.ContainsValue(uid))
  408. return;
  409. // Debug.Log("RemoteAudioStateChanged " + 1);
  410. for (int i = 0; i < listCustomPeer.Count; i++)
  411. {
  412. Debug.Log(listCustomPeer[i].peerId);
  413. if (dicPeeridAndUid[listCustomPeer[i].peerId] == uid)
  414. {
  415. // Debug.Log("RemoteAudioStateChanged " + 2);
  416. switch (state)
  417. {
  418. case REMOTE_AUDIO_STATE.REMOTE_AUDIO_STATE_STOPPED:
  419. // listCustomPeer[i].isAudio = false;
  420. break;
  421. case REMOTE_AUDIO_STATE.REMOTE_AUDIO_STATE_STARTING:
  422. listCustomPeer[i].isAudio = true;
  423. break;
  424. case REMOTE_AUDIO_STATE.REMOTE_AUDIO_STATE_DECODING:
  425. listCustomPeer[i].isOpenAduio = false;
  426. break;
  427. case REMOTE_AUDIO_STATE.REMOTE_AUDIO_STATE_FROZEN:
  428. break;
  429. case REMOTE_AUDIO_STATE.REMOTE_AUDIO_STATE_FAILED:
  430. // listCustomPeer[i].isAudio = false;
  431. break;
  432. default:
  433. break;
  434. }
  435. switch (reason)
  436. {
  437. case REMOTE_AUDIO_STATE_REASON.REMOTE_AUDIO_REASON_INTERNAL:
  438. break;
  439. case REMOTE_AUDIO_STATE_REASON.REMOTE_AUDIO_REASON_NETWORK_CONGESTION:
  440. // listCustomPeer[i].isAudio = false;
  441. break;
  442. case REMOTE_AUDIO_STATE_REASON.REMOTE_AUDIO_REASON_NETWORK_RECOVERY:
  443. // listCustomPeer[i].isAudio = true;
  444. break;
  445. case REMOTE_AUDIO_STATE_REASON.REMOTE_AUDIO_REASON_LOCAL_MUTED:
  446. listCustomPeer[i].isOpenAduio = true;
  447. break;
  448. case REMOTE_AUDIO_STATE_REASON.REMOTE_AUDIO_REASON_LOCAL_UNMUTED:
  449. listCustomPeer[i].isOpenAduio = false;
  450. break;
  451. case REMOTE_AUDIO_STATE_REASON.REMOTE_AUDIO_REASON_REMOTE_MUTED:
  452. listCustomPeer[i].isAudio = false;
  453. break;
  454. case REMOTE_AUDIO_STATE_REASON.REMOTE_AUDIO_REASON_REMOTE_UNMUTED:
  455. listCustomPeer[i].isAudio = true;
  456. break;
  457. case REMOTE_AUDIO_STATE_REASON.REMOTE_AUDIO_REASON_REMOTE_OFFLINE:
  458. listCustomPeer[i].isAudio = false;
  459. break;
  460. default:
  461. break;
  462. }
  463. break;
  464. }
  465. }
  466. }
  467. private void OnDestroy()
  468. {
  469. Debug.Log("OnDestroy");
  470. if (RtcEngine == null) return;
  471. RtcEngine.LeaveChannel();
  472. }
  473. internal static void MakeVideoView(uint uid, RawImage rawImage, string channelId = "")
  474. {
  475. Debug.Log("MakeVideoView " + uid);
  476. //var go = GameObject.Find(uid.ToString());
  477. //if (!ReferenceEquals(go, null))
  478. //{
  479. // return; // reuse
  480. //}
  481. // create a GameObject and assign to this new user
  482. // var videoSurface = MakePlaneSurface(uid.ToString());
  483. // configure videoSurface
  484. if (uid == 0)
  485. {
  486. rawImage.transform.localEulerAngles = Vector3.zero;
  487. //videoSurface.SetForUser(uid, channelId);
  488. rawImage.texture = AgoraRTCManager.Instance.cam2.activeTexture;
  489. }
  490. else
  491. {
  492. rawImage.transform.localEulerAngles = new Vector3(-180,180,0);
  493. var videoSurface = MakeImageSurface(rawImage);
  494. if (ReferenceEquals(videoSurface, null)) return;
  495. videoSurface.SetForUser(uid);
  496. videoSurface.SetEnable(true);
  497. }
  498. //videoSurface.OnTextureSizeModify += (int width, int height) =>
  499. //{
  500. // float scale = (float)height / (float)width;
  501. // videoSurface.transform.localScale = new Vector3(-5, 5 * scale, 1);
  502. // Debug.Log("OnTextureSizeModify: " + width + " " + height);
  503. //};
  504. }
  505. internal static void OnUserJoined(uint uid)
  506. {
  507. // _videoSample.Log.UpdateLog(string.Format("OnUserJoined uid: ${0} elapsed: ${1}", uid, elapsed));
  508. // Debug.Log(string.Format("OnUserJoined uid: ${0} elapsed: ${1}", uid, elapsed))
  509. AgoraRTCManager.Instance.RtcEngine.GetUserInfoByUid(uid);
  510. }
  511. internal static void OnRemoteVideoStateChanged(uint uid, REMOTE_VIDEO_STATE state, REMOTE_VIDEO_STATE_REASON
  512. reason)
  513. {
  514. AgoraRTCManager.Instance.RemoteVideoStateChanged(uid, state, reason);
  515. }
  516. internal static void OnRemoteAudioStateChanged(uint uid, REMOTE_AUDIO_STATE state, REMOTE_AUDIO_STATE_REASON reason)
  517. {
  518. AgoraRTCManager.Instance.RemoteAudioStateChanged(uid, state, reason);
  519. }
  520. #region -- Video Render UI Logic ---
  521. // VIDEO TYPE 1: 3D Object
  522. private static VideoSurface MakePlaneSurface(string goName)
  523. {
  524. var go = GameObject.CreatePrimitive(PrimitiveType.Quad);
  525. //for (int i = 0; i < list_UserInfo.Count; i++)
  526. //{
  527. // if (list_UserInfo[i].uid.ToString() == goName)
  528. // {
  529. // string userAccount = list_UserInfo[i].userAccount;
  530. // if (AgoraVideoAudioManager.Instance.list_ShowView.ContainsKey(list_UserInfo[i].userAccount))
  531. // {
  532. // go = AgoraVideoAudioManager.Instance.list_ShowView[list_UserInfo[i].userAccount].gameObject;
  533. // }
  534. // else
  535. // Debug.LogError(" Agora ShowView is NULL ");
  536. // }
  537. //}
  538. if (go == null)
  539. {
  540. go = GameObject.CreatePrimitive(PrimitiveType.Plane);
  541. return null;
  542. }
  543. go.name = goName;
  544. // set up transform
  545. go.transform.Rotate(-90.0f, 0.0f, 0.0f);
  546. var yPos = Random.Range(3.0f, 5.0f);
  547. var xPos = Random.Range(-2.0f, 2.0f);
  548. go.transform.position = Vector3.zero;
  549. go.transform.localScale = new Vector3(0.25f, 0.5f, 0.5f);
  550. // configure videoSurface
  551. var videoSurface = go.AddComponent<VideoSurface>();
  552. return videoSurface;
  553. }
  554. // Video TYPE 2: RawImage
  555. private static VideoSurface MakeImageSurface(RawImage rawImage)
  556. {
  557. var videoSurface = rawImage.gameObject.AddComponent<VideoSurface>();
  558. return videoSurface;
  559. }
  560. #endregion
  561. }