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 == sfloat.Zero); BoxCollider collider = default; BoxGeometry geometry = new BoxGeometry { BevelRadius = sfloat.Zero, 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 = sfloat.Zero, 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); } } }
public static bool BoxCastCustom <T, C>(ref T target, float3 center, quaternion orientation, float3 halfExtents, float3 direction, sfloat 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 = sfloat.Zero, 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); } } }