예제 #1
0
            public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
            {
                var count = chunk.Count;

                if (chunk.Has(CircleColliderType))
                {
                    var colliders = chunk.GetNativeArray(CircleColliderType);
                    var aabbs     = chunk.GetNativeArray(BoundsType);
                    for (int i = 0; i < count; i++)
                    {
                        aabbs[i] = new Bounds2D(colliders[i]);
                    }
                }
                else if (chunk.Has(VertexType))
                {
                    var colliders = chunk.GetBufferAccessor(VertexType);
                    var aabbs     = chunk.GetNativeArray(BoundsType);
                    for (int i = 0; i < count; i++)
                    {
                        aabbs[i] = new Bounds2D(colliders[i].AsNativeArray());
                    }
                }
            }
예제 #2
0
 public static float2 ClosestPoint(float2 v, Bounds2D aabb)
 {
     return(math.clamp(v, aabb.Min, aabb.Max));
 }
예제 #3
0
        public void ExecuteNext(int key, ColliderData source)
        {
            var hasValue = TargetMap.TryGetFirstValue(key, out var target, out var iterator);

            while (hasValue)
            {
                // TODO: We need to check collider heights aswell
                if (CanCollide(source.Tags, target.Tags) && source.ColliderEntity != target.ColliderEntity && Bounds2D.DoesCollide(source.Bounds, target.Bounds))
                {
                    PossibleCollisions.Add(key, new PossibleCollision
                    {
                        SourceEntity   = source.Entity,
                        SourceCollider = source.ColliderEntity,
                        SourceType     = source.Shape,
                        TargetEntity   = target.Entity,
                        TargetCollider = target.ColliderEntity,
                        TargetType     = target.Shape,
                        SourceCenter   = source.Bounds.Center,
                        TargetCenter   = target.Bounds.Center,
                    });
                }

                hasValue = TargetMap.TryGetNextValue(out target, ref iterator);
            }
        }