InfraredScreenPositioningView.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  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. public class LinePosition
  12. {
  13. public int index;
  14. public List<Vector3> pos;
  15. }
  16. public class InfraredScreenPositioningView : JCUnityLib.ViewBase
  17. {
  18. [SerializeField]
  19. RectTransform canvasRectTransform;
  20. [SerializeField]
  21. RectTransform draggableParent;
  22. [SerializeField]
  23. RectTransform pointsParent;
  24. [SerializeField]
  25. RectTransform pos1;
  26. [SerializeField]
  27. RectTransform pos2;
  28. [SerializeField]
  29. RectTransform pos3;
  30. [SerializeField]
  31. RectTransform pos4;
  32. //画线时候的点偏移量
  33. float offset = 10;
  34. [SerializeField]
  35. Line line;
  36. List<LinePosition> oldLinePosition;
  37. Vector3 beginPos;
  38. Vector3 endPos;
  39. //相机感光部分
  40. [SerializeField]
  41. Slider slider;
  42. [SerializeField]
  43. RawImage rawImage;
  44. [SerializeField]
  45. GameObject textTip1;
  46. [SerializeField]
  47. GameObject textTip2;
  48. [SerializeField]
  49. Button btnAuto;
  50. [SerializeField]
  51. Button btnHandMovement;
  52. bool bAuto = true;
  53. [SerializeField] Color normalColor = Color.white;
  54. [SerializeField] Color highlightedColor = Color.green;
  55. [SerializeField] Color normalTextColor = Color.black;
  56. [SerializeField] Color highlightedTextColor = Color.white;
  57. int DefaultResolutionIndex;
  58. private void Awake()
  59. {
  60. offset = line.MyThickness;
  61. }
  62. void Start()
  63. {
  64. textTip1.SetActive(true);
  65. //设置btnAuto 高亮
  66. OnButtonClick(btnAuto);
  67. textTip2.SetActive(false);
  68. //手动不高亮
  69. //ResetButton(btnHandMovement);
  70. //quadUnityVectorList.Clear();
  71. //quadUnityVectorList.Add(new Vector2(16.39f, 35.91f));
  72. //quadUnityVectorList.Add(new Vector2(233.35f, 51.08f));
  73. //quadUnityVectorList.Add(new Vector2(94.15f, 219.11f));
  74. //quadUnityVectorList.Add(new Vector2(243.12f, 237.40f));
  75. Debug.Log("quadUnityVectorList count:" + ScreenLocate.quadUnityVectorList.Count);
  76. if (ScreenLocate.quadUnityVectorList.Count == 0)
  77. {
  78. Debug.Log("GetLocalPos");
  79. GetLocalPos();
  80. }
  81. else
  82. {
  83. Vector2 texSize = ScreenLocate.Main.getUVCCameraInfoSize;
  84. Debug.Log("texSize:" + texSize + " = " + canvasRectTransform.rect);
  85. //自动识别时候四个点
  86. pos1.anchoredPosition = ScreenLocate.quadUnityVectorList[0].pixelToLocalPosition_AnchorCenter(Vector2.one, canvasRectTransform.rect);
  87. pos2.anchoredPosition = ScreenLocate.quadUnityVectorList[1].pixelToLocalPosition_AnchorCenter(Vector2.one, canvasRectTransform.rect);
  88. pos4.anchoredPosition = ScreenLocate.quadUnityVectorList[2].pixelToLocalPosition_AnchorCenter(Vector2.one, canvasRectTransform.rect);
  89. pos3.anchoredPosition = ScreenLocate.quadUnityVectorList[3].pixelToLocalPosition_AnchorCenter(Vector2.one, canvasRectTransform.rect);
  90. }
  91. //记录操作的位置信息
  92. oldLinePosition = new List<LinePosition>();
  93. SetLinePos();
  94. //相机感光度
  95. if (InfraredDemo._ins)
  96. {
  97. slider.onValueChanged.AddListener((value) =>
  98. {
  99. InfraredDemo._ins.onSliderEvent(value);
  100. });
  101. InfraredDemo._ins.onSetSliderValue(slider);
  102. offset = line.MyThickness = InfraredDemo._ins.lineWidth.Get();
  103. }
  104. else {
  105. //编辑器使用
  106. if (Application.isEditor || Application.platform == RuntimePlatform.WindowsPlayer) {
  107. slider.onValueChanged.AddListener((value) =>
  108. {
  109. double originalMin = 0.0;
  110. double originalMax = 10.0;
  111. double targetMin = -1;
  112. double targetMax = 1;
  113. // 计算转换后的值
  114. double result = InfraredDemo.MapValue(value, originalMin, originalMax, targetMin, targetMax);
  115. //int _current = (int)(result);
  116. Debug.Log("_current:" + value + " , result:" + result);
  117. ScreenLocate.Main.pcContrast = (float)result;
  118. });
  119. float v = ScreenLocate.Main.pcContrast;
  120. // 目标区间 [0, 10] 的边界值
  121. double targetMin = 0.0;
  122. double targetMax = 10.0;
  123. double originalMin = -1;
  124. double originalMax = 1;
  125. // 计算转换后的值
  126. double v2 = InfraredDemo.MapValue(v, originalMin, originalMax, targetMin, targetMax);
  127. Debug.Log("PC获取相机的感光度:" + v + " = " + v2);
  128. slider.SetValueWithoutNotify((float)v2);
  129. }
  130. }
  131. //if (ScreenLocate.Main.getUVCTexture)
  132. //{
  133. // //渲染相机画面
  134. // rawImage.texture = ScreenLocate.Main.getUVCTexture;
  135. // //Debug.Log("rawImage.texture:" + rawImage.texture.name);
  136. //}
  137. //slider.onValueChanged.AddListener((value) => {
  138. // //onSliderEvent(value);
  139. // InfraredDemo._ins.SetBrightness(value);
  140. //});
  141. //slider.value = InfraredDemo._ins.brightness.Get();
  142. //修改分辨率。是否清晰一点?
  143. //DefaultResolutionIndex = InfraredDemo._ins?.ResolutionIndex ?? 0;
  144. //Debug.Log("[InfraredScreenPositioningView]开始记录进入时候的分辨率:" + DefaultResolutionIndex);
  145. //InfraredDemo._ins?.SetResolutionNew(ScreenLocate.Main.HighScreenLocateResolutionIndex);
  146. }
  147. private void OnDestroy()
  148. {
  149. //修改回进入手动调节页面时候的分辨率
  150. //InfraredDemo._ins?.SetResolutionNew(DefaultResolutionIndex);
  151. }
  152. void Update()
  153. {
  154. if (InfraredDemo.running)
  155. {
  156. //渲染相机画面
  157. Texture texture = InfraredDemo.infraredCameraHelper.GetCameraTexture();
  158. if (rawImage.texture == null || texture.GetNativeTexturePtr() != rawImage.texture.GetNativeTexturePtr())
  159. rawImage.texture = texture;
  160. //rawImage.material = InfraredDemo.infraredCameraHelper.GetCameraMaterial();
  161. }
  162. }
  163. public void OnClick_Back()
  164. {
  165. AudioMgr.ins.PlayBtn();
  166. ViewMgr.Instance.DestroyView<InfraredScreenPositioningView>();
  167. }
  168. /// <summary>
  169. /// 自动识别
  170. /// </summary>
  171. public void OnClick_Auto()
  172. {
  173. bAuto = true;
  174. textTip1.SetActive(false);
  175. textTip2.SetActive(true);
  176. ResetButton(btnAuto);
  177. if (enterFromZimWebCamera)
  178. {
  179. ScreenLocate _screenLocate = FindAnyObjectByType<ScreenLocate>();
  180. _screenLocate.EnterScreenLocateManualAuto();
  181. return;
  182. }
  183. if (InfraredDemo.running)
  184. {
  185. InfraredDemo.infraredCameraHelper.EnterScreenLocateManualAuto();
  186. }
  187. }
  188. /// <summary>
  189. /// 切换成手动方式
  190. /// </summary>
  191. public void onHandMovement()
  192. {
  193. bAuto = false;
  194. draggableParent.gameObject.SetActive(true);
  195. pointsParent.gameObject.SetActive(false);
  196. }
  197. /// <summary>
  198. /// 自动识别后同步
  199. /// </summary>
  200. public void SyncScreenPosition()
  201. {
  202. //Debug.Log("quadUnityVectorList[i]:" + quadUnityVectorList[i]);
  203. Vector2 texSize = ScreenLocate.Main.getUVCCameraInfoSize;
  204. Debug.Log("texSize:" + texSize + " = " + canvasRectTransform.rect);
  205. //自动识别时候四个点
  206. pos1.anchoredPosition = ScreenLocate.quadUnityVectorList[0].pixelToLocalPosition_AnchorCenter(Vector2.one, canvasRectTransform.rect);
  207. pos2.anchoredPosition = ScreenLocate.quadUnityVectorList[1].pixelToLocalPosition_AnchorCenter(Vector2.one, canvasRectTransform.rect);
  208. pos4.anchoredPosition = ScreenLocate.quadUnityVectorList[2].pixelToLocalPosition_AnchorCenter(Vector2.one, canvasRectTransform.rect);
  209. pos3.anchoredPosition = ScreenLocate.quadUnityVectorList[3].pixelToLocalPosition_AnchorCenter(Vector2.one, canvasRectTransform.rect);
  210. SetRectanglePoints(linePosConversion(pos1.localPosition, pos2.localPosition, pos3.localPosition, pos4.localPosition));
  211. //自动识别后隐藏手动按钮
  212. draggableParent.gameObject.SetActive(false);
  213. pointsParent.gameObject.SetActive(true);
  214. if (ScreenLocate.Main) {
  215. ZIM.Unity.QuadrilateralInCamera screen = ScreenLocate.Main.getScreenIdentification.Screen.QuadInCamera;
  216. //设置points点
  217. for (int i = 0; i < 4; i++)
  218. {
  219. RectTransform t = pointsParent.GetChild(i) as RectTransform;
  220. t.anchoredPosition = screen.Quad[i].pixelToLocalPosition_AnchorCenter(screen.CameraSize, pointsParent.rect);
  221. }
  222. }
  223. }
  224. #region 绘制线段部分
  225. //点击拖拽的开始位置
  226. public void onBeginPos(int index, Vector3 pos)
  227. {
  228. beginPos = pos;
  229. }
  230. public void onDragPos(int index, Vector3 pos)
  231. {
  232. //设置线段的点
  233. SetRectanglePoints(linePosConversion(pos1.localPosition, pos2.localPosition, pos3.localPosition, pos4.localPosition));
  234. }
  235. //点击拖拽的结束位置
  236. public void onEndPos(int index, Vector3 pos)
  237. {
  238. endPos = pos;
  239. if (beginPos == endPos) return;
  240. //Debug.Log(index+",最后的点:" + pos);
  241. //再记录一次最后的点
  242. SetLinePos();
  243. }
  244. //同步设置图片对应的位置到line
  245. public void SetLinePos()
  246. {
  247. //记录一个操作点的操作位置
  248. AddOldLinePosition();
  249. //设置线段的点
  250. SetRectanglePoints(linePosConversion(pos1.localPosition, pos2.localPosition, pos3.localPosition, pos4.localPosition));
  251. }
  252. void AddOldLinePosition()
  253. {
  254. Vector3[] v = new Vector3[4];
  255. pos1.GetWorldCorners(v);
  256. Vector3[] v1 = new Vector3[4];
  257. pos1.GetLocalCorners(v1);
  258. //for (int i = 0; i < 4; i++)
  259. //{
  260. // Debug.Log(i + " =1= " + v[i]);
  261. // Debug.Log(i + " =2= " + v1[i]);
  262. //}
  263. //记录一个操作点的操作位置
  264. List<Vector3> screenPositions = new List<Vector3>();
  265. screenPositions.Add(pos1.localPosition);
  266. screenPositions.Add(pos2.localPosition);
  267. screenPositions.Add(pos3.localPosition);
  268. screenPositions.Add(pos4.localPosition);
  269. LinePosition linePosition = new LinePosition();
  270. linePosition.index = oldLinePosition.Count;
  271. linePosition.pos = screenPositions;
  272. oldLinePosition.Add(linePosition);
  273. }
  274. //转换绘制线段的点
  275. List<Vector2> linePosConversion(Vector3 _pos1, Vector3 _pos2, Vector3 _pos3, Vector3 _pos4)
  276. {
  277. List<Vector2> _screenPositions = new List<Vector2>();
  278. //点为负数的增大 offset,正数减少 offset
  279. //Vector2 startPos1 = new Vector2(_pos1.x - pos1.rect.width * 0.5f + offset, _pos1.y - pos1.rect.height * 0.5f + offset);
  280. //Vector2 startPos2 = new Vector2(_pos2.x + pos2.rect.width * 0.5f - offset, _pos2.y - pos2.rect.height * 0.5f + offset);
  281. //Vector2 startPos3 = new Vector2(_pos3.x + pos3.rect.width * 0.5f - offset, _pos3.y + pos3.rect.height * 0.5f - offset);
  282. //Vector2 startPos4 = new Vector2(_pos4.x - pos4.rect.width * 0.5f + offset, _pos4.y + pos4.rect.height * 0.5f - offset);
  283. Vector2 startPos1 = new Vector2(_pos1.x + offset, _pos1.y + offset);
  284. Vector2 startPos2 = new Vector2(_pos2.x - offset, _pos2.y + offset);
  285. Vector2 startPos3 = new Vector2(_pos3.x - offset, _pos3.y - offset);
  286. Vector2 startPos4 = new Vector2(_pos4.x + offset, _pos4.y - offset);
  287. _screenPositions.Add(startPos1);
  288. _screenPositions.Add(startPos2);
  289. _screenPositions.Add(startPos3);
  290. _screenPositions.Add(startPos4);
  291. return _screenPositions;
  292. }
  293. void SetRectanglePoints(List<Vector2> screenPositions)
  294. {
  295. line.SetLine(screenPositions);
  296. }
  297. //撤回上一个元素
  298. public void onRecall()
  299. {
  300. // 获取并删除最后一个元素,并且保留一个元素
  301. if (oldLinePosition.Count > 1) // 确保列表不为空
  302. {
  303. // 获取回退的那个元素点
  304. LinePosition lastElement_second = oldLinePosition[oldLinePosition.Count - 2];
  305. // 获取最后一个元素
  306. //LinePosition lastElement = oldLinePosition[oldLinePosition.Count - 1];
  307. //Debug.Log(JsonUtility.ToJson(lastElement) + " = " + oldLinePosition.Count);
  308. oldLinePosition.RemoveAt(oldLinePosition.Count - 1); // 删除最后一个元素
  309. pos1.localPosition = lastElement_second.pos[0];
  310. pos2.localPosition = lastElement_second.pos[1];
  311. pos3.localPosition = lastElement_second.pos[2];
  312. pos4.localPosition = lastElement_second.pos[3];
  313. //设置线段的点
  314. SetRectanglePoints(linePosConversion(lastElement_second.pos[0], lastElement_second.pos[1], lastElement_second.pos[2], lastElement_second.pos[3]));
  315. }
  316. }
  317. //是不是从Demo界面进入该页面的
  318. public bool enterFromInfraredDemo { get; set; } = false;
  319. //是否从测试场景进入
  320. public bool enterFromZimWebCamera { get; set; } = false;
  321. //确认修改
  322. public void onConfirmation()
  323. {
  324. if (enterFromZimWebCamera)
  325. {
  326. ConfirmScreenLocateManualTest();
  327. if (oldLinePosition.Count > 1) // 确保列表不为空
  328. {
  329. LinePosition lastElement = oldLinePosition[oldLinePosition.Count - 1];
  330. oldLinePosition.Clear();
  331. oldLinePosition.Add(lastElement);
  332. }
  333. SaveLocalPos();
  334. AudioMgr.ins.PlayBtn();
  335. ViewManager2.HideView(ViewManager2.Path_InfraredScreenPositioningView);
  336. return;
  337. }
  338. if (!ConfirmScreenLocateManual()) return;
  339. if (oldLinePosition.Count > 1) // 确保列表不为空
  340. {
  341. LinePosition lastElement = oldLinePosition[oldLinePosition.Count - 1];
  342. oldLinePosition.Clear();
  343. oldLinePosition.Add(lastElement);
  344. }
  345. if (InfraredDemo.running)
  346. {
  347. //跳转入界面
  348. AudioMgr.ins.PlayBtn();
  349. if (!enterFromInfraredDemo)
  350. {
  351. //每次初始化重置一下引导
  352. InfraredDemo._ins.resetInfraredPlayerPrefs();
  353. //GameObject connectGuidanceView = ViewManager2.getGameObjectAndShowView(ViewManager2.Path_ConnectGuidanceView);
  354. //connectGuidanceView.GetComponent<ConnectGuidanceView>().showTextipInfrared();
  355. if (!PlayerPrefs.HasKey("hideInfraredBowAndArrow"))
  356. {
  357. //如果是红外连接成功,记录一个tag
  358. PlayerPrefs.SetInt("hideInfraredBowAndArrow", 1);
  359. }
  360. onEnterInfrared();
  361. }
  362. else {
  363. ViewManager2.HideView(ViewManager2.Path_InfraredScreenPositioningView);
  364. }
  365. }
  366. //存储一次节点
  367. SaveLocalPos();
  368. }
  369. //设置位置
  370. public void onReset()
  371. {
  372. oldLinePosition.Clear();
  373. // 获取屏幕的四个角的像素坐标
  374. Vector2 bottomLeft = new Vector2(0, 0);
  375. // 将屏幕像素坐标转换为 Canvas 的局部坐标
  376. Vector2 localBottomLeft;
  377. RectTransformUtility.ScreenPointToLocalPointInRectangle(canvasRectTransform, bottomLeft, null, out localBottomLeft);
  378. // 打印结果
  379. Debug.Log("Local Bottom Left: " + localBottomLeft);
  380. //int _x = Mathf.FloorToInt(Mathf.Abs(localBottomLeft.x) - 120), _y = Mathf.FloorToInt(Mathf.Abs(localBottomLeft.y) - 77);
  381. int _x = Mathf.FloorToInt(Mathf.Abs(localBottomLeft.x)), _y = Mathf.FloorToInt(Mathf.Abs(localBottomLeft.y));
  382. pos1.anchoredPosition = new Vector3(-_x, -_y, 0); //Bottom Left
  383. pos2.anchoredPosition = new Vector3(_x, -_y, 0); //Bottom Right
  384. pos3.anchoredPosition = new Vector3(_x, _y, 0); //Top Right
  385. pos4.anchoredPosition = new Vector3(-_x, _y, 0); //Top Left
  386. //pos1.anchoredPosition = new Vector3(_x, _y, 0);
  387. //pos2.anchoredPosition = new Vector3(-_x, _y, 0);
  388. //pos3.anchoredPosition = new Vector3(-_x, -_y, 0);
  389. //pos4.anchoredPosition = new Vector3(_x, -_y, 0);
  390. //设置一次位置
  391. SetLinePos();
  392. }
  393. #endregion
  394. List<Vector2> _locatePointList = new();
  395. float _texWidth;
  396. float _texHeight;
  397. void RecordLocatePoint(RectTransform p, Vector2 pivot)
  398. {
  399. Vector2 pos = JCUnityLib.RectTransformUtils.GetPositionByPivot(p, pivot);
  400. pos.x = Mathf.Clamp01(pos.x / Screen.width);
  401. pos.y = Mathf.Clamp01(pos.y / Screen.height);
  402. _locatePointList.Add(pos);
  403. }
  404. bool ConfirmScreenLocateManual()
  405. {
  406. if (InfraredDemo.running)
  407. {
  408. //渲染截图
  409. Texture2D texture2D = InfraredDemo.infraredCameraHelper.EnterScreenLocateManual();
  410. if (texture2D == null)
  411. {
  412. Debug.Log("EnterScreenLocateManual = null");
  413. InfraredDemo.infraredCameraHelper.QuitScreenLocateManual(null);
  414. return false;
  415. }
  416. _locatePointList.Clear();
  417. _texWidth = texture2D.width;
  418. _texHeight = texture2D.height;
  419. RecordLocatePoint(pos1, new Vector2(0, 0));
  420. RecordLocatePoint(pos2, new Vector2(1, 0));
  421. RecordLocatePoint(pos3, new Vector2(1, 1));
  422. RecordLocatePoint(pos4, new Vector2(0, 1));
  423. //RecordLocatePoint(pos1, new Vector2(0.5f, 0.5f));
  424. //RecordLocatePoint(pos2, new Vector2(0.5f, 0.5f));
  425. //RecordLocatePoint(pos3, new Vector2(0.5f, 0.5f));
  426. //RecordLocatePoint(pos4, new Vector2(0.5f, 0.5f));
  427. InfraredDemo.infraredCameraHelper.QuitScreenLocateManual(_locatePointList);
  428. FindObjectOfType<InfraredDemo>().SetLocatePointsToCameraRender(_locatePointList, 1, 1);
  429. //setPointsLocation(_locatePointList, pointsParent.gameObject, !bAuto);
  430. //同步数据
  431. ScreenLocate.quadUnityVectorList.Clear();
  432. ScreenLocate.quadUnityVectorList.Add(_locatePointList[0]);
  433. ScreenLocate.quadUnityVectorList.Add(_locatePointList[1]);
  434. //两个点切换,顺序不一样
  435. ScreenLocate.quadUnityVectorList.Add(_locatePointList[3]);
  436. ScreenLocate.quadUnityVectorList.Add(_locatePointList[2]);
  437. ScreenLocate.SaveScreenLocateVectorList();
  438. return true;
  439. }
  440. return false;
  441. }
  442. void ConfirmScreenLocateManualTest()
  443. {
  444. //渲染截图
  445. ScreenLocate _screenLocate = FindAnyObjectByType<ScreenLocate>();
  446. Texture2D texture2D = _screenLocate.EnterScreenLocateManual();
  447. if (texture2D == null)
  448. {
  449. _screenLocate.QuitScreenLocateManual(null);
  450. return;
  451. }
  452. _locatePointList.Clear();
  453. _texWidth = texture2D.width;
  454. _texHeight = texture2D.height;
  455. RecordLocatePoint(pos1, new Vector2(0, 0));
  456. RecordLocatePoint(pos2, new Vector2(1, 0));
  457. RecordLocatePoint(pos3, new Vector2(1, 1));
  458. RecordLocatePoint(pos4, new Vector2(0, 1));
  459. _screenLocate.QuitScreenLocateManual(_locatePointList);
  460. //FindObjectOfType<InfraredDemo>().SetLocatePointsToCameraRender(_locatePointList, _texWidth, _texHeight);
  461. setPointsLocation(_locatePointList,GameObject.Find("WebCameraView/CameraImage0/ScreenQuad"));
  462. setPointsLocation(_locatePointList,pointsParent.gameObject,!bAuto);
  463. //同步数据
  464. ScreenLocate.quadUnityVectorList.Clear();
  465. ScreenLocate.quadUnityVectorList.Add(new Vector2(_locatePointList[0].x, _locatePointList[0].y));
  466. ScreenLocate.quadUnityVectorList.Add(new Vector2(_locatePointList[1].x, _locatePointList[1].y));
  467. //两个点切换,顺序不一样
  468. ScreenLocate.quadUnityVectorList.Add(new Vector2(_locatePointList[3].x, _locatePointList[3].y));
  469. ScreenLocate.quadUnityVectorList.Add(new Vector2(_locatePointList[2].x, _locatePointList[2].y));
  470. ScreenLocate.SaveScreenLocateVectorList();
  471. }
  472. void setPointsLocation(List<Vector2> targetList ,GameObject pointsTF2,bool active = true) {
  473. //GameObject pointsTF2 = GameObject.Find("WebCameraView/CameraImage0/ScreenQuad");
  474. pointsTF2.SetActive(active);
  475. if (pointsTF2.transform.childCount == targetList.Count)
  476. {
  477. Vector2 texSize = new Vector2(_texWidth, _texHeight);
  478. for (int i = 0; i < pointsTF2.transform.childCount; i++)
  479. {
  480. Transform pointTF = pointsTF2.transform.GetChild(i);
  481. Vector2 pos = targetList[i];
  482. pointTF.localPosition = pos.pixelToLocalPosition_AnchorCenter(Vector2.one, pointsTF2.GetComponent<RectTransform>().rect);
  483. pointTF.gameObject.SetActive(true);
  484. }
  485. }
  486. }
  487. void SaveLocalPos()
  488. {
  489. List<Vector3> screenPositions = new List<Vector3>();
  490. screenPositions.Add(pos1.anchoredPosition);
  491. screenPositions.Add(pos2.anchoredPosition);
  492. screenPositions.Add(pos3.anchoredPosition);
  493. screenPositions.Add(pos4.anchoredPosition);
  494. string saveStr = string.Join(';', screenPositions.Select(v => $"{v.x},{v.y}")); //,{v.z}
  495. Debug.Log("Local UI Position: " + saveStr);
  496. PlayerPrefs.SetString("ScreenPositioningView", saveStr);
  497. }
  498. void GetLocalPos()
  499. {
  500. string posListStr = PlayerPrefs.GetString("ScreenPositioningView", "");
  501. if (!string.IsNullOrWhiteSpace(posListStr))
  502. {
  503. List<Vector2> posList = posListStr.Split(';')
  504. .Select(s =>
  505. {
  506. string[] parts = s.Split(',');
  507. return new Vector2(float.Parse(parts[0]), float.Parse(parts[1]));
  508. })
  509. .ToList();
  510. pos1.anchoredPosition = posList[0];
  511. pos2.anchoredPosition = posList[1];
  512. pos3.anchoredPosition = posList[2];
  513. pos4.anchoredPosition = posList[3];
  514. SetRectanglePoints(linePosConversion(pos1.localPosition, pos2.localPosition, pos3.localPosition, pos4.localPosition));
  515. }
  516. }
  517. #region 按钮颜色切换
  518. private void OnButtonClick(Button button)
  519. {
  520. // 切换按钮颜色
  521. ColorBlock colors = button.colors;
  522. colors.normalColor = highlightedColor;
  523. colors.highlightedColor = highlightedColor;
  524. button.colors = colors;
  525. // 切换字体颜色
  526. Text buttonText = button.GetComponentInChildren<Text>();
  527. buttonText.color = highlightedTextColor;
  528. }
  529. private void ResetButton(Button button)
  530. {
  531. // 重置按钮颜色
  532. ColorBlock colors = button.colors;
  533. colors.normalColor = normalColor;
  534. colors.highlightedColor = normalColor;
  535. button.colors = colors;
  536. // 重置字体颜色
  537. Text buttonText = button.GetComponentInChildren<Text>();
  538. buttonText.color = normalTextColor;
  539. }
  540. #endregion
  541. #region 标定完成之后进入游戏界面
  542. void onEnterInfrared()
  543. {
  544. //添加进入射箭场景
  545. if (PlayerPrefs.GetInt("entry-guider-infrared-" + LoginMgr.myUserInfo.id, 0) == 0)
  546. {
  547. Debug.Log("-----进入射箭场景!");
  548. NewUserGuiderManager newUserGuiderManager = FindObjectOfType<NewUserGuiderManager>();
  549. newUserGuiderManager.curConfigKey = "开始-红外调整";
  550. newUserGuiderManager.isNewModule = AimHandler.ins.aimDeviceInfo.type == (int)AimDeviceType.HOUYIPRO || AimHandler.ins.aimDeviceInfo.type == (int)AimDeviceType.Gun || AimHandler.ins.aimDeviceInfo.type == (int)AimDeviceType.ARTEMISPRO;
  551. //进入射箭场景
  552. GlobalData.pkMatchType = PKMatchType.None;
  553. GameMgr.gameType = 1;
  554. //射一箭回到连接页面,Device.view
  555. GameMgr.bNavBack = true;
  556. GameMgr.bShowDistance = false;
  557. AimHandler.ins.bInitOne = true;
  558. //关闭计时器
  559. GameMgr.turnOffTimer = true;
  560. UnityEngine.SceneManagement.SceneManager.LoadScene(
  561. "Game", UnityEngine.SceneManagement.LoadSceneMode.Single);
  562. PlayerPrefs.SetInt("entry-guider-infrared-" + LoginMgr.myUserInfo.id, 1);
  563. }
  564. else
  565. {
  566. Debug.Log("-----跳转回连接界面!");
  567. //如不是第一次,则应该跳转回连接界面
  568. ViewMgr.Instance.DestroyView<SmartArcheryView>();
  569. ViewManager2.HideView(ViewManager2.Path_ConnectGuidanceView);
  570. }
  571. }
  572. #endregion
  573. }