ReplacePosition() 공개 메소드

public ReplacePosition ( IntVector2 newValue ) : Entity
newValue IntVector2
리턴 Entity
        //I explored several ways to have this system only respond when a paddle's position changes
        //1. _group.OnEntityUpdated += OnPaddlePositionUpdated; I'm using this now.
        //2. I couldn't find a way to do it with "public TriggerOnEvent trigger". its more about entity add than components, yes?
        //3. _onPaddlePositionUpdated = _group.CreateObserver(GroupEventType.OnEntityAdded). its more about entity add than components, yes?
        private void Group_OnEntityUpdated(Group group, Entity entity, int index, IComponent previousComponent, IComponent newComponent)
        {
            float sizeY = entity.view.bounds.size.y / 2;
            Vector3 nextVelocity = entity.velocity.velocity;
            Vector3 nextPosition = entity.position.position;
            float bounceAmount = entity.boundsBounce.bounceAmount;

            //Bottom
            if (entity.position.position.y - sizeY < _bounds.min.y)
            {
                nextVelocity = new Vector3 (nextVelocity.x, nextVelocity.y * bounceAmount, nextVelocity.z);
                _pool.CreateEntity().AddPlayAudio(GameConstants.Audio_Collision, GameConstants.AudioVolume);

                //order matters
                //1
                entity.ReplacePosition(new Vector3 (nextPosition.x, _bounds.min.y + sizeY, nextPosition.z));
                //2
                entity.ReplaceVelocity(nextVelocity);
            }
            //Top
            else if (entity.position.position.y + sizeY > _bounds.max.y)
            {
                nextVelocity = new Vector3 (nextVelocity.x, nextVelocity.y * bounceAmount, nextVelocity.z);
                _pool.CreateEntity().AddPlayAudio(GameConstants.Audio_Collision, GameConstants.AudioVolume);

                //order matters
                //1
                entity.ReplacePosition(new Vector3 (nextPosition.x, _bounds.max.y - sizeY, nextPosition.z));
                //2
                entity.ReplaceVelocity(nextVelocity);
            }
        }
        private void Wrap(Entity entity, UnityEngine.Bounds bounds)
        {
            var position = entity.position;

            if (position.x < bounds.min.x)
                entity.ReplacePosition(position.x + bounds.size.x, position.y);

            if (position.x > bounds.max.x)
                entity.ReplacePosition(position.x - bounds.size.x, position.y);

            if (position.y < bounds.min.y)
                entity.ReplacePosition(position.x, position.y + bounds.size.y);

            if (position.y > bounds.max.y)
                entity.ReplacePosition(position.x, position.y - bounds.size.y);
        }
예제 #3
0
 void moveDown(Entity e, int column, int row, Entity[,] grid)
 {
     var nextRowPos = grid.GetNextEmptyRow(column, row);
     if (nextRowPos != row) {
         grid[column, nextRowPos] = e;
         grid[column, row] = null;
         e.ReplacePosition(column, nextRowPos);
     }
 }
        //I explored several ways to have this system only respond when a paddle's position changes
        //1. _group.OnEntityUpdated += OnPaddlePositionUpdated; I'm using this now.
        //2. I couldn't find a way to do it with "public TriggerOnEvent trigger". its more about entity add than components, yes?
        //3. _onPaddlePositionUpdated = _group.CreateObserver(GroupEventType.OnEntityAdded). its more about entity add than components, yes?
        private void PaddleGroup_OnEntityAdded(Group group, Entity paddleEntity, int index, IComponent previousComponent, IComponent newComponent)
        {
            Bounds bounds = _gameEntity.bounds.bounds;
            float sizeY = paddleEntity.view.bounds.size.y / 2;
            Vector3 nextPosition = paddleEntity.position.position;

            //Be careful only to call paddleEntity.ReplacePosition() within the 'if' to prevent an infinite loop - srivello
            //Bottom
            if (paddleEntity.position.position.y - sizeY < bounds.min.y)
            {
                nextPosition = new Vector3(nextPosition.x, bounds.min.y + sizeY, nextPosition.z);
                paddleEntity.ReplacePosition(nextPosition);
                paddleEntity.ReplaceVelocity(Vector3.zero);
            }
            //Top
            else if (paddleEntity.position.position.y + sizeY > bounds.max.y)
            {
                nextPosition = new Vector3(nextPosition.x, bounds.max.y - sizeY, nextPosition.z);
                paddleEntity.ReplacePosition(nextPosition);
                paddleEntity.ReplaceVelocity(Vector3.zero);
            }
        }
        /*
         * 
         * Wiki
         * 
         * 
         */

        static void entityExample(Entity entity) {
            entity.AddPosition(3, 7);
            entity.AddHealth(100);
            entity.isMovable = true;

            entity.ReplacePosition(10, 100);
            entity.ReplaceHealth(entity.health.health - 1);
            entity.isMovable = false;

            entity.RemovePosition();

            var hasPos = entity.hasPosition;
            var movable = entity.isMovable;
        }
예제 #6
0
        static void positionComponent(Entity e, PositionComponent component, int x, int y)
        {
            var pos = e.position;
            var has = e.hasPosition;

            e.AddPosition(x, y);
            e.AddPosition(component);

            e.ReplacePosition(x, y);

            e.RemovePosition();
        }