InfraredScreenPositioningView.cs 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using LineUI;
  5. using UnityEngine.UI;
  6. using System.Linq;
  7. using ZIM;
  8. using o0;
  9. using Color = UnityEngine.Color;
  10. using InfraredManager;
  11. using Org.BouncyCastle.Asn1.Crmf;
  12. using ZIM.Unity;
  13. using o0.Project;
  14. using UnityEngine.SceneManagement;
  15. public class LinePosition
  16. {
  17. public int index;
  18. public List<Vector3> pos;
  19. }
  20. public class InfraredScreenPositioningView : JCUnityLib.ViewBase
  21. {
  22. [SerializeField]
  23. RectTransform canvasRectTransform;
  24. [SerializeField]
  25. RectTransform draggableParent;
  26. [SerializeField]
  27. GameObject mask;
  28. [SerializeField]
  29. GameObject cameraLight;
  30. [SerializeField]
  31. RectTransform pointsParent;
  32. [SerializeField]
  33. RectTransform pos1;
  34. [SerializeField]
  35. RectTransform pos2;
  36. [SerializeField]
  37. RectTransform pos3;
  38. [SerializeField]
  39. RectTransform pos4;
  40. //画线时候的点偏移量
  41. float offset = 10;
  42. [SerializeField]
  43. Line line;
  44. List<LinePosition> oldLinePosition;
  45. Vector3 beginPos;
  46. Vector3 endPos;
  47. //相机感光部分
  48. [SerializeField]
  49. Slider slider;
  50. [SerializeField]
  51. RawImage rawImage;
  52. [SerializeField]
  53. RectTransform crosshair;
  54. [SerializeField]
  55. RectTransform crosshairSmall;
  56. [SerializeField]
  57. GameObject textTip1;
  58. [SerializeField]
  59. GameObject textTip2;
  60. [SerializeField]
  61. Button btnAuto;
  62. [SerializeField]
  63. Button btnHandMovement;
  64. [SerializeField]
  65. BtnRecordInfrared btnRecordInfrared;
  66. bool bAuto = true;
  67. [SerializeField] Color normalColor = Color.white;
  68. [SerializeField] Color highlightedColor = Color.green;
  69. [SerializeField] Color normalTextColor = Color.black;
  70. [SerializeField] Color highlightedTextColor = Color.white;
  71. [SerializeField] TextAutoLanguage2 markerTextAutoLanguage2;
  72. [SerializeField]
  73. GameObject LayoutStart;
  74. [SerializeField]
  75. GameObject LayoutMarker;
  76. [SerializeField]
  77. GameObject LayoutSuccessful;
  78. [Tooltip("选择框的Line")]
  79. [SerializeField]
  80. Sprite[] ResultLines;// 0: 选中状态, 1: 未选中状态
  81. [Tooltip("选择框图片")]
  82. [SerializeField]
  83. Image[] ResultImages;
  84. [Tooltip("选择框按钮")]
  85. [SerializeField]
  86. Button[] ResultImagesButtons;
  87. [SerializeField]
  88. Button[] ResultButtons; // 结果选择按钮
  89. [SerializeField]
  90. RawImage CameraFirstImage; //第一个结果屏幕
  91. [SerializeField]
  92. RawImage CameraSecondImage; //第二个结果屏幕
  93. [SerializeField] LineGenerator FirstUILineGenerator;//第一个结果屏幕线条
  94. [SerializeField] LineGenerator SecondUILineGenerator;//第二个结果屏幕线条
  95. bool doLocateAuto;
  96. int DefaultResolutionIndex;
  97. private void Awake()
  98. {
  99. offset = line.MyThickness;
  100. }
  101. void Start()
  102. {
  103. doLocateAuto = false;
  104. textTip1.SetActive(true);
  105. //设置btnAuto 高亮
  106. OnButtonClick(btnAuto);
  107. textTip2.SetActive(false);
  108. //动态设置marker的提示语
  109. if (BluetoothAim.ins!=null && markerTextAutoLanguage2 != null)
  110. {
  111. string name = "";
  112. bool switchValue = false;
  113. if (BluetoothAim.ins.isMainConnectToHOUYIPRO())
  114. {
  115. name = TextAutoLanguage2.GetTextByKey("TitleTipMarker-HOUYIPro");
  116. }
  117. else if (BluetoothAim.ins.isMainConnectToARTEMISPRO())
  118. {
  119. name = TextAutoLanguage2.GetTextByKey("TitleTipMarker-ArtemisPro");
  120. }
  121. else if (BluetoothAim.ins.isMainConnectToGun())
  122. {
  123. //name = TextAutoLanguage2.GetTextByKey("TitleTipMarker-M9");
  124. switchValue = true;
  125. }
  126. if (switchValue)
  127. {
  128. markerTextAutoLanguage2.SetTextKey("TitleTipMarker-M9");
  129. }
  130. else {
  131. markerTextAutoLanguage2.textFormatArgs = new object[] { name };
  132. }
  133. }
  134. //手动不高亮
  135. //ResetButton(btnHandMovement);
  136. //quadUnityVectorList.Clear();
  137. //quadUnityVectorList.Add(new Vector2(16.39f, 35.91f));
  138. //quadUnityVectorList.Add(new Vector2(233.35f, 51.08f));
  139. //quadUnityVectorList.Add(new Vector2(94.15f, 219.11f));
  140. //quadUnityVectorList.Add(new Vector2(243.12f, 237.40f));
  141. Debug.Log("quadUnityVectorList count:" + ScreenLocate.quadUnityVectorList.Count);
  142. if (ScreenLocate.quadUnityVectorList.Count == 0)
  143. {
  144. Debug.Log("GetLocalPos");
  145. GetLocalPos();
  146. }
  147. else
  148. {
  149. Vector2 texSize = ScreenLocate.Main.getUVCCameraInfoSize;
  150. Debug.Log("texSize:" + texSize + " = " + canvasRectTransform.rect);
  151. //自动识别时候四个点
  152. SyncQuadUnityVectorListToPos();
  153. //pos1.anchoredPosition = ScreenLocate.quadUnityVectorList[0].pixelToLocalPosition_AnchorCenter(Vector2.one, canvasRectTransform.rect);
  154. //pos2.anchoredPosition = ScreenLocate.quadUnityVectorList[1].pixelToLocalPosition_AnchorCenter(Vector2.one, canvasRectTransform.rect);
  155. //pos4.anchoredPosition = ScreenLocate.quadUnityVectorList[2].pixelToLocalPosition_AnchorCenter(Vector2.one, canvasRectTransform.rect);
  156. //pos3.anchoredPosition = ScreenLocate.quadUnityVectorList[3].pixelToLocalPosition_AnchorCenter(Vector2.one, canvasRectTransform.rect);
  157. }
  158. //记录操作的位置信息
  159. oldLinePosition = new List<LinePosition>();
  160. SetLinePos();
  161. //相机感光度
  162. if (InfraredDemo._ins)
  163. {
  164. //重置偏移量
  165. InfraredDemo._ins.ResetCenterOffset();
  166. //重置识别点
  167. ScreenLocate.Main.ScreenIdentification.ClearQuadCache();
  168. //清除一下记录的点
  169. ScreenLocate.quadUnityVectorList.Clear();
  170. slider.onValueChanged.AddListener((value) =>
  171. {
  172. InfraredDemo._ins.onSliderEvent(value);
  173. });
  174. InfraredDemo._ins.onSetSliderValue(slider);
  175. offset = line.MyThickness = InfraredDemo._ins.lineWidth.Get();
  176. }
  177. else {
  178. //编辑器使用
  179. if (Application.isEditor || Application.platform == RuntimePlatform.WindowsPlayer) {
  180. slider.onValueChanged.AddListener((value) =>
  181. {
  182. double originalMin = 0.0;
  183. double originalMax = 10.0;
  184. double targetMin = -1;
  185. double targetMax = 1;
  186. // 计算转换后的值
  187. double result = InfraredDemo.MapValue(value, originalMin, originalMax, targetMin, targetMax);
  188. //int _current = (int)(result);
  189. Debug.Log("_current:" + value + " , result:" + result);
  190. ScreenLocate.Main.pcContrast = (float)result;
  191. });
  192. float v = ScreenLocate.Main.pcContrast;
  193. // 目标区间 [0, 10] 的边界值
  194. double targetMin = 0.0;
  195. double targetMax = 10.0;
  196. double originalMin = -1;
  197. double originalMax = 1;
  198. // 计算转换后的值
  199. double v2 = InfraredDemo.MapValue(v, originalMin, originalMax, targetMin, targetMax);
  200. Debug.Log("PC获取相机的感光度:" + v + " = " + v2);
  201. slider.SetValueWithoutNotify((float)v2);
  202. }
  203. }
  204. initSelectInfo();
  205. //if (ScreenLocate.Main.getUVCTexture)
  206. //{
  207. // //渲染相机画面
  208. // rawImage.texture = ScreenLocate.Main.getUVCTexture;
  209. // //Debug.Log("rawImage.texture:" + rawImage.texture.name);
  210. //}
  211. //slider.onValueChanged.AddListener((value) => {
  212. // //onSliderEvent(value);
  213. // InfraredDemo._ins.SetBrightness(value);
  214. //});
  215. //slider.value = InfraredDemo._ins.brightness.Get();
  216. //修改分辨率。是否清晰一点?
  217. //DefaultResolutionIndex = InfraredDemo._ins?.ResolutionIndex ?? 0;
  218. //Debug.Log("[InfraredScreenPositioningView]开始记录进入时候的分辨率:" + DefaultResolutionIndex);
  219. //InfraredDemo._ins?.SetResolutionNew(ScreenLocate.Main.HighScreenLocateResolutionIndex);
  220. //if (SB_EventSystem.ins && SB_EventSystem.ins.simulateMouseIsAwaked)
  221. //{
  222. // SB_EventSystem.ins.AwakenSimulateMouse();
  223. // // Debug.Log("simulate-mouse-close");
  224. //}
  225. }
  226. private void OnDestroy()
  227. {
  228. //修改回进入手动调节页面时候的分辨率
  229. //InfraredDemo._ins?.SetResolutionNew(DefaultResolutionIndex);
  230. Debug.Log("OnDestroy*********************************AwakenSimulateMouse:" + SB_EventSystem.ins.simulateMouseIsAwaked);
  231. if (SB_EventSystem.ins && !SB_EventSystem.ins.simulateMouseIsAwaked)
  232. {
  233. SB_EventSystem.ins.AwakenSimulateMouse();
  234. }
  235. }
  236. public RawImage Bg => rawImage;
  237. void Update()
  238. {
  239. if (enterFromZimWebCamera && ScreenLocate.Main.DebugOnZIMDemo) {
  240. // ZimWebCamera场景测试
  241. rawImage.texture = ScreenLocate.Main.outputRawImages[7].texture;
  242. if (ScreenLocate.Main.infraredSpotBuffer[0].CameraLocation.HasValue)
  243. {
  244. // 检测到光点
  245. var posInCanvas = ScreenLocate.Main.infraredSpotBuffer[0].CameraLocation.Value.pixelToLocalPosition_AnchorCenter(ScreenLocate.Main.CameraSize, rawImage.rectTransform.rect);
  246. crosshair.gameObject.SetActive(true);
  247. crosshair.anchoredPosition = posInCanvas;
  248. }
  249. else
  250. crosshair.gameObject.SetActive(false);
  251. //渲染相机画面
  252. CameraSecondImage.texture = rawImage.texture;
  253. CameraFirstImage.texture = rawImage.texture;
  254. }
  255. else if (InfraredDemo.running)
  256. {
  257. //渲染相机画面
  258. Texture texture = InfraredDemo.infraredCameraHelper.GetCameraTexture();
  259. if (rawImage.texture == null || texture.GetNativeTexturePtr() != rawImage.texture.GetNativeTexturePtr())
  260. {
  261. rawImage.texture = texture;
  262. //渲染相机画面
  263. CameraSecondImage.texture = rawImage.texture;
  264. CameraFirstImage.texture = rawImage.texture;
  265. }
  266. if (ScreenLocate.Main.infraredSpotBuffer[0].CameraLocation.HasValue)
  267. {
  268. // 检测到光点
  269. var posInCanvas = ScreenLocate.Main.infraredSpotBuffer[0].CameraLocation.Value.pixelToLocalPosition_AnchorCenter(ScreenLocate.Main.CameraSize, rawImage.rectTransform.rect);
  270. crosshairSmall.gameObject.SetActive(true);
  271. crosshairSmall.anchoredPosition = posInCanvas;
  272. }
  273. else
  274. crosshairSmall.gameObject.SetActive(false);
  275. //rawImage.material = InfraredDemo.infraredCameraHelper.GetCameraMaterial();
  276. }
  277. }
  278. public void OnClick_Back()
  279. {
  280. AudioMgr.ins.PlayBtn();
  281. ViewMgr.Instance.DestroyView<InfraredScreenPositioningView>();
  282. }
  283. /// <summary>
  284. /// 进入屏幕标记
  285. /// </summary>
  286. public void OnClick_EnterMarker() {
  287. LayoutStart.SetActive(false);
  288. LayoutMarker.SetActive(true);
  289. }
  290. /// <summary>
  291. /// 自动识别
  292. /// </summary>
  293. public void OnClick_Auto()
  294. {
  295. bAuto = true;
  296. doLocateAuto = true;
  297. textTip1.SetActive(false);
  298. textTip2.SetActive(true);
  299. ResetButton(btnAuto);
  300. if (enterFromZimWebCamera)
  301. {
  302. ScreenLocate _screenLocate = FindAnyObjectByType<ScreenLocate>();
  303. _screenLocate.EnterScreenLocateManualAuto();
  304. return;
  305. }
  306. if (InfraredDemo.running)
  307. {
  308. InfraredDemo.infraredCameraHelper.EnterScreenLocateManualAuto();
  309. }
  310. }
  311. /// <summary>
  312. /// 切换成手动方式
  313. /// </summary>
  314. public void onHandMovement()
  315. {
  316. bAuto = false;
  317. doLocateAuto = false;
  318. draggableParent.gameObject.SetActive(true);
  319. pointsParent.gameObject.SetActive(false);
  320. mask.SetActive(false);
  321. cameraLight.SetActive(true);
  322. }
  323. /// <summary>
  324. /// 自动识别后同步
  325. /// </summary>
  326. public void SyncScreenPosition()
  327. {
  328. //Debug.Log("quadUnityVectorList[i]:" + quadUnityVectorList[i]);
  329. Vector2 texSize = ScreenLocate.Main.getUVCCameraInfoSize;
  330. Debug.Log("texSize:" + texSize + " = " + canvasRectTransform.rect);
  331. //自动识别时候四个点
  332. //pos1.anchoredPosition = ScreenLocate.quadUnityVectorList[0].pixelToLocalPosition_AnchorCenter(Vector2.one, canvasRectTransform.rect);
  333. //pos2.anchoredPosition = ScreenLocate.quadUnityVectorList[1].pixelToLocalPosition_AnchorCenter(Vector2.one, canvasRectTransform.rect);
  334. //pos4.anchoredPosition = ScreenLocate.quadUnityVectorList[2].pixelToLocalPosition_AnchorCenter(Vector2.one, canvasRectTransform.rect);
  335. //pos3.anchoredPosition = ScreenLocate.quadUnityVectorList[3].pixelToLocalPosition_AnchorCenter(Vector2.one, canvasRectTransform.rect);
  336. SyncQuadUnityVectorListToPos();
  337. SetRectanglePoints(linePosConversion(pos1.localPosition, pos2.localPosition, pos3.localPosition, pos4.localPosition));
  338. //自动识别后隐藏手动按钮
  339. draggableParent.gameObject.SetActive(false);
  340. pointsParent.gameObject.SetActive(true);
  341. if (ScreenLocate.Main) {
  342. ZIM.Unity.QuadrilateralInCamera screen = ScreenLocate.Main.ScreenIdentification.Screen.QuadInCamera;
  343. //设置points点
  344. for (int i = 0; i < 4; i++)
  345. {
  346. RectTransform t = pointsParent.GetChild(i) as RectTransform;
  347. t.anchoredPosition = screen.Quad[i].pixelToLocalPosition_AnchorCenter(screen.CameraSize, pointsParent.rect);
  348. }
  349. }
  350. //显示最后结果
  351. LayoutMarker.SetActive(false);
  352. LayoutSuccessful.SetActive(true);
  353. //设置两个线段
  354. QuadrilateralInCamera screenAuto = ScreenLocate.Main.ScreenIdentification.QuadAuto;
  355. QuadrilateralInCamera screenSemiAuto = ScreenLocate.Main.ScreenIdentification.QuadSemiAuto;
  356. var lo = new Vector2(-0.5f, -0.5f);
  357. if (screenAuto != null)
  358. {
  359. FirstUILineGenerator.Points = new Vector2[4] {
  360. 2 * (new Vector2(screenAuto.Quad[0].x/texSize.x,screenAuto.Quad[0].y/texSize.y) + lo),
  361. 2 * (new Vector2(screenAuto.Quad[1].x/texSize.x,screenAuto.Quad[1].y/texSize.y) + lo),
  362. 2 * (new Vector2(screenAuto.Quad[3].x/texSize.x,screenAuto.Quad[3].y/texSize.y) + lo),
  363. 2 * (new Vector2(screenAuto.Quad[2].x/texSize.x,screenAuto.Quad[2].y/texSize.y) + lo) };
  364. // 打印 Points 的值,合并为一个字符串
  365. string pointsOutput = "1 Points: ";
  366. for (int i = 0; i < FirstUILineGenerator.Points.Length; i++)
  367. {
  368. pointsOutput += "[" + FirstUILineGenerator.Points[i].x + ", " + FirstUILineGenerator.Points[i].y + "]";
  369. if (i < FirstUILineGenerator.Points.Length - 1)
  370. {
  371. pointsOutput += ", "; // 添加逗号分隔符,最后一个元素后不加
  372. }
  373. }
  374. Debug.Log(pointsOutput);
  375. // 打印 Quad 的值,合并为一个字符串
  376. int[] customOrder = new int[] { 0, 1, 3, 2 };
  377. string quadOutput = "1 Quad Points: ";
  378. for (int i = 0; i < customOrder.Length; i++)
  379. {
  380. quadOutput += "[" + screenAuto.Quad[customOrder[i]].x + ", " + screenAuto.Quad[customOrder[i]].y + "]";
  381. if (i < customOrder.Length - 1)
  382. {
  383. quadOutput += ", "; // 添加逗号分隔符,最后一个元素后不加
  384. }
  385. }
  386. Debug.Log(quadOutput);
  387. }
  388. else {
  389. Debug.LogError("screenAuto 不存在!");
  390. }
  391. if (screenSemiAuto != null)
  392. {
  393. SecondUILineGenerator.Points = new Vector2[4] {
  394. 2 * (new Vector2(screenSemiAuto.Quad[0].x/texSize.x,screenSemiAuto.Quad[0].y/texSize.y) + lo),
  395. 2 * (new Vector2(screenSemiAuto.Quad[1].x/texSize.x,screenSemiAuto.Quad[1].y/texSize.y) + lo),
  396. 2 * (new Vector2(screenSemiAuto.Quad[3].x/texSize.x,screenSemiAuto.Quad[3].y/texSize.y) + lo),
  397. 2 * (new Vector2(screenSemiAuto.Quad[2].x/texSize.x,screenSemiAuto.Quad[2].y/texSize.y) + lo) };
  398. // 打印 Points 的值,合并为一个字符串
  399. string pointsOutput = "2 Points: ";
  400. for (int i = 0; i < SecondUILineGenerator.Points.Length; i++)
  401. {
  402. pointsOutput += "[" + SecondUILineGenerator.Points[i].x + ", " + SecondUILineGenerator.Points[i].y + "]";
  403. if (i < SecondUILineGenerator.Points.Length - 1)
  404. {
  405. pointsOutput += ", "; // 添加逗号分隔符,最后一个元素后不加
  406. }
  407. }
  408. Debug.Log(pointsOutput);
  409. // 打印 Quad 的值,合并为一个字符串
  410. int[] customOrder = new int[] { 0, 1, 3, 2 };
  411. string quadOutput = "2 Quad Points: ";
  412. for (int i = 0; i < customOrder.Length; i++)
  413. {
  414. quadOutput += "[" + screenSemiAuto.Quad[customOrder[i]].x + ", " + screenSemiAuto.Quad[customOrder[i]].y + "]";
  415. if (i < customOrder.Length - 1)
  416. {
  417. quadOutput += ", "; // 添加逗号分隔符,最后一个元素后不加
  418. }
  419. }
  420. Debug.Log(quadOutput);
  421. }
  422. else {
  423. Debug.LogError("screenSemiAuto 不存在!");
  424. }
  425. }
  426. #region 绘制线段部分
  427. //点击拖拽的开始位置
  428. public void onBeginPos(int index, Vector3 pos)
  429. {
  430. Debug.Log("pos begin: " + pos);
  431. beginPos = pos;
  432. }
  433. public void onDragPos(int index, Vector3 pos)
  434. {
  435. //设置线段的点
  436. SetRectanglePoints(linePosConversion(pos1.localPosition, pos2.localPosition, pos3.localPosition, pos4.localPosition));
  437. }
  438. //点击拖拽的结束位置
  439. public void onEndPos(int index, Vector3 pos)
  440. {
  441. Debug.Log("pos end: " + pos);
  442. endPos = pos;
  443. if (beginPos == endPos) return;
  444. //Debug.Log(index+",最后的点:" + pos);
  445. //再记录一次最后的点
  446. SetLinePos();
  447. }
  448. //同步设置图片对应的位置到line
  449. public void SetLinePos()
  450. {
  451. //记录一个操作点的操作位置
  452. AddOldLinePosition();
  453. //设置线段的点
  454. SetRectanglePoints(linePosConversion(pos1.localPosition, pos2.localPosition, pos3.localPosition, pos4.localPosition));
  455. }
  456. void AddOldLinePosition()
  457. {
  458. Vector3[] v = new Vector3[4];
  459. pos1.GetWorldCorners(v);
  460. Vector3[] v1 = new Vector3[4];
  461. pos1.GetLocalCorners(v1);
  462. //for (int i = 0; i < 4; i++)
  463. //{
  464. // Debug.Log(i + " =1= " + v[i]);
  465. // Debug.Log(i + " =2= " + v1[i]);
  466. //}
  467. //记录一个操作点的操作位置
  468. List<Vector3> screenPositions = new List<Vector3>();
  469. screenPositions.Add(pos1.localPosition);
  470. screenPositions.Add(pos2.localPosition);
  471. screenPositions.Add(pos3.localPosition);
  472. screenPositions.Add(pos4.localPosition);
  473. LinePosition linePosition = new LinePosition();
  474. linePosition.index = oldLinePosition.Count;
  475. linePosition.pos = screenPositions;
  476. oldLinePosition.Add(linePosition);
  477. }
  478. //转换绘制线段的点
  479. List<Vector2> linePosConversion(Vector3 _pos1, Vector3 _pos2, Vector3 _pos3, Vector3 _pos4)
  480. {
  481. List<Vector2> _screenPositions = new List<Vector2>();
  482. //点为负数的增大 offset,正数减少 offset
  483. //Vector2 startPos1 = new Vector2(_pos1.x - pos1.rect.width * 0.5f + offset, _pos1.y - pos1.rect.height * 0.5f + offset);
  484. //Vector2 startPos2 = new Vector2(_pos2.x + pos2.rect.width * 0.5f - offset, _pos2.y - pos2.rect.height * 0.5f + offset);
  485. //Vector2 startPos3 = new Vector2(_pos3.x + pos3.rect.width * 0.5f - offset, _pos3.y + pos3.rect.height * 0.5f - offset);
  486. //Vector2 startPos4 = new Vector2(_pos4.x - pos4.rect.width * 0.5f + offset, _pos4.y + pos4.rect.height * 0.5f - offset);
  487. Vector2 startPos1 = new Vector2(_pos1.x + offset, _pos1.y + offset);
  488. Vector2 startPos2 = new Vector2(_pos2.x - offset, _pos2.y + offset);
  489. Vector2 startPos3 = new Vector2(_pos3.x - offset, _pos3.y - offset);
  490. Vector2 startPos4 = new Vector2(_pos4.x + offset, _pos4.y - offset);
  491. _screenPositions.Add(startPos1);
  492. _screenPositions.Add(startPos2);
  493. _screenPositions.Add(startPos3);
  494. _screenPositions.Add(startPos4);
  495. return _screenPositions;
  496. }
  497. void SetRectanglePoints(List<Vector2> screenPositions)
  498. {
  499. line.SetLine(screenPositions);
  500. }
  501. //撤回上一个元素
  502. public void onRecall()
  503. {
  504. // 获取并删除最后一个元素,并且保留一个元素
  505. if (oldLinePosition.Count > 1) // 确保列表不为空
  506. {
  507. // 获取回退的那个元素点
  508. LinePosition lastElement_second = oldLinePosition[oldLinePosition.Count - 2];
  509. // 获取最后一个元素
  510. //LinePosition lastElement = oldLinePosition[oldLinePosition.Count - 1];
  511. //Debug.Log(JsonUtility.ToJson(lastElement) + " = " + oldLinePosition.Count);
  512. oldLinePosition.RemoveAt(oldLinePosition.Count - 1); // 删除最后一个元素
  513. pos1.localPosition = lastElement_second.pos[0];
  514. pos2.localPosition = lastElement_second.pos[1];
  515. pos3.localPosition = lastElement_second.pos[2];
  516. pos4.localPosition = lastElement_second.pos[3];
  517. //设置线段的点
  518. SetRectanglePoints(linePosConversion(lastElement_second.pos[0], lastElement_second.pos[1], lastElement_second.pos[2], lastElement_second.pos[3]));
  519. }
  520. }
  521. //是不是从Demo界面进入该页面的
  522. public bool enterFromInfraredDemo { get; set; } = false;
  523. //是否从测试场景进入
  524. public bool enterFromZimWebCamera { get; set; } = false;
  525. //确认修改
  526. public void onConfirmation()
  527. {
  528. if (enterFromZimWebCamera)
  529. {
  530. ConfirmScreenLocateManualTest();
  531. if (oldLinePosition.Count > 1) // 确保列表不为空
  532. {
  533. LinePosition lastElement = oldLinePosition[oldLinePosition.Count - 1];
  534. oldLinePosition.Clear();
  535. oldLinePosition.Add(lastElement);
  536. }
  537. SaveLocalPos();
  538. AudioMgr.ins.PlayBtn();
  539. ViewManager2.HideView(ViewManager2.Path_InfraredScreenPositioningView);
  540. return;
  541. }
  542. if (!ConfirmScreenLocateManual()) return;
  543. if (oldLinePosition.Count > 1) // 确保列表不为空
  544. {
  545. LinePosition lastElement = oldLinePosition[oldLinePosition.Count - 1];
  546. oldLinePosition.Clear();
  547. oldLinePosition.Add(lastElement);
  548. }
  549. if (InfraredDemo.running)
  550. {
  551. //跳转入界面
  552. AudioMgr.ins.PlayBtn();
  553. if (!enterFromInfraredDemo)
  554. {
  555. //每次初始化重置一下引导
  556. InfraredDemo._ins.resetInfraredPlayerPrefs();
  557. //GameObject connectGuidanceView = ViewManager2.getGameObjectAndShowView(ViewManager2.Path_ConnectGuidanceView);
  558. //connectGuidanceView.GetComponent<ConnectGuidanceView>().showTextipInfrared();
  559. if (!PlayerPrefs.HasKey("hideInfraredBowAndArrow"))
  560. {
  561. //如果是红外连接成功,记录一个tag
  562. PlayerPrefs.SetInt("hideInfraredBowAndArrow", 1);
  563. }
  564. onEnterInfrared();
  565. }
  566. else {
  567. ViewManager2.HideView(ViewManager2.Path_InfraredScreenPositioningView);
  568. }
  569. }
  570. //存储一次节点
  571. SaveLocalPos();
  572. }
  573. //重置位置
  574. public void onReset()
  575. {
  576. oldLinePosition.Clear();
  577. // 获取屏幕的四个角的像素坐标
  578. Vector2 bottomLeft = new Vector2(0, 0);
  579. // 将屏幕像素坐标转换为 Canvas 的局部坐标
  580. Vector2 localBottomLeft;
  581. RectTransformUtility.ScreenPointToLocalPointInRectangle(canvasRectTransform, bottomLeft, null, out localBottomLeft);
  582. // 打印结果
  583. Debug.Log("Local Bottom Left: " + localBottomLeft);
  584. //int _x = Mathf.FloorToInt(Mathf.Abs(localBottomLeft.x) - 120), _y = Mathf.FloorToInt(Mathf.Abs(localBottomLeft.y) - 77);
  585. int _x = Mathf.FloorToInt(Mathf.Abs(localBottomLeft.x)), _y = Mathf.FloorToInt(Mathf.Abs(localBottomLeft.y));
  586. pos1.anchoredPosition = new Vector3(-_x, -_y, 0); //Bottom Left
  587. pos2.anchoredPosition = new Vector3(_x, -_y, 0); //Bottom Right
  588. pos3.anchoredPosition = new Vector3(_x, _y, 0); //Top Right
  589. pos4.anchoredPosition = new Vector3(-_x, _y, 0); //Top Left
  590. //pos1.anchoredPosition = new Vector3(_x, _y, 0);
  591. //pos2.anchoredPosition = new Vector3(-_x, _y, 0);
  592. //pos3.anchoredPosition = new Vector3(-_x, -_y, 0);
  593. //pos4.anchoredPosition = new Vector3(_x, -_y, 0);
  594. //设置一次位置
  595. SetLinePos();
  596. btnRecordInfrared.Reset();
  597. ScreenLocate.Main.ScreenIdentification.ClearQuadCache();
  598. if (enterFromZimWebCamera)
  599. {
  600. ScreenLocate.Main.ScreenQuad.gameObject.SetActive(false);
  601. ScreenLocate.Main.UILineGenerator.Points = new Vector2[0];
  602. }
  603. }
  604. /// <summary>
  605. /// 标准四个点
  606. /// </summary>
  607. /// <param name="index"></param>
  608. /// <param name="pos"></param>
  609. public void onManualNewPos(int index, Vector3 pos)
  610. {
  611. Debug.Log("pos end: " + pos);
  612. if (index == 0)
  613. pos1.localPosition = pos;
  614. else if (index == 1)
  615. pos2.localPosition = pos;
  616. else if (index == 2)
  617. pos3.localPosition = pos;
  618. else if (index == 3)
  619. pos4.localPosition = pos;
  620. //再记录一次最后的点
  621. SetLinePos();
  622. }
  623. /// <summary>
  624. /// 处理新流程,先记录手动,然后到自动识别处理
  625. /// </summary>
  626. public void onManualToAutomatic() {
  627. if (enterFromZimWebCamera)
  628. {
  629. ConfirmScreenLocateManualTest();
  630. if (oldLinePosition.Count > 1) // 确保列表不为空
  631. {
  632. LinePosition lastElement = oldLinePosition[oldLinePosition.Count - 1];
  633. oldLinePosition.Clear();
  634. oldLinePosition.Add(lastElement);
  635. }
  636. SaveLocalPos();
  637. //到自动
  638. OnClick_Auto();
  639. return;
  640. }
  641. if (!ConfirmScreenLocateManual()) {
  642. Debug.LogError("ConfirmScreenLocateManual is false!");
  643. return;
  644. }
  645. if (oldLinePosition.Count > 1) // 确保列表不为空
  646. {
  647. LinePosition lastElement = oldLinePosition[oldLinePosition.Count - 1];
  648. oldLinePosition.Clear();
  649. oldLinePosition.Add(lastElement);
  650. }
  651. //存储一次节点
  652. SaveLocalPos();
  653. bAuto = true;
  654. doLocateAuto = true;
  655. //自动校准
  656. InfraredDemo.infraredCameraHelper.EnterScreenLocateManualAuto();
  657. }
  658. #endregion
  659. List<Vector2> _locatePointList = new();
  660. float _texWidth;
  661. float _texHeight;
  662. void RecordLocatePoint(RectTransform p, Vector2 pivot)
  663. {
  664. Vector2 pos = JCUnityLib.RectTransformUtils.GetPositionByPivot(p, pivot);
  665. pos.x = Mathf.Clamp01(pos.x / Screen.width);
  666. pos.y = Mathf.Clamp01(pos.y / Screen.height);
  667. _locatePointList.Add(pos);
  668. }
  669. bool ConfirmScreenLocateManual()
  670. {
  671. if (InfraredDemo.running)
  672. {
  673. //渲染截图
  674. Texture2D texture2D = InfraredDemo.infraredCameraHelper.EnterScreenLocateManual();
  675. if (texture2D == null)
  676. {
  677. Debug.Log("EnterScreenLocateManual = null");
  678. InfraredDemo.infraredCameraHelper.QuitScreenLocateManual(null);
  679. return false;
  680. }
  681. _locatePointList.Clear();
  682. _texWidth = texture2D.width;
  683. _texHeight = texture2D.height;
  684. RecordLocatePoint(pos1, new Vector2(0, 0));
  685. RecordLocatePoint(pos2, new Vector2(1, 0));
  686. RecordLocatePoint(pos3, new Vector2(1, 1));
  687. RecordLocatePoint(pos4, new Vector2(0, 1));
  688. //RecordLocatePoint(pos1, new Vector2(0.5f, 0.5f));
  689. //RecordLocatePoint(pos2, new Vector2(0.5f, 0.5f));
  690. //RecordLocatePoint(pos3, new Vector2(0.5f, 0.5f));
  691. //RecordLocatePoint(pos4, new Vector2(0.5f, 0.5f));
  692. InfraredDemo.infraredCameraHelper.QuitScreenLocateManual(_locatePointList);
  693. FindObjectOfType<InfraredDemo>().SetLocatePointsToCameraRender(_locatePointList, 1, 1);
  694. //同步数据
  695. ScreenLocate.quadUnityVectorList.Clear();
  696. ScreenLocate.quadUnityVectorList.Add(_locatePointList[0]);
  697. ScreenLocate.quadUnityVectorList.Add(_locatePointList[1]);
  698. //两个点切换,顺序不一样
  699. ScreenLocate.quadUnityVectorList.Add(_locatePointList[3]);
  700. ScreenLocate.quadUnityVectorList.Add(_locatePointList[2]);
  701. ScreenLocate.SaveScreenLocateVectorList();
  702. return true;
  703. }
  704. return false;
  705. }
  706. void ConfirmScreenLocateManualTest()
  707. {
  708. //渲染截图
  709. ScreenLocate _screenLocate = FindAnyObjectByType<ScreenLocate>();
  710. Texture2D texture2D = _screenLocate.EnterScreenLocateManual();
  711. if (texture2D == null)
  712. {
  713. _screenLocate.QuitScreenLocateManual(null);
  714. return;
  715. }
  716. _locatePointList.Clear();
  717. _texWidth = texture2D.width;
  718. _texHeight = texture2D.height;
  719. RecordLocatePoint(pos1, new Vector2(0, 0));
  720. RecordLocatePoint(pos2, new Vector2(1, 0));
  721. RecordLocatePoint(pos3, new Vector2(1, 1));
  722. RecordLocatePoint(pos4, new Vector2(0, 1));
  723. _screenLocate.QuitScreenLocateManual(_locatePointList);
  724. //FindObjectOfType<InfraredDemo>().SetLocatePointsToCameraRender(_locatePointList, _texWidth, _texHeight);
  725. setPointsLocation(_locatePointList,pointsParent.gameObject,!bAuto);
  726. if (!doLocateAuto) // 设置手动定位数据
  727. setPointsManual(_locatePointList, GameObject.Find("WebCameraView/CameraImage0/ScreenQuad"));
  728. //同步数据
  729. ScreenLocate.quadUnityVectorList.Clear();
  730. ScreenLocate.quadUnityVectorList.Add(new Vector2(_locatePointList[0].x, _locatePointList[0].y));
  731. ScreenLocate.quadUnityVectorList.Add(new Vector2(_locatePointList[1].x, _locatePointList[1].y));
  732. //两个点切换,顺序不一样
  733. ScreenLocate.quadUnityVectorList.Add(new Vector2(_locatePointList[3].x, _locatePointList[3].y));
  734. ScreenLocate.quadUnityVectorList.Add(new Vector2(_locatePointList[2].x, _locatePointList[2].y));
  735. ScreenLocate.SaveScreenLocateVectorList();
  736. }
  737. void setPointsLocation(List<Vector2> targetList, GameObject pointsTF2, bool active = true)
  738. {
  739. //GameObject pointsTF2 = GameObject.Find("WebCameraView/CameraImage0/ScreenQuad");
  740. pointsTF2.SetActive(active);
  741. if (pointsTF2.transform.childCount == targetList.Count)
  742. {
  743. for (int i = 0; i < pointsTF2.transform.childCount; i++)
  744. {
  745. Transform pointTF = pointsTF2.transform.GetChild(i);
  746. Vector2 pos = targetList[i];
  747. pointTF.localPosition = pos.pixelToLocalPosition_AnchorCenter(Vector2.one, pointsTF2.GetComponent<RectTransform>().rect);
  748. pointTF.gameObject.SetActive(true);
  749. }
  750. }
  751. }
  752. void setPointsManual(List<Vector2> targetList, GameObject pointsTF2, bool active = true)
  753. {
  754. setPointsLocation(targetList, pointsTF2, active);
  755. var lo = new Vector2(-0.5f, -0.5f);
  756. ScreenLocate.Main.UILineGenerator.Points = new Vector2[4] {
  757. 2 * (targetList[0] + lo),
  758. 2 * (targetList[1] + lo),
  759. 2 * (targetList[2] + lo),
  760. 2 * (targetList[3] + lo) };
  761. }
  762. void SaveLocalPos()
  763. {
  764. List<Vector3> screenPositions = new List<Vector3>();
  765. screenPositions.Add(pos1.anchoredPosition);
  766. screenPositions.Add(pos2.anchoredPosition);
  767. screenPositions.Add(pos3.anchoredPosition);
  768. screenPositions.Add(pos4.anchoredPosition);
  769. string saveStr = string.Join(';', screenPositions.Select(v => $"{v.x},{v.y}")); //,{v.z}
  770. Debug.Log("Local UI Position: " + saveStr);
  771. PlayerPrefs.SetString("ScreenPositioningView", saveStr);
  772. }
  773. void GetLocalPos()
  774. {
  775. string posListStr = PlayerPrefs.GetString("ScreenPositioningView", "");
  776. if (!string.IsNullOrWhiteSpace(posListStr))
  777. {
  778. List<Vector2> posList = posListStr.Split(';')
  779. .Select(s =>
  780. {
  781. string[] parts = s.Split(',');
  782. return new Vector2(float.Parse(parts[0]), float.Parse(parts[1]));
  783. })
  784. .ToList();
  785. pos1.anchoredPosition = posList[0];
  786. pos2.anchoredPosition = posList[1];
  787. pos3.anchoredPosition = posList[2];
  788. pos4.anchoredPosition = posList[3];
  789. SetRectanglePoints(linePosConversion(pos1.localPosition, pos2.localPosition, pos3.localPosition, pos4.localPosition));
  790. }
  791. }
  792. #region 按钮颜色切换
  793. private void OnButtonClick(Button button)
  794. {
  795. // 切换按钮颜色
  796. ColorBlock colors = button.colors;
  797. colors.normalColor = highlightedColor;
  798. colors.highlightedColor = highlightedColor;
  799. button.colors = colors;
  800. // 切换字体颜色
  801. Text buttonText = button.GetComponentInChildren<Text>();
  802. buttonText.color = highlightedTextColor;
  803. }
  804. private void ResetButton(Button button)
  805. {
  806. // 重置按钮颜色
  807. ColorBlock colors = button.colors;
  808. colors.normalColor = normalColor;
  809. colors.highlightedColor = normalColor;
  810. button.colors = colors;
  811. // 重置字体颜色
  812. Text buttonText = button.GetComponentInChildren<Text>();
  813. buttonText.color = normalTextColor;
  814. }
  815. #endregion
  816. #region 标定完成之后进入游戏界面
  817. void onEnterInfrared()
  818. {
  819. //添加进入射箭场景
  820. if (PlayerPrefs.GetInt("entry-guider-infrared-" + LoginMgr.myUserInfo.id, 0) == 0)
  821. {
  822. Debug.Log("-----进入射箭场景!");
  823. NewUserGuiderManager newUserGuiderManager = FindObjectOfType<NewUserGuiderManager>();
  824. newUserGuiderManager.curConfigKey = "开始-红外调整";
  825. newUserGuiderManager.isNewModule = AimHandler.ins.aimDeviceInfo.type == (int)AimDeviceType.HOUYIPRO || AimHandler.ins.aimDeviceInfo.type == (int)AimDeviceType.Gun || AimHandler.ins.aimDeviceInfo.type == (int)AimDeviceType.ARTEMISPRO;
  826. //进入射箭场景
  827. GlobalData.pkMatchType = PKMatchType.None;
  828. GameMgr.gameType = 1;
  829. //射一箭回到连接页面,Device.view
  830. GameMgr.bNavBack = true;
  831. GameMgr.bShowDistance = false;
  832. AimHandler.ins.bInitOne = false;//true
  833. //关闭计时器
  834. GameMgr.turnOffTimer = true;
  835. //关闭左边靶子和底部速度栏
  836. GameMgr.HideTargetView = true;
  837. GameMgr.HideBillboard = true;
  838. GameMgr.ButtonCount = 0;
  839. UnityEngine.SceneManagement.SceneManager.LoadScene(
  840. "Game", UnityEngine.SceneManagement.LoadSceneMode.Single);
  841. PlayerPrefs.SetInt("entry-guider-infrared-" + LoginMgr.myUserInfo.id, 1);
  842. }
  843. else
  844. {
  845. Debug.Log("-----跳转回连接界面!");
  846. //如不是第一次,则应该跳转回连接界面
  847. ViewMgr.Instance.DestroyView<SmartArcheryView>();
  848. ViewManager2.HideView(ViewManager2.Path_ConnectGuidanceView);
  849. }
  850. }
  851. #endregion
  852. #region 最后选择算法处理UI
  853. int selected = -1;
  854. void initSelectInfo() {
  855. for (int i = 0; i < 2; i++)
  856. {
  857. int currentIndex = i; // 将 i 赋值给局部变量
  858. ResultImagesButtons[currentIndex].onClick.AddListener(() => SelectImage(currentIndex));
  859. //ResultButtons[currentIndex].onClick.AddListener(() =>
  860. //{
  861. // if (currentIndex == 0)
  862. // {
  863. // OnFirstResult();
  864. // }
  865. // else if (currentIndex == 1)
  866. // {
  867. // OnSecondResult();
  868. // }
  869. //});
  870. }
  871. //默认选择1 自动
  872. SelectImage(0);
  873. }
  874. // 添加一个选择函数
  875. void SelectImage(int selectedIndex)
  876. {
  877. //如果重复选中则跳转
  878. if (selected == selectedIndex) {
  879. if (selected == 0)
  880. {
  881. OnFirstResult();
  882. }
  883. else if (selected == 1)
  884. {
  885. OnSecondResult();
  886. }
  887. return;
  888. }
  889. // 遍历所有图片
  890. for (int i = 0; i < ResultImages.Length; i++)
  891. {
  892. // 如果是选中的 index,赋值为 ResultLines[0],否则赋值为 ResultLines[1]
  893. if (i == selectedIndex)
  894. {
  895. selected = i;
  896. ResultImages[i].sprite = ResultLines[0];
  897. ResultButtons[i].interactable = true;
  898. }
  899. else
  900. {
  901. ResultImages[i].sprite = ResultLines[1];
  902. ResultButtons[i].interactable = false;
  903. }
  904. }
  905. }
  906. //选择全自动结果后进入游戏
  907. void OnFirstResult()
  908. {
  909. ScreenLocate.Main.SelectScreenAfterLocate(ScreenLocate.ScreenIdentificationTag.Auto);
  910. UpdateQuadUnityVectorList();
  911. onCompelete();
  912. }
  913. //选择半自动结果
  914. void OnSecondResult()
  915. {
  916. ScreenLocate.Main.SelectScreenAfterLocate(ScreenLocate.ScreenIdentificationTag.SemiAuto);
  917. UpdateQuadUnityVectorList();
  918. onCompelete();
  919. }
  920. public void onCompelete()
  921. {
  922. if (enterFromZimWebCamera)
  923. {
  924. SaveLocalPos();
  925. ViewManager2.HideView(ViewManager2.Path_InfraredScreenPositioningView);
  926. return;
  927. }
  928. if (InfraredDemo.running)
  929. {
  930. //跳转入界面
  931. AudioMgr.ins.PlayBtn();
  932. if (!enterFromInfraredDemo)
  933. {
  934. //每次初始化重置一下引导
  935. InfraredDemo._ins.resetInfraredPlayerPrefs();
  936. //GameObject connectGuidanceView = ViewManager2.getGameObjectAndShowView(ViewManager2.Path_ConnectGuidanceView);
  937. //connectGuidanceView.GetComponent<ConnectGuidanceView>().showTextipInfrared();
  938. if (!PlayerPrefs.HasKey("hideInfraredBowAndArrow"))
  939. {
  940. //如果是红外连接成功,记录一个tag
  941. PlayerPrefs.SetInt("hideInfraredBowAndArrow", 1);
  942. }
  943. onEnterInfrared();
  944. }
  945. else
  946. {
  947. ViewManager2.HideView(ViewManager2.Path_InfraredScreenPositioningView);
  948. }
  949. }
  950. //存储一次节点
  951. SaveLocalPos();
  952. }
  953. /// <summary>
  954. /// 选择模式后更新 quadUnityVectorList
  955. /// </summary>
  956. void UpdateQuadUnityVectorList() {
  957. ScreenLocate.Main.UpdateQuadUnityVectorList();
  958. SyncQuadUnityVectorListToPos();
  959. InfraredDemo._ins?.SetLocatePointsToCameraRender(ScreenLocate.quadUnityVectorList, 1, 1);
  960. _locatePointList.Clear();
  961. }
  962. void SyncQuadUnityVectorListToPos() {
  963. Debug.Log("[ScreenLocate] SyncQuadUnityVectorListToPos quadUnityVectorList:" + ScreenLocate.Main.PrintVector2List(ScreenLocate.quadUnityVectorList));
  964. pos1.anchoredPosition = ScreenLocate.quadUnityVectorList[0].pixelToLocalPosition_AnchorCenter(Vector2.one, canvasRectTransform.rect);
  965. pos2.anchoredPosition = ScreenLocate.quadUnityVectorList[1].pixelToLocalPosition_AnchorCenter(Vector2.one, canvasRectTransform.rect);
  966. pos4.anchoredPosition = ScreenLocate.quadUnityVectorList[2].pixelToLocalPosition_AnchorCenter(Vector2.one, canvasRectTransform.rect);
  967. pos3.anchoredPosition = ScreenLocate.quadUnityVectorList[3].pixelToLocalPosition_AnchorCenter(Vector2.one, canvasRectTransform.rect);
  968. }
  969. //这个脚本存在时候。任何切换操作都直接处理删除
  970. void OnSceneUnloaded(Scene scene)
  971. {
  972. ViewManager2.HideView(ViewManager2.Path_ConnectGuidanceView);
  973. ViewManager2.HideView(ViewManager2.Path_InfraredScreenPositioningView);
  974. }
  975. void OnEnable()
  976. {
  977. SceneManager.sceneUnloaded += OnSceneUnloaded;
  978. }
  979. void OnDisable()
  980. {
  981. SceneManager.sceneUnloaded -= OnSceneUnloaded;
  982. }
  983. #endregion
  984. }