コード例 #1
0
        public IState Update(AbstractStateManager stateManager)
        {
            SetEntityPosition(stateManager, GetNewPosition(stateManager));

            if (HasArrived(_targetPosition, stateManager))
            {
                SetEntityPosition(stateManager, _targetPosition);

                if (stateManager is PlayerMovementManager)
                {
                    return(new PlayerIdleState((PlayerMovementManager)stateManager));
                }

                if (stateManager is BlockMovementManager)
                {
                    return(new BlockIdleState((BlockMovementManager)stateManager));
                }

                if (stateManager is SheepMovementManager)
                {
                    return(new SheepIdleState((SheepMovementManager)stateManager));
                }

                return(new IdleState());
            }

            return(null);
        }
コード例 #2
0
        private bool HasArrived(Vector3 target, AbstractStateManager stateManager)
        {
            float           snap           = 0;
            IEntityWithSnap entityWithSnap = stateManager as IEntityWithSnap;

            if (entityWithSnap != null)
            {
                snap = entityWithSnap.GetSnapDistance();
            }

            return(Vector3.Distance(target, stateManager.transform.position) <= snap);
        }
コード例 #3
0
        private Vector3 GetNewPosition(AbstractStateManager stateManager)
        {
            IEntityWithSpeed entityWithSpeed = stateManager as IEntityWithSpeed;

            if (entityWithSpeed == null)
            {
                throw new Exception("Entity that moves must implement IEntityWithSpeed");
            }

            return(Vector3.SmoothDamp(stateManager.transform.position, _targetPosition, ref _velocity,
                                      Time.deltaTime * entityWithSpeed.GetSpeed()));
        }
コード例 #4
0
 public EntityMovingState(
     AbstractStateManager stateManager,
     MovementInstruction movementInstruction
     )
 {
     Instruction     = movementInstruction;
     _targetPosition = new Vector3(
         movementInstruction.Direction.x,
         0,
         movementInstruction.Direction.y
         ) + stateManager.transform.position;
 }
コード例 #5
0
 private void SetEntityPosition(AbstractStateManager stateManager, Vector3 position)
 {
     stateManager.transform.position = position;
 }
コード例 #6
0
 public void Exit(AbstractStateManager stateManager)
 {
     _movementManager.collisionService.OnCollision -= HandleCollision;
 }
コード例 #7
0
 public IState Update(AbstractStateManager stateManager)
 {
     return(null);
 }
コード例 #8
0
 public void Exit(AbstractStateManager stateManager)
 {
     _playerMovementManager.playerInputService.OnInput -= HandleInput;
 }
コード例 #9
0
 public void Enter(AbstractStateManager stateManager)
 {
     _playerMovementManager.playerInputService.OnInput += HandleInput;
     LevelManager.Instance.CheckWinCondition();
 }
コード例 #10
0
 public void Exit(AbstractStateManager stateManager)
 {
     _movementManager.repelService.OnRepel -= HandleRepel;
 }