Ejemplo n.º 1
0
        public virtual void RemoveAssociatedColliderShapes(PhysicsTriggerComponentBase physicsComponent)
        {
            if (physicsComponent == null)
            {
                return;
            }

            foreach (var pair in tileBlockColliderShapes)
            {
                var colliderShapes = pair.Value;
                RemoveAssociatedColliderShapes(physicsComponent, colliderShapes);
            }
        }
Ejemplo n.º 2
0
        private static bool RemoveAssociatedColliderShapes(PhysicsTriggerComponentBase physicsComponent, List <IInlineColliderShapeDesc> colliderShapes)
        {
            var changed = false;

            for (int i = 0; i < colliderShapes.Count; i++)
            {
                changed = changed || physicsComponent.ColliderShapes.Remove(colliderShapes[i]);
            }

            colliderShapes.Clear();

            return(changed);
        }
Ejemplo n.º 3
0
        public void Update(TileGrid tileGrid, PhysicsTriggerComponentBase physicsComponent)
        {
            var blocks   = tileGrid.InternalBlocks;
            var cellSize = tileGrid.CellSize;

            context.ColliderShapeProvider = tileGrid;

            var changed = false;

            for (int i = 0; i < blocks.Count; i++)
            {
                var block = blocks[i];

                List <IInlineColliderShapeDesc> colliderShapes = null;

                if (tileBlockColliderShapes.TryGetValue(block.Location, out colliderShapes))
                {
                    if (block.PhysicsInvalidated)
                    {
                        changed = changed || RemoveAssociatedColliderShapes(physicsComponent, colliderShapes);
                    }
                    tileBlockColliderShapes.Remove(block.Location);
                }
                else if (!block.IsEmpty)
                {
                    colliderShapes = new List <IInlineColliderShapeDesc>();
                }

                if (colliderShapes != null)
                {
                    tileBlockColliderShapesSwap[block.Location] = colliderShapes;

                    context.PhysicsComponentColliderShapes = physicsComponent.ColliderShapes;
                    context.ColliderShapes = colliderShapes;

                    Update(context, block);

                    context.PhysicsComponentColliderShapes = null;
                    context.ColliderShapes = null;

                    changed = changed || true;
                }

                block.PhysicsInvalidated = false;
            }

            Utilities.Swap(ref tileBlockColliderShapes, ref tileBlockColliderShapesSwap);

            foreach (var colliderShapes in tileBlockColliderShapesSwap.Values)
            {
                changed = changed || RemoveAssociatedColliderShapes(physicsComponent, colliderShapes);
            }

            tileBlockColliderShapesSwap.Clear();

            //if (changed)
            //{
            //    var entity = physicsComponent.Entity;
            //    if (entity != null)
            //    {
            //        entity.Components.Remove(physicsComponent);
            //        entity.Components.Add(physicsComponent);
            //    }

            //}
        }