public static int OverlapCollider (Collider2D collider, ContactFilter2D contactFilter, Collider2D[] results);

Parameters

collider定义用于查询其他碰撞体重叠的区域的碰撞体。
contactFilter接触筛选器,用于以不同方式筛选结果,例如按层遮罩、Z 深度。注意,法线角度不用于重叠测试。
results用于接收结果的数组。该数组的大小决定可返回的结果的最大数量。

Returns

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

Description

Gets a list of all Colliders that overlap the given collider.

整数返回值是与 collider 重叠的碰撞体数,这些碰撞体可存储在所提供的给定了长度的数组中。如果结果数组中没有足够的元素来报告所有这些结果,则不会调整数组的大小。其意义在于不为这些结果分配内存,因此,如果经常进行检查,可以提高垃圾回收性能。

另请参阅:Collider2D.OverlapColliderRigidbody2D.OverlapCollider


Parameters

colliderThe Collider that defines the area used to query for other Collider overlaps.
contactFilter接触筛选器,用于以不同方式筛选结果,例如按层遮罩、Z 深度。注意,法线角度不用于重叠测试。
resultsThe list to receive results.

Returns

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

Description

Gets a list of all Colliders that overlap the given collider.

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.

另请参阅:Collider2D.OverlapColliderRigidbody2D.OverlapCollider