InfraredScreenPositioningView.cs 21 KB

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