示例#1
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);
                }
            }
        }
示例#2
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);
                }
            }
        }