protected override int DoOverlapCheck(Vector3 center, Collider[] colliders)
        {
            var scale = transform.lossyScale;

            if (width != 0)
            {
                Vector3 p1;
                Vector3 p2;

                PhysicsSensorUtils.GetCapsulePoints(center, transform.rotation, width, scale.x, out p1, out p2);

#if UNITY_2019_1_OR_NEWER
                return(PhysicsScene.OverlapCapsule
#else
                return Physics.OverlapCapsuleNonAlloc
#endif
                           (p1, p2, PhysicsSensorUtils.GetScaledCapsuleRadius(radius, scale),
                           colliders, layerMask, queryTriggerInteraction));
            }

#if UNITY_2019_1_OR_NEWER
            return(PhysicsScene.OverlapSphere
#else
            return Physics.OverlapSphereNonAlloc
#endif
                       (center, PhysicsSensorUtils.GetScaledSphereRadius(radius, scale),
                       colliders, layerMask, queryTriggerInteraction));
        }
Exemplo n.º 2
0
        protected override int DoCast(Ray ray, RaycastHit[] hitArray)
        {
            var scale        = transform.lossyScale;
            var castDistance = PhysicsSensorUtils.GetCastDistance(maxDistance, scale);

            if (width != 0)
            {
                Vector3 p1;
                Vector3 p2;

                PhysicsSensorUtils.GetCapsulePoints(ray.origin, transform.rotation, width, scale.x, out p1, out p2);

                if (hitArray.Length == 1)
                {
                    return(Physics.CapsuleCast(p1, p2, PhysicsSensorUtils.GetScaledCapsuleRadius(radius, scale),
                                               ray.direction, out hitArray[0], castDistance, layerMask, queryTriggerInteraction)
                        ? 1
                        : 0);
                }

                return(Physics.CapsuleCastNonAlloc(p1, p2, PhysicsSensorUtils.GetScaledCapsuleRadius(radius, scale),
                                                   ray.direction, hitArray, castDistance, layerMask, queryTriggerInteraction));
            }

            if (radius != 0)
            {
                if (hitArray.Length == 1)
                {
                    return(Physics.SphereCast(Ray, PhysicsSensorUtils.GetScaledSphereRadius(radius, scale),
                                              out hitArray[0], castDistance, layerMask, queryTriggerInteraction)
                        ? 1
                        : 0);
                }

                return(Physics.SphereCastNonAlloc(Ray, PhysicsSensorUtils.GetScaledSphereRadius(radius, scale),
                                                  hitArray, castDistance, layerMask, queryTriggerInteraction));
            }

            if (hitArray.Length == 1)
            {
                return(Physics.Raycast(Ray, out hitArray[0], castDistance, layerMask, queryTriggerInteraction) ? 1 : 0);
            }

            return(Physics.RaycastNonAlloc(Ray, hitArray,
                                           castDistance, layerMask, queryTriggerInteraction));
        }