bool ICanvasRaycastFilter.IsRaycastLocationValid(Vector2 screenPos, Camera eventCamera)
{
if (null == _target) return true;
// 将目标对象范围内的事件镂空(使其穿过)
return !RectTransformUtility.RectangleContainsScreenPoint(_target, screenPos, eventCamera);
}
IsRaycastLocationValid:
解释:Given a point and a camera is the raycast valid.–>给定一个点和一个摄像机是有效的光线投射。
RectTransformUtility.RectangleContainsScreenPoint:
解释:Does the RectTransform contain the screen point as seen from the given camera?–》RectTransform是否包含从给定摄像机中看到的屏幕点?
RectangleContainsScreenPoint的作用:判断第二个参数代表的位置(鼠标的位置)是否在第一个参数rect的范围内
IsRaycastLocationValid的作用:判断是否投射到物体上
true:投射到为体上,不能穿透
false:没有投射到为体上,可以穿透