| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using LineUI;
- using UnityEngine.UI;
- using System.Linq;
- using ZIM;
- using o0;
- using Color = UnityEngine.Color;
- using InfraredManager;
- using Org.BouncyCastle.Asn1.Crmf;
- using ZIM.Unity;
- public class LinePosition
- {
- public int index;
- public List<Vector3> pos;
- }
- public class InfraredScreenPositioningView : JCUnityLib.ViewBase
- {
- [SerializeField]
- RectTransform canvasRectTransform;
- [SerializeField]
- RectTransform draggableParent;
- [SerializeField]
- GameObject mask;
- [SerializeField]
- GameObject cameraLight;
- [SerializeField]
- RectTransform pointsParent;
- [SerializeField]
- RectTransform pos1;
- [SerializeField]
- RectTransform pos2;
- [SerializeField]
- RectTransform pos3;
- [SerializeField]
- RectTransform pos4;
- //画线时候的点偏移量
- float offset = 10;
- [SerializeField]
- Line line;
- List<LinePosition> oldLinePosition;
- Vector3 beginPos;
- Vector3 endPos;
- //相机感光部分
- [SerializeField]
- Slider slider;
- [SerializeField]
- RawImage rawImage;
- [SerializeField]
- RectTransform crosshair;
- [SerializeField]
- GameObject textTip1;
- [SerializeField]
- GameObject textTip2;
- [SerializeField]
- Button btnAuto;
- [SerializeField]
- Button btnHandMovement;
- [SerializeField]
- BtnRecordInfrared btnRecordInfrared;
- bool bAuto = true;
- [SerializeField] Color normalColor = Color.white;
- [SerializeField] Color highlightedColor = Color.green;
- [SerializeField] Color normalTextColor = Color.black;
- [SerializeField] Color highlightedTextColor = Color.white;
- int DefaultResolutionIndex;
- private void Awake()
- {
- offset = line.MyThickness;
- }
- void Start()
- {
- textTip1.SetActive(true);
- //设置btnAuto 高亮
- OnButtonClick(btnAuto);
- textTip2.SetActive(false);
- //手动不高亮
- //ResetButton(btnHandMovement);
- //quadUnityVectorList.Clear();
- //quadUnityVectorList.Add(new Vector2(16.39f, 35.91f));
- //quadUnityVectorList.Add(new Vector2(233.35f, 51.08f));
- //quadUnityVectorList.Add(new Vector2(94.15f, 219.11f));
- //quadUnityVectorList.Add(new Vector2(243.12f, 237.40f));
- Debug.Log("quadUnityVectorList count:" + ScreenLocate.quadUnityVectorList.Count);
- if (ScreenLocate.quadUnityVectorList.Count == 0)
- {
- Debug.Log("GetLocalPos");
- GetLocalPos();
- }
- else
- {
- Vector2 texSize = ScreenLocate.Main.getUVCCameraInfoSize;
- Debug.Log("texSize:" + texSize + " = " + canvasRectTransform.rect);
- //自动识别时候四个点
- pos1.anchoredPosition = ScreenLocate.quadUnityVectorList[0].pixelToLocalPosition_AnchorCenter(Vector2.one, canvasRectTransform.rect);
- pos2.anchoredPosition = ScreenLocate.quadUnityVectorList[1].pixelToLocalPosition_AnchorCenter(Vector2.one, canvasRectTransform.rect);
- pos4.anchoredPosition = ScreenLocate.quadUnityVectorList[2].pixelToLocalPosition_AnchorCenter(Vector2.one, canvasRectTransform.rect);
- pos3.anchoredPosition = ScreenLocate.quadUnityVectorList[3].pixelToLocalPosition_AnchorCenter(Vector2.one, canvasRectTransform.rect);
- }
- //记录操作的位置信息
- oldLinePosition = new List<LinePosition>();
- SetLinePos();
- //相机感光度
- if (InfraredDemo._ins)
- {
- //重置偏移量
- InfraredDemo._ins.ResetCenterOffset();
- slider.onValueChanged.AddListener((value) =>
- {
- InfraredDemo._ins.onSliderEvent(value);
- });
- InfraredDemo._ins.onSetSliderValue(slider);
- offset = line.MyThickness = InfraredDemo._ins.lineWidth.Get();
- }
- else {
- //编辑器使用
- if (Application.isEditor || Application.platform == RuntimePlatform.WindowsPlayer) {
- slider.onValueChanged.AddListener((value) =>
- {
- double originalMin = 0.0;
- double originalMax = 10.0;
- double targetMin = -1;
- double targetMax = 1;
- // 计算转换后的值
- double result = InfraredDemo.MapValue(value, originalMin, originalMax, targetMin, targetMax);
- //int _current = (int)(result);
- Debug.Log("_current:" + value + " , result:" + result);
- ScreenLocate.Main.pcContrast = (float)result;
- });
- float v = ScreenLocate.Main.pcContrast;
- // 目标区间 [0, 10] 的边界值
- double targetMin = 0.0;
- double targetMax = 10.0;
- double originalMin = -1;
- double originalMax = 1;
- // 计算转换后的值
- double v2 = InfraredDemo.MapValue(v, originalMin, originalMax, targetMin, targetMax);
- Debug.Log("PC获取相机的感光度:" + v + " = " + v2);
- slider.SetValueWithoutNotify((float)v2);
- }
- }
- //if (ScreenLocate.Main.getUVCTexture)
- //{
- // //渲染相机画面
- // rawImage.texture = ScreenLocate.Main.getUVCTexture;
- // //Debug.Log("rawImage.texture:" + rawImage.texture.name);
- //}
- //slider.onValueChanged.AddListener((value) => {
- // //onSliderEvent(value);
- // InfraredDemo._ins.SetBrightness(value);
- //});
- //slider.value = InfraredDemo._ins.brightness.Get();
- //修改分辨率。是否清晰一点?
- //DefaultResolutionIndex = InfraredDemo._ins?.ResolutionIndex ?? 0;
- //Debug.Log("[InfraredScreenPositioningView]开始记录进入时候的分辨率:" + DefaultResolutionIndex);
- //InfraredDemo._ins?.SetResolutionNew(ScreenLocate.Main.HighScreenLocateResolutionIndex);
- }
- private void OnDestroy()
- {
- //修改回进入手动调节页面时候的分辨率
- //InfraredDemo._ins?.SetResolutionNew(DefaultResolutionIndex);
- }
- public RawImage Bg => rawImage;
- void Update()
- {
- if (enterFromZimWebCamera && ScreenLocate.Main.DebugOnZIMDemo) {
- // ZimWebCamera场景测试
- rawImage.texture = ScreenLocate.Main.outputRawImages[7].texture;
- if (ScreenLocate.Main.infraredSpotBuffer[0].CameraLocation.HasValue)
- {
- // 检测到光点
- var posInCanvas = ScreenLocate.Main.infraredSpotBuffer[0].CameraLocation.Value.pixelToLocalPosition_AnchorCenter(ScreenLocate.Main.CameraSize, rawImage.rectTransform.rect);
- crosshair.gameObject.SetActive(true);
- crosshair.anchoredPosition = posInCanvas;
- }
- else
- crosshair.gameObject.SetActive(false);
- }
- else if (InfraredDemo.running)
- {
- //渲染相机画面
- Texture texture = InfraredDemo.infraredCameraHelper.GetCameraTexture();
- if (rawImage.texture == null || texture.GetNativeTexturePtr() != rawImage.texture.GetNativeTexturePtr())
- rawImage.texture = texture;
- //rawImage.material = InfraredDemo.infraredCameraHelper.GetCameraMaterial();
- }
- }
- public void OnClick_Back()
- {
- AudioMgr.ins.PlayBtn();
- ViewMgr.Instance.DestroyView<InfraredScreenPositioningView>();
- }
- /// <summary>
- /// 自动识别
- /// </summary>
- public void OnClick_Auto()
- {
- bAuto = true;
- textTip1.SetActive(false);
- textTip2.SetActive(true);
- ResetButton(btnAuto);
- if (enterFromZimWebCamera)
- {
- ScreenLocate _screenLocate = FindAnyObjectByType<ScreenLocate>();
- _screenLocate.EnterScreenLocateManualAuto();
- return;
- }
- if (InfraredDemo.running)
- {
- InfraredDemo.infraredCameraHelper.EnterScreenLocateManualAuto();
- }
-
- }
- /// <summary>
- /// 切换成手动方式
- /// </summary>
- public void onHandMovement()
- {
- bAuto = false;
- draggableParent.gameObject.SetActive(true);
- pointsParent.gameObject.SetActive(false);
- mask.SetActive(false);
- cameraLight.SetActive(true);
- }
- /// <summary>
- /// 自动识别后同步
- /// </summary>
- public void SyncScreenPosition()
- {
- //Debug.Log("quadUnityVectorList[i]:" + quadUnityVectorList[i]);
- Vector2 texSize = ScreenLocate.Main.getUVCCameraInfoSize;
- Debug.Log("texSize:" + texSize + " = " + canvasRectTransform.rect);
- //自动识别时候四个点
- pos1.anchoredPosition = ScreenLocate.quadUnityVectorList[0].pixelToLocalPosition_AnchorCenter(Vector2.one, canvasRectTransform.rect);
- pos2.anchoredPosition = ScreenLocate.quadUnityVectorList[1].pixelToLocalPosition_AnchorCenter(Vector2.one, canvasRectTransform.rect);
- pos4.anchoredPosition = ScreenLocate.quadUnityVectorList[2].pixelToLocalPosition_AnchorCenter(Vector2.one, canvasRectTransform.rect);
- pos3.anchoredPosition = ScreenLocate.quadUnityVectorList[3].pixelToLocalPosition_AnchorCenter(Vector2.one, canvasRectTransform.rect);
- SetRectanglePoints(linePosConversion(pos1.localPosition, pos2.localPosition, pos3.localPosition, pos4.localPosition));
- //自动识别后隐藏手动按钮
- draggableParent.gameObject.SetActive(false);
- pointsParent.gameObject.SetActive(true);
- if (ScreenLocate.Main) {
- ZIM.Unity.QuadrilateralInCamera screen = ScreenLocate.Main.ScreenIdentification.Screen.QuadInCamera;
- //设置points点
- for (int i = 0; i < 4; i++)
- {
- RectTransform t = pointsParent.GetChild(i) as RectTransform;
- t.anchoredPosition = screen.Quad[i].pixelToLocalPosition_AnchorCenter(screen.CameraSize, pointsParent.rect);
- }
- }
-
- }
- #region 绘制线段部分
- //点击拖拽的开始位置
- public void onBeginPos(int index, Vector3 pos)
- {
- Debug.Log("pos begin: " + pos);
- beginPos = pos;
- }
- public void onDragPos(int index, Vector3 pos)
- {
- //设置线段的点
- SetRectanglePoints(linePosConversion(pos1.localPosition, pos2.localPosition, pos3.localPosition, pos4.localPosition));
- }
- //点击拖拽的结束位置
- public void onEndPos(int index, Vector3 pos)
- {
- Debug.Log("pos end: " + pos);
- endPos = pos;
- if (beginPos == endPos) return;
- //Debug.Log(index+",最后的点:" + pos);
- //再记录一次最后的点
- SetLinePos();
- }
- //同步设置图片对应的位置到line
- public void SetLinePos()
- {
- //记录一个操作点的操作位置
- AddOldLinePosition();
- //设置线段的点
- SetRectanglePoints(linePosConversion(pos1.localPosition, pos2.localPosition, pos3.localPosition, pos4.localPosition));
- }
- void AddOldLinePosition()
- {
- Vector3[] v = new Vector3[4];
- pos1.GetWorldCorners(v);
- Vector3[] v1 = new Vector3[4];
- pos1.GetLocalCorners(v1);
- //for (int i = 0; i < 4; i++)
- //{
- // Debug.Log(i + " =1= " + v[i]);
- // Debug.Log(i + " =2= " + v1[i]);
- //}
- //记录一个操作点的操作位置
- List<Vector3> screenPositions = new List<Vector3>();
- screenPositions.Add(pos1.localPosition);
- screenPositions.Add(pos2.localPosition);
- screenPositions.Add(pos3.localPosition);
- screenPositions.Add(pos4.localPosition);
- LinePosition linePosition = new LinePosition();
- linePosition.index = oldLinePosition.Count;
- linePosition.pos = screenPositions;
- oldLinePosition.Add(linePosition);
- }
- //转换绘制线段的点
- List<Vector2> linePosConversion(Vector3 _pos1, Vector3 _pos2, Vector3 _pos3, Vector3 _pos4)
- {
- List<Vector2> _screenPositions = new List<Vector2>();
- //点为负数的增大 offset,正数减少 offset
- //Vector2 startPos1 = new Vector2(_pos1.x - pos1.rect.width * 0.5f + offset, _pos1.y - pos1.rect.height * 0.5f + offset);
- //Vector2 startPos2 = new Vector2(_pos2.x + pos2.rect.width * 0.5f - offset, _pos2.y - pos2.rect.height * 0.5f + offset);
- //Vector2 startPos3 = new Vector2(_pos3.x + pos3.rect.width * 0.5f - offset, _pos3.y + pos3.rect.height * 0.5f - offset);
- //Vector2 startPos4 = new Vector2(_pos4.x - pos4.rect.width * 0.5f + offset, _pos4.y + pos4.rect.height * 0.5f - offset);
- Vector2 startPos1 = new Vector2(_pos1.x + offset, _pos1.y + offset);
- Vector2 startPos2 = new Vector2(_pos2.x - offset, _pos2.y + offset);
- Vector2 startPos3 = new Vector2(_pos3.x - offset, _pos3.y - offset);
- Vector2 startPos4 = new Vector2(_pos4.x + offset, _pos4.y - offset);
- _screenPositions.Add(startPos1);
- _screenPositions.Add(startPos2);
- _screenPositions.Add(startPos3);
- _screenPositions.Add(startPos4);
- return _screenPositions;
- }
- void SetRectanglePoints(List<Vector2> screenPositions)
- {
- line.SetLine(screenPositions);
- }
- //撤回上一个元素
- public void onRecall()
- {
- // 获取并删除最后一个元素,并且保留一个元素
- if (oldLinePosition.Count > 1) // 确保列表不为空
- {
- // 获取回退的那个元素点
- LinePosition lastElement_second = oldLinePosition[oldLinePosition.Count - 2];
- // 获取最后一个元素
- //LinePosition lastElement = oldLinePosition[oldLinePosition.Count - 1];
- //Debug.Log(JsonUtility.ToJson(lastElement) + " = " + oldLinePosition.Count);
- oldLinePosition.RemoveAt(oldLinePosition.Count - 1); // 删除最后一个元素
- pos1.localPosition = lastElement_second.pos[0];
- pos2.localPosition = lastElement_second.pos[1];
- pos3.localPosition = lastElement_second.pos[2];
- pos4.localPosition = lastElement_second.pos[3];
- //设置线段的点
- SetRectanglePoints(linePosConversion(lastElement_second.pos[0], lastElement_second.pos[1], lastElement_second.pos[2], lastElement_second.pos[3]));
- }
- }
- //是不是从Demo界面进入该页面的
- public bool enterFromInfraredDemo { get; set; } = false;
- //是否从测试场景进入
- public bool enterFromZimWebCamera { get; set; } = false;
- //确认修改
- public void onConfirmation()
- {
- if (enterFromZimWebCamera)
- {
- ConfirmScreenLocateManualTest();
- if (oldLinePosition.Count > 1) // 确保列表不为空
- {
- LinePosition lastElement = oldLinePosition[oldLinePosition.Count - 1];
- oldLinePosition.Clear();
- oldLinePosition.Add(lastElement);
- }
- SaveLocalPos();
- AudioMgr.ins.PlayBtn();
- ViewManager2.HideView(ViewManager2.Path_InfraredScreenPositioningView);
- return;
- }
- if (!ConfirmScreenLocateManual()) return;
- if (oldLinePosition.Count > 1) // 确保列表不为空
- {
- LinePosition lastElement = oldLinePosition[oldLinePosition.Count - 1];
- oldLinePosition.Clear();
- oldLinePosition.Add(lastElement);
- }
- if (InfraredDemo.running)
- {
- //跳转入界面
- AudioMgr.ins.PlayBtn();
- if (!enterFromInfraredDemo)
- {
- //每次初始化重置一下引导
- InfraredDemo._ins.resetInfraredPlayerPrefs();
- //GameObject connectGuidanceView = ViewManager2.getGameObjectAndShowView(ViewManager2.Path_ConnectGuidanceView);
- //connectGuidanceView.GetComponent<ConnectGuidanceView>().showTextipInfrared();
- if (!PlayerPrefs.HasKey("hideInfraredBowAndArrow"))
- {
- //如果是红外连接成功,记录一个tag
- PlayerPrefs.SetInt("hideInfraredBowAndArrow", 1);
- }
- onEnterInfrared();
- }
- else {
- ViewManager2.HideView(ViewManager2.Path_InfraredScreenPositioningView);
- }
-
- }
- //存储一次节点
- SaveLocalPos();
- }
- //重置位置
- public void onReset()
- {
- oldLinePosition.Clear();
- // 获取屏幕的四个角的像素坐标
- Vector2 bottomLeft = new Vector2(0, 0);
- // 将屏幕像素坐标转换为 Canvas 的局部坐标
- Vector2 localBottomLeft;
- RectTransformUtility.ScreenPointToLocalPointInRectangle(canvasRectTransform, bottomLeft, null, out localBottomLeft);
- // 打印结果
- Debug.Log("Local Bottom Left: " + localBottomLeft);
- //int _x = Mathf.FloorToInt(Mathf.Abs(localBottomLeft.x) - 120), _y = Mathf.FloorToInt(Mathf.Abs(localBottomLeft.y) - 77);
- int _x = Mathf.FloorToInt(Mathf.Abs(localBottomLeft.x)), _y = Mathf.FloorToInt(Mathf.Abs(localBottomLeft.y));
- pos1.anchoredPosition = new Vector3(-_x, -_y, 0); //Bottom Left
- pos2.anchoredPosition = new Vector3(_x, -_y, 0); //Bottom Right
- pos3.anchoredPosition = new Vector3(_x, _y, 0); //Top Right
- pos4.anchoredPosition = new Vector3(-_x, _y, 0); //Top Left
- //pos1.anchoredPosition = new Vector3(_x, _y, 0);
- //pos2.anchoredPosition = new Vector3(-_x, _y, 0);
- //pos3.anchoredPosition = new Vector3(-_x, -_y, 0);
- //pos4.anchoredPosition = new Vector3(_x, -_y, 0);
- //设置一次位置
- SetLinePos();
- btnRecordInfrared.Reset();
- ScreenLocate.Main.ScreenIdentification.SetScreenQuad(null);
- }
- #endregion
- List<Vector2> _locatePointList = new();
- float _texWidth;
- float _texHeight;
- void RecordLocatePoint(RectTransform p, Vector2 pivot)
- {
- Vector2 pos = JCUnityLib.RectTransformUtils.GetPositionByPivot(p, pivot);
- pos.x = Mathf.Clamp01(pos.x / Screen.width);
- pos.y = Mathf.Clamp01(pos.y / Screen.height);
- _locatePointList.Add(pos);
- }
- bool ConfirmScreenLocateManual()
- {
- if (InfraredDemo.running)
- {
- //渲染截图
- Texture2D texture2D = InfraredDemo.infraredCameraHelper.EnterScreenLocateManual();
- if (texture2D == null)
- {
- Debug.Log("EnterScreenLocateManual = null");
- InfraredDemo.infraredCameraHelper.QuitScreenLocateManual(null);
- return false;
- }
- _locatePointList.Clear();
- _texWidth = texture2D.width;
- _texHeight = texture2D.height;
- RecordLocatePoint(pos1, new Vector2(0, 0));
- RecordLocatePoint(pos2, new Vector2(1, 0));
- RecordLocatePoint(pos3, new Vector2(1, 1));
- RecordLocatePoint(pos4, new Vector2(0, 1));
- //RecordLocatePoint(pos1, new Vector2(0.5f, 0.5f));
- //RecordLocatePoint(pos2, new Vector2(0.5f, 0.5f));
- //RecordLocatePoint(pos3, new Vector2(0.5f, 0.5f));
- //RecordLocatePoint(pos4, new Vector2(0.5f, 0.5f));
- InfraredDemo.infraredCameraHelper.QuitScreenLocateManual(_locatePointList);
- FindObjectOfType<InfraredDemo>().SetLocatePointsToCameraRender(_locatePointList, 1, 1);
- //setPointsLocation(_locatePointList, pointsParent.gameObject, !bAuto);
- //同步数据
- ScreenLocate.quadUnityVectorList.Clear();
- ScreenLocate.quadUnityVectorList.Add(_locatePointList[0]);
- ScreenLocate.quadUnityVectorList.Add(_locatePointList[1]);
- //两个点切换,顺序不一样
- ScreenLocate.quadUnityVectorList.Add(_locatePointList[3]);
- ScreenLocate.quadUnityVectorList.Add(_locatePointList[2]);
- ScreenLocate.SaveScreenLocateVectorList();
- return true;
- }
- return false;
- }
- void ConfirmScreenLocateManualTest()
- {
- //渲染截图
- ScreenLocate _screenLocate = FindAnyObjectByType<ScreenLocate>();
- Texture2D texture2D = _screenLocate.EnterScreenLocateManual();
- if (texture2D == null)
- {
- _screenLocate.QuitScreenLocateManual(null);
- return;
- }
- _locatePointList.Clear();
- _texWidth = texture2D.width;
- _texHeight = texture2D.height;
- RecordLocatePoint(pos1, new Vector2(0, 0));
- RecordLocatePoint(pos2, new Vector2(1, 0));
- RecordLocatePoint(pos3, new Vector2(1, 1));
- RecordLocatePoint(pos4, new Vector2(0, 1));
- _screenLocate.QuitScreenLocateManual(_locatePointList);
- //FindObjectOfType<InfraredDemo>().SetLocatePointsToCameraRender(_locatePointList, _texWidth, _texHeight);
- setPointsLocation(_locatePointList,GameObject.Find("WebCameraView/CameraImage0/ScreenQuad"));
- setPointsLocation(_locatePointList,pointsParent.gameObject,!bAuto);
- //同步数据
- ScreenLocate.quadUnityVectorList.Clear();
- ScreenLocate.quadUnityVectorList.Add(new Vector2(_locatePointList[0].x, _locatePointList[0].y));
- ScreenLocate.quadUnityVectorList.Add(new Vector2(_locatePointList[1].x, _locatePointList[1].y));
- //两个点切换,顺序不一样
- ScreenLocate.quadUnityVectorList.Add(new Vector2(_locatePointList[3].x, _locatePointList[3].y));
- ScreenLocate.quadUnityVectorList.Add(new Vector2(_locatePointList[2].x, _locatePointList[2].y));
- ScreenLocate.SaveScreenLocateVectorList();
- var lo = new Vector2(-0.5f, -0.5f);
- ScreenLocate.Main.UILineGenerator.Points = new Vector2[4] {
- 2 * (_locatePointList[0] + lo),
- 2 * (_locatePointList[1] + lo),
- 2 * (_locatePointList[2] + lo),
- 2 * (_locatePointList[3] + lo) };
- }
- void setPointsLocation(List<Vector2> targetList ,GameObject pointsTF2,bool active = true) {
- //GameObject pointsTF2 = GameObject.Find("WebCameraView/CameraImage0/ScreenQuad");
- pointsTF2.SetActive(active);
- if (pointsTF2.transform.childCount == targetList.Count)
- {
- Vector2 texSize = new Vector2(_texWidth, _texHeight);
- for (int i = 0; i < pointsTF2.transform.childCount; i++)
- {
- Transform pointTF = pointsTF2.transform.GetChild(i);
- Vector2 pos = targetList[i];
- pointTF.localPosition = pos.pixelToLocalPosition_AnchorCenter(Vector2.one, pointsTF2.GetComponent<RectTransform>().rect);
- pointTF.gameObject.SetActive(true);
- }
- }
- }
- void SaveLocalPos()
- {
- List<Vector3> screenPositions = new List<Vector3>();
- screenPositions.Add(pos1.anchoredPosition);
- screenPositions.Add(pos2.anchoredPosition);
- screenPositions.Add(pos3.anchoredPosition);
- screenPositions.Add(pos4.anchoredPosition);
- string saveStr = string.Join(';', screenPositions.Select(v => $"{v.x},{v.y}")); //,{v.z}
- Debug.Log("Local UI Position: " + saveStr);
- PlayerPrefs.SetString("ScreenPositioningView", saveStr);
- }
- void GetLocalPos()
- {
- string posListStr = PlayerPrefs.GetString("ScreenPositioningView", "");
- if (!string.IsNullOrWhiteSpace(posListStr))
- {
- List<Vector2> posList = posListStr.Split(';')
- .Select(s =>
- {
- string[] parts = s.Split(',');
- return new Vector2(float.Parse(parts[0]), float.Parse(parts[1]));
- })
- .ToList();
- pos1.anchoredPosition = posList[0];
- pos2.anchoredPosition = posList[1];
- pos3.anchoredPosition = posList[2];
- pos4.anchoredPosition = posList[3];
- SetRectanglePoints(linePosConversion(pos1.localPosition, pos2.localPosition, pos3.localPosition, pos4.localPosition));
- }
- }
- #region 按钮颜色切换
- private void OnButtonClick(Button button)
- {
- // 切换按钮颜色
- ColorBlock colors = button.colors;
- colors.normalColor = highlightedColor;
- colors.highlightedColor = highlightedColor;
- button.colors = colors;
- // 切换字体颜色
- Text buttonText = button.GetComponentInChildren<Text>();
- buttonText.color = highlightedTextColor;
- }
- private void ResetButton(Button button)
- {
- // 重置按钮颜色
- ColorBlock colors = button.colors;
- colors.normalColor = normalColor;
- colors.highlightedColor = normalColor;
- button.colors = colors;
- // 重置字体颜色
- Text buttonText = button.GetComponentInChildren<Text>();
- buttonText.color = normalTextColor;
- }
- #endregion
- #region 标定完成之后进入游戏界面
- void onEnterInfrared()
- {
- //添加进入射箭场景
- if (PlayerPrefs.GetInt("entry-guider-infrared-" + LoginMgr.myUserInfo.id, 0) == 0)
- {
- Debug.Log("-----进入射箭场景!");
- NewUserGuiderManager newUserGuiderManager = FindObjectOfType<NewUserGuiderManager>();
- newUserGuiderManager.curConfigKey = "开始-红外调整";
- newUserGuiderManager.isNewModule = AimHandler.ins.aimDeviceInfo.type == (int)AimDeviceType.HOUYIPRO || AimHandler.ins.aimDeviceInfo.type == (int)AimDeviceType.Gun || AimHandler.ins.aimDeviceInfo.type == (int)AimDeviceType.ARTEMISPRO;
- //进入射箭场景
- GlobalData.pkMatchType = PKMatchType.None;
- GameMgr.gameType = 1;
- //射一箭回到连接页面,Device.view
- GameMgr.bNavBack = true;
- GameMgr.bShowDistance = false;
- AimHandler.ins.bInitOne = false;//true
- //关闭计时器
- GameMgr.turnOffTimer = true;
- //关闭左边靶子和底部速度栏
- GameMgr.HideTargetView = true;
- GameMgr.HideBillboard = true;
- GameMgr.ButtonCount = 0;
- UnityEngine.SceneManagement.SceneManager.LoadScene(
- "Game", UnityEngine.SceneManagement.LoadSceneMode.Single);
- PlayerPrefs.SetInt("entry-guider-infrared-" + LoginMgr.myUserInfo.id, 1);
- }
- else
- {
- Debug.Log("-----跳转回连接界面!");
- //如不是第一次,则应该跳转回连接界面
- ViewMgr.Instance.DestroyView<SmartArcheryView>();
- ViewManager2.HideView(ViewManager2.Path_ConnectGuidanceView);
- }
- }
- #endregion
- }
|