Esempio n. 1
0
        private PlayerActionStateBase CreateStateByType(PlayerInputType wantedType)
        {
            PlayerActionStateBase wantedStage = null;

            switch (wantedType)
            {
            case PlayerInputType.None:
                wantedStage = gameObject.AddComponent <NoneState>();
                break;

            case PlayerInputType.Move:
                wantedStage = gameObject.AddComponent <MoveState>();
                break;

            case PlayerInputType.Dash:
                wantedStage = gameObject.AddComponent <DashState>();
                break;

            case PlayerInputType.Attack:
                wantedStage = gameObject.AddComponent <AttackState>();
                break;

            case PlayerInputType.Spellcast:
                wantedStage = gameObject.AddComponent <SpellcastState>();
                break;

            case PlayerInputType.Interact:
                wantedStage = gameObject.AddComponent <InteractState>();
                break;
            }

            return(wantedStage);
        }
Esempio n. 2
0
        private PlayerActionStateBase GetStateByType(PlayerInputType nextMoveStageType)
        {
            PlayerActionStateBase nextState = null;

            foreach (PlayerActionStateBase state in playerActionStates)
            {
                if (state.Type == nextMoveStageType)
                {
                    nextState = state;
                    break;
                }
            }

            return(nextState);
        }
Esempio n. 3
0
        public bool ChangeState(PlayerInputType nextStateType)
        {
            // Let's check first if we can transition from current state to the target state or not
            if (!CurrentState.IsValidTargetState(nextStateType))
            {
                return(false);
            }

            // Fetch the next state object
            PlayerActionStateBase nextState = GetStateByType(nextStateType);

            if (nextState == null)
            {
                return(false);
            }

            CurrentState.TransitionOut();
            PreviousState = CurrentState;
            CurrentState  = nextState;
            CurrentState.TransitionIn();

            return(true);
        }