Version: 2021.2

Physics2D.OverlapCollider

切换到手册
public static int OverlapCollider (Collider2D collider, ContactFilter2D contactFilter, Collider2D[] results);

参数

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

返回

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

描述

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

The integer return value is the number of Colliders that overlap the Collider and which could be stored in the supplied array given its length. The results array will not be resized if it doesn't contain enough elements to report all the results. The significance of this is that no memory is allocated for the results and so garbage collection performance is improved when the check is performed frequently.

另请参阅:Collider2D.OverlapColliderRigidbody2D.OverlapCollider


public static int OverlapCollider (Collider2D collider, ContactFilter2D contactFilter, List<Collider2D> results);

参数

Collider 定义用于查询其他碰撞体重叠的区域的碰撞体。
contactFilter 接触筛选器,用于以不同方式筛选结果,例如按层遮罩、Z 深度。注意,法线角度不用于重叠测试。
results 用于接收结果的列表。

返回

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

描述

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

该整数返回值是写入到 results 列表中的结果数。如果结果列表中没有足够的元素来报告所有这些结果,则会调整列表的大小。这可在 results 列表无需调整大小时防止为结果分配内存,可在经常执行查询时提高垃圾收集性能。

也可以通过 contactFilter 对结果进行筛选。

另请参阅:Collider2D.OverlapColliderRigidbody2D.OverlapCollider