public static Collider2D OverlapArea (Vector2 pointA, Vector2 pointB, int layerMask= DefaultRaycastLayers, float minDepth= -Mathf.Infinity, float maxDepth= Mathf.Infinity);

Parameters

pointA矩形的一角。
pointB矩形 A 角的对角。
layerMask筛选器,用于检查仅在指定层上的对象。
minDepth仅包括 Z 坐标(深度)大于或等于该值的对象。
maxDepth仅包括 Z 坐标(深度)小于或等于该值的对象。

Returns

Collider2D 与该区域重叠的碰撞体。

Description

检查某碰撞体是否位于一个矩形区域内。

矩形由世界空间中的两个对角坐标定义。您可以将这两个对角坐标想象为左上角和右下角,但即使点的顺序相反,测试仍然有效。可选的 layerMask 可让测试仅检查特定层上的对象。

虽然 Z 轴与 2D 中的渲染或碰撞无关,但您可以使用 minDepthmaxDepth 参数根据其 Z 轴坐标筛选对象。如果有多个碰撞体位于该区域内,则返回 Z 坐标值最小的碰撞体。如果该区域没有任何碰撞体,则返回 Null。

另请参阅:OverlapAreaAllOverlapAreaNonAlloc


public static int OverlapArea (Vector2 pointA, Vector2 pointB, ContactFilter2D contactFilter, Collider2D[] results);

Parameters

pointA矩形的一角。
pointB矩形 A 角的对角。
contactFilter接触筛选器,用于以不同方式筛选结果,例如按层遮罩、Z 深度。注意,法线角度不用于重叠测试。
results用于接收结果的数组。该数组的大小决定可返回的结果的最大数量。

Returns

int 返回放置在 results 数组中的结果数。

Description

检查某碰撞体是否位于一个矩形区域内。

矩形由世界空间中的两个对角坐标定义。您可以将这两个对角坐标想象为左上角和右下角,但即使点的顺序相反,测试仍然有效。

该函数返回找到的碰撞体数,并将这些碰撞体放入 results 数组。也可以通过 contactFilter 对结果进行过滤。注意,按法线角筛选不适用于重叠函数。


Parameters

pointA矩形的一角。
pointB矩形 A 角的对角。
contactFilter接触筛选器,用于以不同方式筛选结果,例如按层遮罩、Z 深度。注意,法线角度不用于重叠测试。
resultsThe list to receive results.

Returns

void Returns the number of results placed in the results list.

Description

Checks if a Collider falls within a rectangular area.

矩形由世界空间中的两个对角坐标定义。您可以将这两个对角坐标想象为左上角和右下角,但即使点的顺序相反,测试仍然有效。

The integer return value is the number of results written into the results list. The results list will be resized if it doesn't contain enough elements to report all the results. This prevents memory from being allocated for results when the results list does not need to be resized, and improves garbage collection performance when the query is performed frequently.

The results can also be filtered by the contactFilter.

Note that filtering by normal angle is not available for overlap functions.