ScreenLocate.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. #define ENABLE_LOG
  2. using Serenegiant.UVC;
  3. using System;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. using UnityEngine.UI;
  7. using ZIM;
  8. using static Serenegiant.UVC.UVCManager;
  9. using Color = UnityEngine.Color;
  10. using InfraredManager;
  11. [RequireComponent(typeof(Canvas))]
  12. public partial class ScreenLocate : MonoBehaviour
  13. {
  14. public InfraredCameraHelper InfraredCameraHelper;
  15. private const string TAG = "ScreenLocate#";
  16. enum Mode
  17. {
  18. InfraredLocate,
  19. ScreenMap,
  20. ScreenLocateManual
  21. }
  22. enum InfraredCount
  23. {
  24. Single,
  25. Double
  26. }
  27. enum Platform
  28. {
  29. Window,
  30. Android
  31. }
  32. Platform mPlatform = Platform.Android;
  33. // 2个灯,顺序根据红外灯的大小 由大到小, 坐标通过 InfraredSpot.ScreenUV 和 InfraredSpot.CameraLocation 获得
  34. public InfraredSpot[] InfraredSpots
  35. {
  36. get
  37. {
  38. infraredCount = InfraredCount.Double;
  39. return infraredSpotBuffer;
  40. }
  41. }
  42. // 1个灯, 坐标通过 InfraredSpot.ScreenUV 和 InfraredSpot.CameraLocation 获得
  43. public InfraredSpot InfraredSpotSingle
  44. {
  45. get
  46. {
  47. infraredCount = InfraredCount.Single;
  48. return infraredSpotBuffer[0];
  49. }
  50. }
  51. public InfraredSpot[] infraredSpotBuffer;
  52. InfraredCount infraredCount;
  53. public string GetInfraredCount() { return infraredCount.ToString(); }
  54. #region UVC 处理的对象
  55. public UVCManager mUVCManager;
  56. public UVCDrawer mUVCDrawer;
  57. public CameraInfo mUVCCameraInfo;
  58. private Texture mUVCTexture;
  59. private Texture2D mUVCTexture2D;
  60. #endregion
  61. public Text Info;
  62. public List<RectTransform> CrosshairInCamera;
  63. public List<RectTransform> CrosshairInScreen;
  64. public RectTransform ScreenQuad;
  65. public Toggle SaveToggle;
  66. public bool ShowScreenQuad = false;
  67. public RawImage rawImage;
  68. public RawImage rawImage1;
  69. public RawImage rawImage2;
  70. public RawImage rawImage3;
  71. public RawImage rawImage4;
  72. public RawImage rawImage5;
  73. public RawImage FullScreenImage;
  74. public InfraredSpotSettings InfraredSpotSettings;
  75. public Texture2D DebugScreenImage;
  76. public bool bSinglePoint = true;//默认单点识别
  77. bool bIdentifyRed = true;//默认设备红色
  78. bool bIdentifyGreen = true;
  79. #region 性能检测相关
  80. public Text m_UITime;
  81. const float m_UIUpdateInterval = 0.1f;
  82. float m_UIUpdateTimer = 0.0f;
  83. List<float> m_History = new List<float>(100);
  84. int m_ValidHistoryFrames = 0;
  85. float m_AverageTime = float.NaN;
  86. float m_MedianTime = float.NaN;
  87. float m_MinTime = float.NaN;
  88. float m_MaxTime = float.NaN;
  89. public float updateInterval = 0.5F;
  90. private double lastInterval;
  91. private int frames = 0;
  92. private float fps;
  93. public Text m_FPS;
  94. #endregion
  95. InfraredLocate infraredLocate;
  96. Mode mode;
  97. //o0.Project.WebCam o0WebCam = null;
  98. public o0.Project.ScreenIdentification screenIdentification;
  99. static public ScreenLocate Main;
  100. static public List<RawImage> DebugImage = new List<RawImage>();
  101. static public RectTransform BackQuad = null;
  102. static public void DebugTexture(int index, Texture texture)
  103. {
  104. Destroy(DebugImage[index].texture);
  105. DebugImage[index].texture = texture;
  106. }
  107. static public void SetScreen(UnityEngine.Color? color = null)
  108. {
  109. if (BackQuad == null)
  110. {
  111. var canvas = GameObject.Find("WebCameraView").GetComponent<RectTransform>();
  112. var background = canvas.Find("Background");
  113. BackQuad = background.GetChild(0).GetComponent<RectTransform>();
  114. }
  115. BackQuad.parent.gameObject.SetActive(color != null);
  116. BackQuad.GetComponent<RawImage>().color = color ?? Color.black;
  117. }
  118. static public void SetScreen(Rect rect, UnityEngine.Color? color = null)
  119. {
  120. if (BackQuad == null)
  121. {
  122. var canvas = GameObject.Find("WebCameraView").GetComponent<RectTransform>();
  123. var background = canvas.Find("Background");
  124. BackQuad = background.GetChild(0).GetComponent<RectTransform>();
  125. }
  126. BackQuad.parent.gameObject.SetActive(color != null);
  127. BackQuad.anchorMin = rect.min;
  128. BackQuad.anchorMax = rect.max;
  129. BackQuad.GetComponent<RawImage>().color = color ?? Color.black;
  130. }
  131. static void DebugBackQuad(Rect? rect = null)
  132. {
  133. if (BackQuad)
  134. {
  135. BackQuad.parent.GetComponent<RawImage>().enabled = false;
  136. BackQuad.GetComponent<RawImage>().color = Color.white;
  137. BackQuad.parent.gameObject.SetActive(!BackQuad.parent.gameObject.activeSelf);
  138. if (rect.HasValue)
  139. {
  140. BackQuad.anchorMin = rect.Value.min;
  141. BackQuad.anchorMax = rect.Value.max;
  142. }
  143. }
  144. }
  145. void Awake()
  146. {
  147. Main = this;
  148. if (mUVCDrawer)
  149. mUVCDrawer.StartPreviewAction += UVCIsReady;
  150. }
  151. void OnDestroy()
  152. {
  153. if (mUVCDrawer)
  154. mUVCDrawer.StartPreviewAction -= UVCIsReady;
  155. }
  156. void Start()
  157. {
  158. DebugImage.Add(rawImage);
  159. DebugImage.Add(rawImage1);
  160. DebugImage.Add(rawImage2);
  161. DebugImage.Add(rawImage3);
  162. DebugImage.Add(rawImage4);
  163. DebugImage.Add(rawImage5);
  164. DebugImage.Add(FullScreenImage);
  165. mode = Mode.InfraredLocate;
  166. infraredCount = InfraredCount.Single;
  167. #region 性能检测相关
  168. for (var i = 0; i < m_History.Capacity; ++i)
  169. {
  170. m_History.Add(0.0f);
  171. }
  172. lastInterval = Time.realtimeSinceStartup;
  173. frames = 0;
  174. #endregion
  175. }
  176. //ZIMWebCamera场景使用
  177. public void WebCamIsReady(Texture texture)
  178. {
  179. mPlatform = Platform.Window;
  180. mUVCTexture = texture;
  181. mUVCCameraInfo = new CameraInfo(mUVCTexture);
  182. }
  183. //手机端UVCCamra使用
  184. public void UVCIsReady(Texture texture)
  185. {
  186. mPlatform = Platform.Android;
  187. //this.startUVCBtn.interactable = true;
  188. mUVCTexture = texture;
  189. //ARGB32
  190. //mUVCTexture2D = Texture2D.CreateExternalTexture(texture.width, texture.height, TextureFormat.ARGB32, false, true, texture.GetNativeTexturePtr()); //TextureToTexture2D(texture);
  191. //Debug.Log("mUVCTexture2D isReable:" + mUVCTexture2D.isReadable);
  192. //Debug.Log("mUVCTexture2D mipmapCount:" + (mUVCTexture2D.mipmapCount > 1));
  193. List<CameraInfo> cameraInfos = mUVCManager.GetAttachedDevices();
  194. mUVCCameraInfo = cameraInfos[cameraInfos.Count - 1];
  195. }
  196. void Update()
  197. {
  198. ++frames;
  199. float timeNow = Time.realtimeSinceStartup;
  200. if (timeNow > lastInterval + updateInterval)
  201. {
  202. fps = (float)(frames / (timeNow - lastInterval));
  203. frames = 0;
  204. lastInterval = timeNow;
  205. }
  206. if (m_FPS != null)
  207. m_FPS.text = "FPS:" + fps.ToString("f2");
  208. if (mUVCCameraInfo == null) return;
  209. if (screenIdentification == null)
  210. screenIdentification = new o0.Project.ScreenIdentification(mUVCTexture);
  211. if (infraredLocate == null)
  212. infraredLocate = new InfraredLocate(mUVCCameraInfo, screenIdentification, InfraredSpotSettings);
  213. if (mode == Mode.ScreenLocateManual)
  214. {
  215. //if (Input.GetMouseButtonDown(0))
  216. //{
  217. // var mouse = Input.mousePosition;
  218. // var u = mouse.x / Screen.width;
  219. // var v = mouse.y / Screen.height;
  220. // u = Math.Clamp(u, 0, 1);
  221. // v = Math.Clamp(v, 0, 1);
  222. // pointManual.Add(new Vector2(u * mUVCTexture.width, v * mUVCTexture.height));
  223. // var obj = Instantiate(Resources.Load("Point")) as GameObject;
  224. // obj.transform.SetParent(FullScreenImage.transform);
  225. // obj.transform.localPosition = new Vector2(u, v).pixelToLocalPosition_AnchorCenter(new Vector2(1, 1), FullScreenImage.rectTransform.rect);
  226. // if (pointManual.Count == 1)
  227. // Info.text = "左键单击屏幕 右下角";
  228. // else if (pointManual.Count == 2)
  229. // Info.text = "左键单击屏幕 右上角";
  230. // else if (pointManual.Count == 3)
  231. // Info.text = "左键单击屏幕 左上角";
  232. // else if (pointManual.Count == 4)
  233. // {
  234. // screenIdentification.LocateScreenManual(new OrdinalQuadrilateral(pointManual[0].o0Vector(), pointManual[1].o0Vector(), pointManual[3].o0Vector(), pointManual[2].o0Vector()));
  235. // pointManual.Clear();
  236. // ShowScreen(screenIdentification.Screen.Quad);
  237. // foreach (Transform i in FullScreenImage.transform)
  238. // Destroy(i.gameObject);
  239. // ToMode(Mode.InfraredLocate);
  240. // }
  241. //}
  242. return;
  243. }
  244. var t0 = Time.realtimeSinceStartup;
  245. /* New*/
  246. if (mUVCCameraInfo != null && mUVCCameraInfo.IsPreviewing && screenIdentification.Screen.Active) // 成功定位屏幕后才做红外识别
  247. {
  248. CreateUVCTexture2DIfNeeded();
  249. if (!screenIdentification.Update(mUVCTexture2D))
  250. {
  251. if (mode == Mode.InfraredLocate)
  252. {
  253. //0,0, cameraTexture2D.width, cameraTexture2D.height,0
  254. var pixels = mUVCTexture2D.GetPixels(); // 从左往右、从下往上
  255. //InfraredSpots = infraredLocate.Update(pixels);
  256. if (bSinglePoint)
  257. infraredSpotBuffer = infraredLocate.UpdateSingle(pixels);
  258. else
  259. infraredSpotBuffer = infraredLocate.Update(pixels);
  260. if (mPlatform == Platform.Window) //渲染ui上面的点。进入游戏可以隐藏
  261. {
  262. for (int i = 0; i < infraredSpotBuffer.Length; i++)
  263. {
  264. if (infraredSpotBuffer[i].CameraLocation != null)
  265. {
  266. // 检测到光点
  267. var posInCanvas = infraredSpotBuffer[i].CameraLocation.Value.pixelToLocalPosition_AnchorCenter(mUVCCameraInfo.Size, rawImage.rectTransform.rect);
  268. CrosshairInCamera[i].gameObject.SetActive(true);
  269. CrosshairInCamera[i].anchoredPosition = posInCanvas;
  270. }
  271. else
  272. CrosshairInCamera[i].gameObject.SetActive(false);
  273. }
  274. }
  275. //手机端使用
  276. if (mPlatform == Platform.Android && infraredSpotBuffer.Length > 0)
  277. {
  278. int redIndex = 0;
  279. int greenIndex = 1;
  280. //仅仅第一个点显示(如果最大点出界了会闪烁)
  281. if (bSinglePoint)
  282. {
  283. redIndex = 0; //单点识别是,可以选择切换颜色
  284. if (infraredSpotBuffer[redIndex].ScreenUV != null)
  285. {
  286. string str = "Single:";
  287. Info.text = str + infraredSpotBuffer[redIndex].ScreenUV.Value.ToString("F4");
  288. //InfraredManager.ConnetDevicesSingle.ins.posAction?.Invoke(new Vector3(infraredSpotBuffer[redIndex].ScreenUV.Value.x * Screen.width, infraredSpotBuffer[redIndex].ScreenUV.Value.y * Screen.height, 0));
  289. onFilterPos(infraredSpotBuffer[redIndex].ScreenUV.Value);
  290. }
  291. }
  292. else
  293. {
  294. //雙點模式下選擇第一個點
  295. if (bIdentifyRed && !bIdentifyGreen)
  296. {
  297. if (infraredSpotBuffer[redIndex].ScreenUV != null)
  298. {
  299. Info.text = "Red" + redIndex + ":" + infraredSpotBuffer[redIndex].ScreenUV.Value.ToString("F4");
  300. //InfraredManager.ConnetDevicesSingle.ins.posAction?.Invoke(new Vector3(infraredSpotBuffer[redIndex].ScreenUV.Value.x * Screen.width, infraredSpotBuffer[redIndex].ScreenUV.Value.y * Screen.height, 0));
  301. onFilterPos2(infraredSpotBuffer[redIndex].ScreenUV.Value, redIndex);
  302. }
  303. else
  304. {
  305. Info.text = "未检测到红色最大点!";
  306. }
  307. }
  308. else if (!bIdentifyRed && bIdentifyGreen) {
  309. if (infraredSpotBuffer[greenIndex].ScreenUV != null)
  310. {
  311. Info.text = "Green:" + infraredSpotBuffer[greenIndex].ScreenUV.Value.ToString("F4");
  312. //InfraredManager.ConnetDevicesSingle.ins.posAction?.Invoke(new Vector3(infraredSpotBuffer[greenIndex].ScreenUV.Value.x * Screen.width, infraredSpotBuffer[greenIndex].ScreenUV.Value.y * Screen.height, 0));
  313. onFilterPos2(infraredSpotBuffer[greenIndex].ScreenUV.Value, greenIndex);
  314. }
  315. else
  316. {
  317. Info.text = "未检测到绿色点!";
  318. }
  319. }
  320. else
  321. {
  322. //两个不选择和两个全选都跑识别两个点
  323. //自動切換 检测到光点
  324. if (infraredSpotBuffer[redIndex].ScreenUV != null)
  325. {
  326. Info.text = "Red:" + infraredSpotBuffer[redIndex].ScreenUV.Value.ToString("F4");
  327. //InfraredManager.ConnetDevicesSingle.ins.posAction?.Invoke(new Vector3(infraredSpotBuffer[redIndex].ScreenUV.Value.x * Screen.width, infraredSpotBuffer[redIndex].ScreenUV.Value.y * Screen.height, 0));
  328. onFilterPos2(infraredSpotBuffer[redIndex].ScreenUV.Value, redIndex);
  329. }
  330. else if (infraredSpotBuffer[greenIndex].ScreenUV != null)
  331. {
  332. Info.text = "Green:" + infraredSpotBuffer[greenIndex].ScreenUV.Value.ToString("F4");
  333. //InfraredManager.ConnetDevicesSingle.ins.posAction?.Invoke(new Vector3(infraredSpotBuffer[greenIndex].ScreenUV.Value.x * Screen.width, infraredSpotBuffer[greenIndex].ScreenUV.Value.y * Screen.height, 0));
  334. onFilterPos2(infraredSpotBuffer[greenIndex].ScreenUV.Value, greenIndex);
  335. }
  336. else
  337. {
  338. Info.text = "未检测到点!";
  339. }
  340. }
  341. }
  342. }
  343. }
  344. }
  345. }
  346. var t1 = Time.realtimeSinceStartup;
  347. var dt = t1 - t0;
  348. m_History[m_ValidHistoryFrames % m_History.Count] = dt;
  349. ++m_ValidHistoryFrames;
  350. m_UIUpdateTimer += Time.deltaTime;
  351. if (m_UIUpdateTimer >= m_UIUpdateInterval)
  352. {
  353. m_UIUpdateTimer = 0.0f;
  354. if (m_ValidHistoryFrames >= m_History.Count)
  355. {
  356. m_ValidHistoryFrames = 0;
  357. m_AverageTime = 0.0f;
  358. m_MinTime = float.PositiveInfinity;
  359. m_MaxTime = float.NegativeInfinity;
  360. {
  361. for (var i = 0; i < m_History.Count; i++)
  362. {
  363. var time = m_History[i];
  364. m_AverageTime += time;
  365. m_MinTime = Mathf.Min(m_MinTime, time);
  366. m_MaxTime = Mathf.Max(m_MaxTime, time);
  367. }
  368. m_AverageTime /= m_History.Count;
  369. }
  370. {
  371. m_History.Sort();
  372. // Odd-length history?
  373. if ((m_History.Count & 1) != 0)
  374. {
  375. m_MedianTime = m_History[m_History.Count / 2];
  376. }
  377. else
  378. {
  379. m_MedianTime = (m_History[m_History.Count / 2] + m_History[m_History.Count / 2 - 1]) / 2.0f;
  380. }
  381. }
  382. }
  383. var statistics = $"{m_History.Count} 帧样本:\naverage: {m_AverageTime * 1000.0f:F2}ms\nmedian: {m_MedianTime * 1000.0f:F2}ms\nmin: {m_MinTime * 1000.0f:F2}ms\nmax: {m_MaxTime * 1000.0f:F2}ms\n";
  384. //Method: {m_Method} {UnityEngine.SceneManagement.SceneManager.GetActiveScene().name} |
  385. if (m_UITime != null)
  386. m_UITime.text = $"Cam: {mUVCCameraInfo.CurrentWidth}x{mUVCCameraInfo.CurrentHeight}{(mUVCTexture2D? ",T2D:" : "")}{(mUVCTexture2D? mUVCTexture2D.width+ "x" : "")}{(mUVCTexture2D ? mUVCTexture2D.height:"")} \nLast Frame: {dt * 1000.0f:F2}ms \n{statistics}";
  387. }
  388. }
  389. Vector2 targetPos = Vector2.zero;
  390. public float filterDis = 3.0f;
  391. void onFilterPos(Vector2 _vector2Pos) {
  392. Vector2 np = new Vector2(_vector2Pos.x * Screen.width, _vector2Pos.y * Screen.height); //_vector2Pos.pixelToLocalPosition_AnchorCenter(Vector2.one, (transform as RectTransform).rect);
  393. if (Vector2.Distance(np, targetPos) >= filterDis)
  394. {
  395. targetPos = np;
  396. InfraredCameraHelper.InvokeOnPositionUpdate(targetPos);
  397. }
  398. }
  399. Vector2[] _targetPoints2 = new Vector2[] { Vector2.zero, Vector2.zero };
  400. void onFilterPos2(Vector2 _vector2Pos, int index)
  401. {
  402. Vector2 np = new Vector2(_vector2Pos.x * Screen.width, _vector2Pos.y * Screen.height);
  403. if (Vector2.Distance(np, _targetPoints2[index]) >= filterDis)
  404. {
  405. _targetPoints2[index] = np;
  406. InfraredCameraHelper.InvokeOnPositionUpdate2(_targetPoints2[index], index);
  407. }
  408. }
  409. // 标记屏幕的四个角
  410. public void ShowScreen(OrdinalQuadrilateral quad)
  411. {
  412. if (quad == null)
  413. {
  414. Info.text = "识别屏幕失败";
  415. return;
  416. }
  417. Info.text = "已识别到屏幕";
  418. if (ShowScreenQuad)
  419. {
  420. ScreenQuad.gameObject.SetActive(true);
  421. for (int i = 0; i < 4; i++)
  422. {
  423. RectTransform t = ScreenQuad.GetChild(i) as RectTransform;
  424. //mUVCCameraInfo.Size
  425. t.anchoredPosition = quad[i].UnityVector().pixelToLocalPosition_AnchorCenter(mUVCCameraInfo.Size, ScreenQuad.rect);
  426. }
  427. }
  428. }
  429. void ToMode(Mode mode)
  430. {
  431. if (this.mode == mode)
  432. return;
  433. if (mode == Mode.ScreenMap)
  434. {
  435. if (!screenIdentification.Screen.Active)
  436. {
  437. Info.text = "先定位屏幕";
  438. return;
  439. }
  440. Info.text = "按ESC退出";
  441. SetScreen(Color.black);
  442. Info.transform.SetAsLastSibling();
  443. this.mode = Mode.ScreenMap;
  444. }
  445. else if (mode == Mode.InfraredLocate)
  446. {
  447. Info.text = screenIdentification.Screen.Active ? "已定位屏幕" : "定位屏幕失败";
  448. //Info.text = "已识别到屏幕";
  449. SetScreen(null);
  450. foreach (var i in CrosshairInScreen)
  451. i.gameObject.SetActive(false);
  452. FullScreenImage.gameObject.SetActive(false);
  453. Info.transform.SetSiblingIndex(transform.childCount - 4);
  454. this.mode = Mode.InfraredLocate;
  455. DebugTexture(6, null);
  456. //DebugTexture(1, null); //null
  457. // rawImage1.texture = null;
  458. #if (!NDEBUG && DEBUG && ENABLE_LOG)
  459. Console.WriteLine($"{TAG} Mode.InfraredLocate:已识别到屏幕:{ screenIdentification.Screen.Active}");
  460. #endif
  461. }
  462. else if (mode == Mode.ScreenLocateManual)
  463. {
  464. //Info.text = "左键单击屏幕 左下角";
  465. //FullScreenImage.gameObject.SetActive(true);
  466. //Info.transform.SetSiblingIndex(transform.childCount - 1);
  467. //// var newTex = WebCamera.webCamTexture.AutoLight(10);
  468. ////DebugTexture(1, TextureToTexture2D(rawImage.texture));
  469. //CreateUVCTexture2DIfNeeded();
  470. //DebugTexture(6, mUVCTexture2D.zimAutoLight(brightness));
  471. ////mUVCTexture2DTemp = TextureToTexture2D(mUVCCameraInfo.previewTexture);
  472. ////DebugTexture(6, mUVCTexture2DTemp.zimAutoLight(brightness));
  473. //this.mode = Mode.ScreenLocateManual;
  474. }
  475. }
  476. private Texture2D TextureToTexture2D(Texture texture)
  477. {
  478. Texture2D _texture2D = new Texture2D(texture.width, texture.height, TextureFormat.ARGB32, false, true);
  479. RenderTexture currentRT = RenderTexture.active;
  480. RenderTexture renderTexture = RenderTexture.GetTemporary(
  481. texture.width,
  482. texture.height,
  483. 0,
  484. RenderTextureFormat.ARGB32,
  485. RenderTextureReadWrite.Linear);
  486. Graphics.Blit(texture, renderTexture);
  487. RenderTexture.active = renderTexture;
  488. _texture2D.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0);
  489. _texture2D.Apply();
  490. RenderTexture.active = currentRT;
  491. RenderTexture.ReleaseTemporary(renderTexture);
  492. return _texture2D;
  493. }
  494. private void CreateUVCTexture2DIfNeeded()
  495. {
  496. if (mUVCTexture2D != null)
  497. Destroy(mUVCTexture2D);
  498. mUVCTexture2D = TextureToTexture2D(mUVCTexture);
  499. }
  500. }