返回介绍

Physics2D.CircleCastNonAlloc 圆形投射不分配内存

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

JavaScript => static function CircleCastNonAlloc(origin: Vector2, radius: float, direction: Vector2, results: RaycastHit2D[], distance: float = Mathf.Infinity, layerMask: int = DefaultRaycastLayers, minDepth: float = -Mathf.Infinity, maxDepth: float = Mathf.Infinity): int;
C# => static int CircleCastNonAlloc(Vector2 origin, float radius, Vector2 direction, RaycastHit2D[] results, float distance = Mathf.Infinity, int layerMask = DefaultRaycastLayers, float minDepth = -Mathf.Infinity, float maxDepth = Mathf.Infinity);

Parameters 参数

originThe point in 2D space where the shape originates.
在2D空间中,形状的发源点。
radiusThe radius of the shape.
形状的半径。
directionVector representing the direction of the shape.
代表形状方向的向量。
resultsArray to receive results.
接收投射结果的数组。
distanceMaximum distance over which to cast the shape.
形状投射的最大距离。
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 circle into the scene, returning colliders that contact with it into the provided results array.
对场景内投射一个圆形,把检测到的碰撞器放入提供结果数组,用这样的方式来返回投射到碰撞器。

This function is similar to the CircleCastAll function except that the results are returned in the supplied array. The integer return value is the number of objects that intersect the circle (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 performed frequently.
这个函数与CircleCastAll函数很像,区别在于他把返回结果放到一个事先准备好的数组内。整形的返回值(可能为零)就是圆形贯穿的对象的数量,但是结果数组将不会重新调整大小即使他没有足够的元素装下所有的结果(碰撞器)。他的意义在于整个过程中不会为结果重新分配内存,使垃圾回收的频率降低从而提高了性能。

The returned RaycastHit2D returns both the point and normal of the contact where the circle would touch the collider. It also returns the centroid where the circle would be positioned for it to contact at that point.
返回的RaycastHit2D类型内包含了投射圆形接触到碰撞器的接触点和法线信息。它还返回圆形被定位在接触点时的中心点。

See Also: LayerMask class, RaycastHit2D class, CircleCast, CircleCastAll, DefaultRaycastLayers, IgnoreRaycastLayer, raycastsHitTriggers.

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

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

发布评论

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