Exemple #1
0
        public static bool OverlapSphereCustom <T, C>(ref T target, float3 position, float radius, ref C collector, CollisionFilter filter, QueryInteraction queryInteraction = QueryInteraction.Default)
            where T : struct, ICollidable
            where C : struct, ICollector <DistanceHit>
        {
            PointDistanceInput input = new PointDistanceInput
            {
                Filter      = filter,
                MaxDistance = radius,
                Position    = position
            };

            if (queryInteraction == QueryInteraction.Default)
            {
                return(target.CalculateDistance(input, ref collector));
            }
            else
            {
                unsafe
                {
                    var interactionCollector = new QueryInteractionCollector <DistanceHit, C>
                    {
                        Collector = collector
                    };

                    bool returnValue = target.CalculateDistance(input, ref interactionCollector);

                    collector = interactionCollector.Collector;
                    return(returnValue);
                }
            }
        }
Exemple #2
0
        public static bool OverlapBoxCustom <T, C>(ref T target, float3 center, quaternion orientation, float3 halfExtents, ref C collector, CollisionFilter filter, QueryInteraction queryInteraction = QueryInteraction.Default)
            where T : struct, ICollidable
            where C : struct, ICollector <DistanceHit>
        {
            Assert.IsTrue(collector.MaxFraction == 0);

            BoxCollider collider = default;
            BoxGeometry geometry = new BoxGeometry
            {
                BevelRadius = 0.0f,
                Center      = float3.zero,
                Size        = halfExtents * 2,
                Orientation = quaternion.identity
            };

            collider.Initialize(geometry, filter, Material.Default);

            ColliderDistanceInput input;

            unsafe
            {
                input = new ColliderDistanceInput
                {
                    Collider    = (Collider *)UnsafeUtility.AddressOf(ref collider),
                    MaxDistance = 0.0f,
                    Transform   = new RigidTransform
                    {
                        pos = center,
                        rot = orientation
                    }
                };
            }

            if (queryInteraction == QueryInteraction.Default)
            {
                return(target.CalculateDistance(input, ref collector));
            }
            else
            {
                unsafe
                {
                    var interactionCollector = new QueryInteractionCollector <DistanceHit, C>
                    {
                        Collector = collector,
                    };

                    bool returnValue = target.CalculateDistance(input, ref interactionCollector);

                    collector = interactionCollector.Collector;
                    return(returnValue);
                }
            }
        }
Exemple #3
0
        public static bool OverlapCapsuleCustom <T, C>(ref T target, float3 point1, float3 point2, float radius, ref C collector, CollisionFilter filter, QueryInteraction queryInteraction = QueryInteraction.Default)
            where T : struct, ICollidable
            where C : struct, ICollector <DistanceHit>
        {
            Assert.IsTrue(collector.MaxFraction == 0);

            CapsuleCollider collider = default;
            float3          center   = (point1 + point2) / 2;

            CapsuleGeometry geometry = new CapsuleGeometry
            {
                Radius  = radius,
                Vertex0 = point1 - center,
                Vertex1 = point2 - center
            };

            collider.Initialize(geometry, filter, Material.Default);
            ColliderDistanceInput input;

            unsafe
            {
                input = new ColliderDistanceInput
                {
                    Collider    = (Collider *)UnsafeUtility.AddressOf(ref collider),
                    MaxDistance = 0.0f,
                    Transform   = new RigidTransform
                    {
                        pos = center,
                        rot = quaternion.identity
                    }
                };
            }

            if (queryInteraction == QueryInteraction.Default)
            {
                return(target.CalculateDistance(input, ref collector));
            }
            else
            {
                unsafe
                {
                    var interactionCollector = new QueryInteractionCollector <DistanceHit, C>
                    {
                        Collector = collector,
                    };

                    bool returnValue = target.CalculateDistance(input, ref interactionCollector);

                    collector = interactionCollector.Collector;
                    return(returnValue);
                }
            }
        }
Exemple #4
0
        public static bool CapsuleCastCustom <T, C>(ref T target, float3 point1, float3 point2, float radius, float3 direction, float maxDistance, ref C collector, CollisionFilter filter, QueryInteraction queryInteraction = QueryInteraction.Default)
            where T : struct, ICollidable
            where C : struct, ICollector <ColliderCastHit>
        {
            CapsuleCollider collider = default;

            float3 center = (point1 + point2) / 2;

            CapsuleGeometry geometry = new CapsuleGeometry
            {
                Radius  = radius,
                Vertex0 = point1 - center,
                Vertex1 = point2 - center
            };

            collider.Initialize(geometry, filter, Material.Default);

            ColliderCastInput input;

            unsafe
            {
                input = new ColliderCastInput
                {
                    Collider    = (Collider *)UnsafeUtility.AddressOf(ref collider),
                    Orientation = quaternion.identity,
                    Start       = center,
                    End         = center + direction * maxDistance
                };
            }

            if (queryInteraction == QueryInteraction.Default)
            {
                return(target.CastCollider(input, ref collector));
            }
            else
            {
                unsafe
                {
                    var interactionCollector = new QueryInteractionCollector <ColliderCastHit, C>
                    {
                        Collector = collector
                    };

                    bool returnValue = target.CastCollider(input, ref interactionCollector);

                    collector = interactionCollector.Collector;
                    return(returnValue);
                }
            }
        }
Exemple #5
0
        public static bool BoxCastCustom <T, C>(ref T target, float3 center, quaternion orientation, float3 halfExtents, float3 direction, float maxDistance, ref C collector, CollisionFilter filter, QueryInteraction queryInteraction = QueryInteraction.Default)
            where T : struct, ICollidable
            where C : struct, ICollector <ColliderCastHit>
        {
            BoxCollider collider    = default;
            BoxGeometry boxGeometry = new BoxGeometry
            {
                BevelRadius = 0,
                Center      = 0,
                Orientation = quaternion.identity,
                Size        = halfExtents * 2
            };

            collider.Initialize(boxGeometry, filter, Material.Default);

            ColliderCastInput input;

            unsafe
            {
                input = new ColliderCastInput
                {
                    Collider    = (Collider *)UnsafeUtility.AddressOf(ref collider),
                    Orientation = orientation,
                    Start       = center,
                    End         = center + direction * maxDistance
                };
            }

            if (queryInteraction == QueryInteraction.Default)
            {
                return(target.CastCollider(input, ref collector));
            }
            else
            {
                unsafe
                {
                    var interactionCollector = new QueryInteractionCollector <ColliderCastHit, C>
                    {
                        Collector = collector
                    };

                    bool returnValue = target.CastCollider(input, ref interactionCollector);

                    collector = interactionCollector.Collector;
                    return(returnValue);
                }
            }
        }