返回介绍

Physics2D.LinecastNonAlloc 直线投射不分配内存

发布于 2019-12-18 15:38:17 字数 3987 浏览 1027 评论 0 收藏 0

JavaScript => static function LinecastNonAlloc(start: Vector2, end: Vector2, results: RaycastHit2D[], layerMask: int = DefaultRaycastLayers, minDepth: float = -Mathf.Infinity, maxDepth: float = Mathf.Infinity): int;
C# => static int LinecastNonAlloc(Vector2 start, Vector2 end, RaycastHit2D[] results, int layerMask = DefaultRaycastLayers, float minDepth = -Mathf.Infinity, float maxDepth = Mathf.Infinity);

Parameters 参数

startThe start point of the line in world space.
直线在世界空间的开始点。
endThe end point of the line in world space.
直线在时间空间的结束点。
resultsReturned array of objects that intersect the line.
返回与直线相交的物体数组。
layerMaskFilter to detect Colliders only on certain layers.
只在某些层过滤检测碰撞器。
minDepthOnly include objects with a Z coordinate (depth) greater than this value.
只包括Z坐标(深度)大于这个值的对象。
maxDepthOnly include objects with a Z coordinate (depth) less than this value.
只包括Z坐标(深度)小于这个值的对象。

Returns 返回值

int The number of results returned.
int 返回结果的数量。

Description 描述

Casts a line against colliders in the scene.

A linecast is an imaginary line between two points in world space. Any object making contact with the beam can be detected and reported. This differs from the similar raycast in that the raycast specifies the line using an origin and directtion.

This function is similar to the LinecastAll function except that the results are returned in the supplied array. The integer return value is the number of objects that intersect the line (possibly zero) but 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 linecasts are performed frequently. The line is assumed to run from its start point to its end point; colliders will be placed in the returned array in order of distance from the start of the line.

Additionally, this will also detect Collider(s) at the start of the line. In this case the line is starting inside the Collider and doesn't intersect the Collider surface. This means that the collision normal cannot be calculated in which case the collision normal returned is set to the inverse of the line vector being tested. This can easily be detected because such results are always at a RaycastHit2D fraction of zero.

See Also: LayerMask class, RaycastHit2D class, Linecast, LinecastAll, DefaultRaycastLayers, IgnoreRaycastLayer, raycastsHitTriggers.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文