unityzgy/Assets/Scripts/Managers/Surveyor.cs
ayuan9957 bf12e02276 feat: 多语言本地化系统 - 支持中/英/法/俄实时切换
- LocalizationManager: 新增翻译表(SetFormatted/SetDuration/LocalizeOperateMsg)
- LoginPanel: InputField placeholder本地化、字体颜色保持
- HistoryPanel: 用时数据本地化、placeholder本地化
- RecordDetailPanel: 操作详情消息本地化(LanguageChanged重建)
- AppraiseWindowBase: 评价等级本地化、操作消息重建
- EditorAppraiser: 所有评估消息改用InjectOperateMsgLocalized
- StudentOperateRecorder: 新增InjectOperateMsgLocalized方法
- LocalizationLanguageTestBar: 单例模式、ScreenSpaceOverlay筛选
- 字体切换时保留颜色和verticalOverflow
2026-07-16 10:05:59 +08:00

84 lines
2.4 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using XFramework.Objects;
//测量功能实现类
public class Surveyor
{
GameObject rulerPrefab;
RulerInstanceCtrl currentRuler;//当前待测量的点
public List<GameObject> rulers = new List<GameObject>();
public Surveyor(GameObject rulerPrefab)
{
this.rulerPrefab = rulerPrefab;
}
/// <summary>
/// 循环函数 监听测量输入
/// </summary>
public void Update()
{
if (EventSystem.current != null && EventSystem.current.IsPointerOverGameObject()) return; //射线检测时屏蔽UI部分
if (Input.GetMouseButtonDown(0))//鼠标点击地面时
{
Vector3 point = GetRayHitPoint();
if (point != Vector3.zero)
SetPoint(point);
}
if (currentRuler)//当前测量未完成时 不断更新第二个测量点位
{
Vector3 point = GetRayHitPoint();
if (point != Vector3.zero)
currentRuler?.SetSecondPos(point);
}
}
//结束测量 收起所有的尺子
public void StopCL()
{
for (int i = 0; i < rulers.Count; i++)
{
ObjectPool.Instance.Destroy(rulers[i].gameObject);
}
}
/// <summary>
/// 设置待测量点 第一个点生成测量实例 第二个点完成一次测量
/// </summary>
void SetPoint(Vector3 point)
{
if (currentRuler == null)//当前没有等待设置第二个点的尺子 重新复制一把 并将该点位确认为起点
{
currentRuler = ObjectPool.Instance.Instantiate(rulerPrefab).GetComponent<RulerInstanceCtrl>();
rulers.Add(currentRuler.gameObject);
currentRuler.SetFirstPos(point);
}
else//当前有等待设置第二个点的尺子 确定第二点位 即放下尺子
{
currentRuler.SetSecondPos(point);
currentRuler = null;
}
}
//获取点击的地面位置
Vector3 GetRayHitPoint()
{
RaycastHit hit;//鼠标射线检测
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit, 2000, LayerMask.GetMask("Floor")))
{
return hit.point;
}
return Vector3.zero;
}
}