Пример #1
0
        protected override int DoCast(Ray ray, RaycastHit[] hitArray)
        {
            var scale = transform.lossyScale;

            if (maxResults == 1)
            {
#if UNITY_2019_1_OR_NEWER
                return(PhysicsScene.
#else
                return Physics.
#endif
                       BoxCast(ray.origin, PhysicsSensorUtils.GetScaledBoxRadius(halfExtents, scale), ray.direction,
                               out hitArray[0], transform.rotation, PhysicsSensorUtils.GetCastDistance(maxDistance, scale),
                               layerMask, queryTriggerInteraction) ? 1 : 0);
            }

#if UNITY_2019_1_OR_NEWER
            return(PhysicsScene.BoxCast
#else
            return Physics.BoxCastNonAlloc
#endif
                       (ray.origin, PhysicsSensorUtils.GetScaledBoxRadius(halfExtents, scale),
                       ray.direction, hitArray, transform.rotation, PhysicsSensorUtils.GetCastDistance(maxDistance, scale),
                       layerMask, queryTriggerInteraction));
        }
        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));
        }
Пример #3
0
        protected override int DoOverlapCheck(Vector3 center, Collider[] colliders)
        {
#if UNITY_2019_1_OR_NEWER
            return(PhysicsScene.OverlapBox
#else
            return Physics.OverlapBoxNonAlloc
#endif
                       (center, PhysicsSensorUtils.GetScaledBoxRadius(halfExtents, transform.lossyScale),
                       colliders, transform.rotation, layerMask, queryTriggerInteraction));
        }
Пример #4
0
 protected override void DrawColliderShape(Vector3 position, Quaternion rotation, Vector3 scale)
 {
     if (width != 0)
     {
         PhysicsSensorUtils.DrawCapsuleGizmo(position, rotation, scale, width, radius);
     }
     else if (radius != 0)
     {
         PhysicsSensorUtils.DrawSphereGizmo(position, rotation, scale, radius);
     }
 }
Пример #5
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));
        }
Пример #6
0
        private void OnDrawGizmosSelected()
        {
            var castDistance = CastDistance;

            if (float.IsPositiveInfinity(castDistance))
            {
                castDistance = 1000000f;
            }

            var castRay = Ray;

            EnsureArrayCapacity(ref gizmoRayHits);
            var gizmoHitCount = DoCast(castRay, gizmoRayHits);
            var rayEnd        = castRay.GetPoint(castDistance);

            if (gizmoHitCount > 0)
            {
                for (var i = 0; i < gizmoHitCount; i++)
                {
                    var gizmoHit       = gizmoRayHits[i];
                    var collisionPoint = castRay.GetPoint(gizmoHit.distance);

                    Gizmos.color = PhysicsSensorUtils.hasHitColor;
                    Gizmos.DrawLine(castRay.origin, collisionPoint);
                    DrawColliderShape(collisionPoint, transform.rotation, transform.lossyScale);
                    Gizmos.color = PhysicsSensorUtils.rayEndColor;
                    Gizmos.DrawLine(collisionPoint, rayEnd);

                    PhysicsSensorUtils.DrawNormal(gizmoHit);
                    PhysicsSensorUtils.DrawCollisionPoints(collisionPoint, gizmoHit);
                    PhysicsSensorUtils.HighlightMeshVertices(gizmoHit);
                    PhysicsSensorUtils.DrawHitInfo(gizmoHit);
                }
            }
            else
            {
                Gizmos.color = PhysicsSensorUtils.noHitColor;
                Gizmos.DrawLine(castRay.origin, rayEnd);
                DrawColliderShape(rayEnd, transform.rotation, transform.lossyScale);
            }
        }
Пример #7
0
 protected override void DrawColliderShape(Vector3 position, Quaternion rotation, Vector3 scale)
 {
     PhysicsSensorUtils.DrawBoxGizmo(position, rotation, scale, halfExtents);
 }
Пример #8
0
 protected override int DoOverlapCheck(Vector3 center, Collider[] colliders)
 {
     return(Physics.OverlapBoxNonAlloc(center,
                                       PhysicsSensorUtils.GetScaledBoxRadius(halfExtents, transform.lossyScale),
                                       colliders, transform.rotation, layerMask, queryTriggerInteraction));
 }