private static void RaycastCanvas canvas Camera eventCamera Vector2 pointerPosition IListGraphic foundGraphics ListGraphic results Necessary for the event system int tot
if (graphic.depth == -1 || !graphic.raycastTarget) { continue; }
RectTransform graphicRectTransform = graphic.rectTransform;
Vector3[] corners = new Vector3[4];
graphicRectTransform.GetWorldCorners(corners);
bool isInside = RectTransformUtility.RectangleContainsScreenPoint(graphicRectTransform, pointerPosition, eventCamera);
if (isInside)
{
Vector2 localPosition;
RectTransformUtility.ScreenPointToLocalPointInRectangle(graphicRectTransform, pointerPosition, eventCamera, out localPosition);
Vector3[] localCorners = new Vector3[4];
graphicRectTransform.GetLocalCorners(localCorners);
if (!RectTransformUtility.RectangleContainsScreenPoint(graphicRectTransform, localPosition, eventCamera))
{
continue;
}
float width = corners[2].x - corners[0].x;
float height = corners[2].y - corners[0].y;
float x = (localPosition.x - localCorners[0].x) / width;
float y = (localPosition.y - localCorners[0].y) / height;
if (graphic.Raycast(new Vector2(x, y), eventCamera))
{
results.Add(graphic);
}
}
}
原文地址: https://www.cveoy.top/t/topic/ixy4 著作权归作者所有。请勿转载和采集!