- LocalizationManager: 新增翻译表(SetFormatted/SetDuration/LocalizeOperateMsg) - LoginPanel: InputField placeholder本地化、字体颜色保持 - HistoryPanel: 用时数据本地化、placeholder本地化 - RecordDetailPanel: 操作详情消息本地化(LanguageChanged重建) - AppraiseWindowBase: 评价等级本地化、操作消息重建 - EditorAppraiser: 所有评估消息改用InjectOperateMsgLocalized - StudentOperateRecorder: 新增InjectOperateMsgLocalized方法 - LocalizationLanguageTestBar: 单例模式、ScreenSpaceOverlay筛选 - 字体切换时保留颜色和verticalOverflow
187 lines
6.4 KiB
C#
187 lines
6.4 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEngine.Events;
|
||
using UnityEngine.EventSystems;
|
||
|
||
namespace GOEventSystem
|
||
{
|
||
public class EventSystem_Camera : MonoBehaviour
|
||
{
|
||
Camera rayCamera;
|
||
bool isUsed = true;//事件监测系统是否启用
|
||
bool hoverTriggerEnter;
|
||
|
||
Transform hoverRecord;//记录当前触发hover的物体
|
||
public float rayDistacne = 800;
|
||
public LayerMask rayGOLayer;
|
||
|
||
GOPointerEventData eventData = new GOPointerEventData();
|
||
[Header("Hovr检测的灵敏度,检测时间间隔")]
|
||
public float hoverCheckTime = 0.2f;//射线重复检测时才会触发hover 理论上触发最大时长为hoverCheckTime*2-0.02f;
|
||
float upTime;//一帧运行时间
|
||
float timer;//计时器
|
||
public UnityAction<List<int>> clickOperatorsEvent;
|
||
public UnityAction<List<int>> doubleClickOperatorsEvent;
|
||
public UnityAction clickOutUIEvent;
|
||
// Start is called before the first frame update
|
||
void Start()
|
||
{
|
||
rayGOLayer = ~(1 << -1);
|
||
rayCamera = this.GetComponent<Camera>();
|
||
if (rayCamera == null && Camera.main)
|
||
{
|
||
rayCamera = Camera.main;
|
||
}
|
||
|
||
if (!rayCamera)
|
||
{
|
||
isUsed = false;
|
||
Debug.Log("无有效检测相机,EventSystem_Camera置位不可用模式");
|
||
}
|
||
upTime = Time.fixedDeltaTime;
|
||
timer = hoverCheckTime;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 某些情况下可关闭或再次开启事件检测系统
|
||
/// </summary>
|
||
/// <param name="used"></param>
|
||
public void SetUsed(bool used)
|
||
{
|
||
isUsed = used;
|
||
if (!isUsed && hoverRecord != null&& hoverTriggerEnter)
|
||
{
|
||
hoverRecord.GetComponent<IPointerHoverHandler>().OnHoverExit(eventData);
|
||
hoverRecord = null;
|
||
}
|
||
}
|
||
|
||
// Update is called once per frame
|
||
void Update()
|
||
{
|
||
if (!isUsed) return;
|
||
if (EventSystem.current!=null&& EventSystem.current.IsPointerOverGameObject()) return;//UI触发时不做检测
|
||
//HoverCheck();
|
||
ClickCheck();
|
||
}
|
||
|
||
void HoverCheck()
|
||
{
|
||
timer-= upTime;
|
||
if (timer > 0) return;
|
||
timer = hoverCheckTime;
|
||
Transform rayHit = CameraRay();
|
||
if (rayHit == null)//没有检测到物体
|
||
{
|
||
if (hoverRecord && hoverTriggerEnter)
|
||
{
|
||
hoverRecord.GetComponentInParent<IPointerHoverHandler>()?.OnHoverExit(eventData);
|
||
}
|
||
hoverRecord = null;
|
||
hoverTriggerEnter = false;
|
||
}
|
||
else if (rayHit == hoverRecord) //检测到的物体与记录的物体是重复的
|
||
{
|
||
if (hoverTriggerEnter) return;//避免hover重复触发
|
||
hoverTriggerEnter = true;
|
||
rayHit.GetComponentInParent<IPointerHoverHandler>()?.OnHoverEnter(eventData);
|
||
}
|
||
else//检测到其他物体时
|
||
{
|
||
if (hoverRecord&&hoverTriggerEnter)
|
||
hoverRecord.GetComponentInParent<IPointerHoverHandler>()?.OnHoverExit(eventData);
|
||
hoverTriggerEnter = false;
|
||
hoverRecord = rayHit;
|
||
}
|
||
}
|
||
|
||
private float clickTimer;
|
||
[Header("双击检测的灵敏度,最大触发时间间隔")]
|
||
public float DoubClickTime = 0.2f;//多长时间内再次点击时触发双击
|
||
void ClickCheck()
|
||
{
|
||
if (clickTimer > 0)
|
||
{
|
||
clickTimer -= Time.deltaTime;
|
||
}
|
||
if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1))
|
||
{
|
||
clickOutUIEvent?.Invoke();//点击地形空白位置
|
||
}
|
||
if (Input.GetMouseButtonDown(0))
|
||
{
|
||
eventData.gOInputButton = GOInputButton.Left;
|
||
if (clickTimer <= 0)
|
||
{
|
||
Click();
|
||
}
|
||
else
|
||
DoubleClick();
|
||
}
|
||
}
|
||
|
||
List<int> clickOperators = new List<int>();
|
||
void Click()
|
||
{
|
||
clickTimer = DoubClickTime;
|
||
|
||
CameraRay()?.GetComponentInParent<IPointerClickHandler>()?.OnPointerClick(eventData);
|
||
//RaycastHit[] raycastHits = CameraRayCastAll();
|
||
//if (raycastHits.Length > 0)
|
||
//{
|
||
// clickOperators.Clear();
|
||
// for (int i = 0; i < raycastHits.Length; i++)
|
||
// {
|
||
// clickOperators.Add(raycastHits[i].transform.GetComponent<OperatorCtrl>().id);
|
||
// //Debug.Log("Click Trigger"+ raycastHits[i].transform.name);
|
||
// }
|
||
// clickOperatorsEvent?.Invoke(clickOperators);
|
||
//}
|
||
}
|
||
|
||
private void DoubleClick()
|
||
{
|
||
CameraRay()?.GetComponentInParent<IPointerDoubleClickHandler>()?.OnPointerDoubleClick(eventData);
|
||
|
||
//RaycastHit[] raycastHits = CameraRayCastAll();
|
||
//if (raycastHits.Length > 0)
|
||
//{
|
||
// clickOperators.Clear();
|
||
// for (int i = 0; i < raycastHits.Length; i++)
|
||
// {
|
||
// clickOperators.Add(raycastHits[i].transform.GetComponent<OperatorCtrl>().id);
|
||
// //Debug.Log("Click Trigger"+ raycastHits[i].transform.name);
|
||
// }
|
||
// doubleClickOperatorsEvent?.Invoke(clickOperators);
|
||
//}
|
||
}
|
||
|
||
Ray ray;
|
||
RaycastHit raycastHit;
|
||
|
||
Transform CameraRay()
|
||
{
|
||
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
||
if (Physics.Raycast(ray, out raycastHit, rayDistacne, rayGOLayer))
|
||
{
|
||
return raycastHit.collider.transform;
|
||
}
|
||
else
|
||
return null;
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 获取射线检测到的所有物体
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
RaycastHit[] CameraRayCastAll()
|
||
{
|
||
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
||
return Physics.RaycastAll(ray, rayDistacne, rayGOLayer);
|
||
}
|
||
}
|
||
}
|