|
|
@@ -1,36 +1,37 @@
|
|
|
-using UnityEngine;
|
|
|
+锘縰sing UnityEngine;
|
|
|
using UnityEngine.UI;
|
|
|
using System.Collections.Generic;
|
|
|
using System;
|
|
|
using ZIM.Unity;
|
|
|
using System.Linq;
|
|
|
+using o0InfraredLocate.ZIM;
|
|
|
|
|
|
public class PointMarker : MonoBehaviour
|
|
|
{
|
|
|
- //public Text instructionText; // 用于显示提示文字
|
|
|
- [Tooltip("标记页面标题提示")]
|
|
|
+ //public Text instructionText; // 鐢ㄤ簬鏄剧ず鎻愮ず鏂囧瓧
|
|
|
+ [Tooltip("鏍囪�椤甸潰鏍囬�鎻愮ず")]
|
|
|
[SerializeField] TextAutoLanguage2 instructionText;
|
|
|
- public Button undoButton; // 撤回按钮
|
|
|
- public Button completeButton; // 完成按钮
|
|
|
- public bool bComplete = false;// 是否完成
|
|
|
- public GameObject markerPrefab; // 用于表示标记的UI元素,可能是一个小图标(如枪)
|
|
|
+ public Button undoButton; // 鎾ゅ洖鎸夐挳
|
|
|
+ public Button completeButton; // 瀹屾垚鎸夐挳
|
|
|
+ public bool bComplete = false;// 鏄�惁瀹屾垚
|
|
|
+ public GameObject markerPrefab; // 鐢ㄤ簬琛ㄧず鏍囪�鐨刄I鍏冪礌锛屽彲鑳芥槸涓€涓�皬鍥炬爣锛堝�鏋�級
|
|
|
|
|
|
- // 新增父对象,用于存放标记的物体
|
|
|
- public Transform markerParent; // 标记物体的父对象(例如Canvas中的一个空物体)
|
|
|
+ // 鏂板�鐖跺�璞★紝鐢ㄤ簬瀛樻斁鏍囪�鐨勭墿浣�
|
|
|
+ public Transform markerParent; // 鏍囪�鐗╀綋鐨勭埗瀵硅薄锛堜緥濡侰anvas涓�殑涓€涓�┖鐗╀綋锛�
|
|
|
|
|
|
- public Image[] hintImages; // 依次存放左上、右上、右下、左下四个提示图片
|
|
|
+ public Image[] hintImages; // 渚濇�瀛樻斁宸︿笂銆佸彸涓娿€佸彸涓嬨€佸乏涓嬪洓涓�彁绀哄浘鐗�
|
|
|
|
|
|
Vector2 oldPoint = Vector2.zero;
|
|
|
private List<Vector2> markedPoints = new List<Vector2>();
|
|
|
- // { "左上", "右上", "右下", "左下" }
|
|
|
+ // { "宸︿笂", "鍙充笂", "鍙充笅", "宸︿笅" }
|
|
|
private string[] directions = { "TipTopLeft", "TipTopRight", "TipBottomRight", "TipBottomLeft" };
|
|
|
- private int currentPointIndex = 0; // 当前需要标记的点的索引
|
|
|
- private List<GameObject> markerObjects = new List<GameObject>(); // 记录标记物体
|
|
|
+ private int currentPointIndex = 0; // 褰撳墠闇€瑕佹爣璁扮殑鐐圭殑绱㈠紩
|
|
|
+ private List<GameObject> markerObjects = new List<GameObject>(); // 璁板綍鏍囪�鐗╀綋
|
|
|
|
|
|
[SerializeField] InfraredScreenPositioningView infraredScreenPositioningView;
|
|
|
|
|
|
- [Tooltip("存在校准数据时候显示")]
|
|
|
- [SerializeField] ZIM.LineGenerator line;//开始显示屏幕线条
|
|
|
+ [Tooltip("瀛樺湪鏍″噯鏁版嵁鏃跺€欐樉绀�")]
|
|
|
+ [SerializeField] ZIM.LineGenerator line;//寮€濮嬫樉绀哄睆骞曠嚎鏉�
|
|
|
|
|
|
|
|
|
void Start()
|
|
|
@@ -39,10 +40,10 @@ public class PointMarker : MonoBehaviour
|
|
|
|
|
|
UpdateInstruction();
|
|
|
undoButton.onClick.AddListener(UndoLastPoint);
|
|
|
- completeButton.onClick.AddListener(CompletePoint); // 初始化时隐藏完成按钮
|
|
|
+ completeButton.onClick.AddListener(CompletePoint); // 鍒濆�鍖栨椂闅愯棌瀹屾垚鎸夐挳
|
|
|
bComplete = false;
|
|
|
|
|
|
- // 初始化时,显示第一个提示图片,其余隐藏
|
|
|
+ // 鍒濆�鍖栨椂锛屾樉绀虹�涓€涓�彁绀哄浘鐗囷紝鍏朵綑闅愯棌
|
|
|
ShowHintImage(0);
|
|
|
|
|
|
}
|
|
|
@@ -51,15 +52,15 @@ public class PointMarker : MonoBehaviour
|
|
|
if (AimHandler.ins) AimHandler.ins.OnCrossBtnEvent -= OnRecordInfrared;
|
|
|
}
|
|
|
private float lastClickTime = 0f;
|
|
|
- private float doubleClickThreshold = 0.3f; // 双击间隔时间,单位:秒
|
|
|
+ private float doubleClickThreshold = 0.3f; // 鍙屽嚮闂撮殧鏃堕棿锛屽崟浣嶏細绉�
|
|
|
void Update()
|
|
|
{
|
|
|
- if (Input.GetMouseButtonDown(0)) // 检测左键按下
|
|
|
+ if (Input.GetMouseButtonDown(0)) // 妫€娴嬪乏閿�寜涓�
|
|
|
{
|
|
|
float currentTime = Time.time;
|
|
|
if (currentTime - lastClickTime <= doubleClickThreshold)
|
|
|
{
|
|
|
- // 双击检测成功,执行触发逻辑
|
|
|
+ // 鍙屽嚮妫€娴嬫垚鍔燂紝鎵ц�瑙﹀彂閫昏緫
|
|
|
if (currentPointIndex >= 4) return;
|
|
|
|
|
|
var mouse = Input.mousePosition;
|
|
|
@@ -71,10 +72,10 @@ public class PointMarker : MonoBehaviour
|
|
|
Vector2 pos = new Vector2(u * ScreenLocate.Main.getUVCTexture.width, v * ScreenLocate.Main.getUVCTexture.height);
|
|
|
//markedPoints.Add(pos);
|
|
|
oldPoint = new Vector2(u, v);
|
|
|
- // 设置标记的位置
|
|
|
+ // 璁剧疆鏍囪�鐨勪綅缃�
|
|
|
MarkPoint(new Vector2(u, v).pixelToLocalPosition_AnchorCenter(new Vector2(1, 1), markerParent.GetComponent<RectTransform>().rect));
|
|
|
}
|
|
|
- lastClickTime = currentTime; // 更新上一次点击时间
|
|
|
+ lastClickTime = currentTime; // 鏇存柊涓婁竴娆$偣鍑绘椂闂�
|
|
|
}
|
|
|
//#if UNITY_EDITOR
|
|
|
//if (Input.GetKeyDown(KeyCode.Alpha6) || Input.GetMouseButtonDown(1))
|
|
|
@@ -90,13 +91,13 @@ public class PointMarker : MonoBehaviour
|
|
|
// v = Math.Clamp(v, 0, 1);
|
|
|
// Vector2 pos = new Vector2(u * ScreenLocate.Main.getUVCTexture.width, v * ScreenLocate.Main.getUVCTexture.height);
|
|
|
// markedPoints.Add(pos);
|
|
|
- // // 设置标记的位置
|
|
|
+ // // 璁剧疆鏍囪�鐨勪綅缃�
|
|
|
// MarkPoint(new Vector2(u, v).pixelToLocalPosition_AnchorCenter(new Vector2(1, 1), markerParent.GetComponent<RectTransform>().rect));
|
|
|
//}
|
|
|
//#endif
|
|
|
}
|
|
|
/// <summary>
|
|
|
- /// 记录红外点
|
|
|
+ /// 璁板綍绾㈠�鐐�
|
|
|
/// </summary>
|
|
|
public void OnRecordInfrared()
|
|
|
{
|
|
|
@@ -113,26 +114,26 @@ public class PointMarker : MonoBehaviour
|
|
|
void MarkPoint(Vector2 point)
|
|
|
{
|
|
|
if (!infraredScreenPositioningView.IsPointInMaskLine(point)) {
|
|
|
- Debug.Log("不在梯形内部!");
|
|
|
+ Debug.Log("涓嶅湪姊�舰鍐呴儴锛�");
|
|
|
instructionText.SetTextKey("TipMarkerError");
|
|
|
return;
|
|
|
}
|
|
|
- // 创建标记物体,并将其作为markerParent的子对象
|
|
|
+ // 鍒涘缓鏍囪�鐗╀綋锛屽苟灏嗗叾浣滀负markerParent鐨勫瓙瀵硅薄
|
|
|
GameObject marker = Instantiate(markerPrefab, markerParent);
|
|
|
marker.SetActive(true);
|
|
|
marker.transform.localPosition = point;
|
|
|
markerObjects.Add(marker);
|
|
|
- //绘制连线
|
|
|
+ //缁樺埗杩炵嚎
|
|
|
markedPoints.Add(point);
|
|
|
UpdateLine();
|
|
|
|
|
|
- // 隐藏当前的提示图片,显示下一个提示图片
|
|
|
+ // 闅愯棌褰撳墠鐨勬彁绀哄浘鐗囷紝鏄剧ず涓嬩竴涓�彁绀哄浘鐗�
|
|
|
currentPointIndex++;
|
|
|
ShowHintImage(currentPointIndex);
|
|
|
|
|
|
UpdateInstruction();
|
|
|
|
|
|
- // 如果已经标记了四个点,显示完成按钮
|
|
|
+ // 濡傛灉宸茬粡鏍囪�浜嗗洓涓�偣锛屾樉绀哄畬鎴愭寜閽�
|
|
|
if (currentPointIndex == 4)
|
|
|
{
|
|
|
Vector2[] points = {
|
|
|
@@ -142,7 +143,7 @@ public class PointMarker : MonoBehaviour
|
|
|
markerObjects[3].transform.localPosition,
|
|
|
};
|
|
|
bool result = infraredScreenPositioningView.IsValidQuadrilateral(points);
|
|
|
- Debug.Log(result ? "是有效的四边形" : "不是有效的四边形");
|
|
|
+ Debug.Log(result ? "鏄�湁鏁堢殑鍥涜竟褰�" : "涓嶆槸鏈夋晥鐨勫洓杈瑰舰");
|
|
|
if (result)
|
|
|
{
|
|
|
instructionText.SetTextKey("TipMarkComplete");
|
|
|
@@ -150,7 +151,7 @@ public class PointMarker : MonoBehaviour
|
|
|
bComplete = true;
|
|
|
}
|
|
|
else {
|
|
|
- //不是有效是四边形时候,回退 一个
|
|
|
+ //涓嶆槸鏈夋晥鏄�洓杈瑰舰鏃跺€欙紝鍥為€€ 涓€涓�
|
|
|
//instructionText.SetTextKey("TipMarkerError");
|
|
|
PopupMgr.ins.ShowTipTop(TextAutoLanguage2.GetTextByKey("TipQuadError"));
|
|
|
UndoLastPoint();
|
|
|
@@ -162,29 +163,29 @@ public class PointMarker : MonoBehaviour
|
|
|
{
|
|
|
if (currentPointIndex > 0)
|
|
|
{
|
|
|
- // 移除最后一个标记的点
|
|
|
+ // 绉婚櫎鏈€鍚庝竴涓�爣璁扮殑鐐�
|
|
|
markedPoints.RemoveAt(markedPoints.Count - 1);
|
|
|
UpdateLine();
|
|
|
- // 删除最后一个标记的物体
|
|
|
+ // 鍒犻櫎鏈€鍚庝竴涓�爣璁扮殑鐗╀綋
|
|
|
Destroy(markerObjects[markerObjects.Count - 1]);
|
|
|
markerObjects.RemoveAt(markerObjects.Count - 1);
|
|
|
|
|
|
- // 回退到上一个提示图片
|
|
|
+ // 鍥為€€鍒颁笂涓€涓�彁绀哄浘鐗�
|
|
|
currentPointIndex--;
|
|
|
ShowHintImage(currentPointIndex);
|
|
|
|
|
|
UpdateInstruction();
|
|
|
}
|
|
|
|
|
|
- // 隐藏完成按钮
|
|
|
+ // 闅愯棌瀹屾垚鎸夐挳
|
|
|
bComplete = false;
|
|
|
}
|
|
|
/// <summary>
|
|
|
- /// 移除全部标记,选择自动和半自动数据界面返回时候调用
|
|
|
+ /// 绉婚櫎鍏ㄩ儴鏍囪�锛岄€夋嫨鑷�姩鍜屽崐鑷�姩鏁版嵁鐣岄潰杩斿洖鏃跺€欒皟鐢�
|
|
|
/// </summary>
|
|
|
public void UndoAllPoints()
|
|
|
{
|
|
|
- // 移除所有标记物体
|
|
|
+ // 绉婚櫎鎵€鏈夋爣璁扮墿浣�
|
|
|
foreach (var marker in markerObjects)
|
|
|
{
|
|
|
Destroy(marker);
|
|
|
@@ -193,21 +194,21 @@ public class PointMarker : MonoBehaviour
|
|
|
|
|
|
markedPoints.Clear();
|
|
|
UpdateLine();
|
|
|
- // 重置索引
|
|
|
+ // 閲嶇疆绱㈠紩
|
|
|
currentPointIndex = 0;
|
|
|
|
|
|
- // 更新提示图片和说明
|
|
|
+ // 鏇存柊鎻愮ず鍥剧墖鍜岃�鏄�
|
|
|
ShowHintImage(currentPointIndex);
|
|
|
UpdateInstruction();
|
|
|
|
|
|
- // 隐藏完成按钮
|
|
|
+ // 闅愯棌瀹屾垚鎸夐挳
|
|
|
bComplete = false;
|
|
|
}
|
|
|
|
|
|
void UpdateLine() {
|
|
|
if (line.gameObject.activeSelf) {
|
|
|
RectTransform rectTransform = markerParent as RectTransform;
|
|
|
- Vector2 pivot = rectTransform.pivot; // 获取父物体的 pivot 值
|
|
|
+ Vector2 pivot = rectTransform.pivot; // 鑾峰彇鐖剁墿浣撶殑 pivot 鍊�
|
|
|
Vector2 texSize = rectTransform.rect.size;
|
|
|
line.Points = InfraredDemo._ins.ConvertPointsToCoordinates(markedPoints.ToArray(), texSize, pivot);
|
|
|
}
|
|
|
@@ -222,7 +223,7 @@ public class PointMarker : MonoBehaviour
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 显示当前需要的提示图片,并隐藏其余提示图片
|
|
|
+ // 鏄剧ず褰撳墠闇€瑕佺殑鎻愮ず鍥剧墖锛屽苟闅愯棌鍏朵綑鎻愮ず鍥剧墖
|
|
|
void ShowHintImage(int index)
|
|
|
{
|
|
|
for (int i = 0; i < hintImages.Length; i++)
|
|
|
@@ -234,7 +235,7 @@ public class PointMarker : MonoBehaviour
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
- /// 如果没有数据时候,可能需要隐藏渲染
|
|
|
+ /// 濡傛灉娌℃湁鏁版嵁鏃跺€欙紝鍙�兘闇€瑕侀殣钘忔覆鏌�
|
|
|
/// </summary>
|
|
|
/// <param name="bShow"></param>
|
|
|
public void ShowHintImageParent(bool bShow)
|
|
|
@@ -246,12 +247,12 @@ public class PointMarker : MonoBehaviour
|
|
|
}
|
|
|
void CompletePoint() {
|
|
|
if (!bComplete) {
|
|
|
- //Debug.Log("未完成");
|
|
|
- //todo,加提示
|
|
|
+ //Debug.Log("鏈�畬鎴�");
|
|
|
+ //todo锛屽姞鎻愮ず
|
|
|
PopupMgr.ins.ShowTipTop(TextAutoLanguage2.GetTextByKey("Incomplete"));
|
|
|
return;
|
|
|
}
|
|
|
- //完成,下一步
|
|
|
+ //瀹屾垚锛屼笅涓€姝�
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
{
|
|
|
int index = i;
|
|
|
@@ -259,9 +260,9 @@ public class PointMarker : MonoBehaviour
|
|
|
}
|
|
|
infraredScreenPositioningView.onFinishManualToAutomatic();
|
|
|
|
|
|
- ////清空数据
|
|
|
+ ////娓呯┖鏁版嵁
|
|
|
//currentPointIndex = 0;
|
|
|
- ////清空生成的数据
|
|
|
+ ////娓呯┖鐢熸垚鐨勬暟鎹�
|
|
|
//markerObjects.Clear();
|
|
|
//foreach (Transform i in markerParent.transform)
|
|
|
// Destroy(i.gameObject);
|