@@ -23,6 +23,12 @@ namespace Ichni.Editor
|
||||
private List<SelectionConnector> lastHitConnectors = new List<SelectionConnector>();
|
||||
private int currentSelectIndex = 0;
|
||||
|
||||
private Vector2 lastMousePosition;
|
||||
private bool cachedIsPointerOverUI;
|
||||
private GameObject cachedHoveredUI;
|
||||
private int uiCheckFrameInterval = 3; // 每3帧检查一次
|
||||
private int frameCount;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
instance = this;
|
||||
@@ -34,7 +40,22 @@ namespace Ichni.Editor
|
||||
|
||||
private void Update()
|
||||
{
|
||||
isPointerOverUI = IsPointerOverUI(out hoveredUI);
|
||||
frameCount++;
|
||||
|
||||
// 只有当鼠标移动或每隔几帧时才更新UI检测
|
||||
Vector2 currentMousePosition = Mouse.current.position.ReadValue();
|
||||
if (currentMousePosition != lastMousePosition || frameCount % uiCheckFrameInterval == 0)
|
||||
{
|
||||
isPointerOverUI = IsPointerOverUI(out hoveredUI);
|
||||
lastMousePosition = currentMousePosition;
|
||||
cachedIsPointerOverUI = isPointerOverUI;
|
||||
cachedHoveredUI = hoveredUI;
|
||||
}
|
||||
else
|
||||
{
|
||||
isPointerOverUI = cachedIsPointerOverUI;
|
||||
hoveredUI = cachedHoveredUI;
|
||||
}
|
||||
|
||||
SceneCameraOperation();
|
||||
MusicPlayerOperation();
|
||||
@@ -296,6 +317,12 @@ namespace Ichni.Editor
|
||||
public bool IsPointerOverUI(out GameObject hoveredUI)
|
||||
{
|
||||
hoveredUI = null;
|
||||
|
||||
// 快速检查 - 使用Unity内置方法
|
||||
if (!EventSystem.current.IsPointerOverGameObject())
|
||||
return false;
|
||||
|
||||
// 详细检查 - 只有当快速检查通过时才执行
|
||||
if (eventSystem == null || graphicRaycasters.Count == 0)
|
||||
return false;
|
||||
|
||||
@@ -306,20 +333,19 @@ namespace Ichni.Editor
|
||||
|
||||
List<RaycastResult> allResults = new List<RaycastResult>();
|
||||
|
||||
// 遍历所有 Canvas 上的 GraphicRaycaster
|
||||
foreach (var raycaster in graphicRaycasters)
|
||||
// 只对最上层的Canvas进行检测
|
||||
foreach (var raycaster in graphicRaycasters.Where(r => r.gameObject.activeInHierarchy))
|
||||
{
|
||||
List<RaycastResult> results = new List<RaycastResult>();
|
||||
raycaster.Raycast(pointerEventData, results);
|
||||
allResults.AddRange(results);
|
||||
}
|
||||
|
||||
if (allResults.Count > 0)
|
||||
{
|
||||
// 按照 sortingOrder 获取最前面的 UI 物体
|
||||
allResults.Sort((a, b) => b.sortingOrder.CompareTo(a.sortingOrder));
|
||||
hoveredUI = allResults[0].gameObject;
|
||||
return true;
|
||||
if (results.Count > 0)
|
||||
{
|
||||
// 找到最前面的结果后立即返回
|
||||
results.Sort((a, b) => b.sortingOrder.CompareTo(a.sortingOrder));
|
||||
hoveredUI = results[0].gameObject;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user