/// <summary> /// Validates the transition from the current state to the nextBattleState passed in. /// </summary> /// <param name="nextBattleState"> The desired next battle state. </param> /// <returns> Returns the next state or null depending on the validity of the state transition requested. </returns> private IShowdownState ValidateStateTransition(ShowdownState.ShowdownStateType nextBattleState) { IShowdownState nextState = null; if (!currentState.StateType.Equals(nextBattleState)) { ShowdownStateTransition transition = new ShowdownStateTransition(currentState.StateType, nextBattleState); if (!transitions.TryGetValue(transition, out nextState)) { UnityEngine.Debug.Log("Invalid Transition from:" + currentState.StateType.ToString() + " to:" + nextBattleState.ToString()); } } return(nextState); }
/// <summary> /// A call to transition to the nextState passed in. /// </summary> /// <param name="nextState"> the desired state to transition to. </param> public void TransitionToState(ShowdownState.ShowdownStateType nextState) { IShowdownState battleState = GetNextState(nextState); if (battleState != null) { currentState.OnExit(); currentState = battleState; currentState.OnEnter(); } else { } }
/// <summary> /// Default Constructor /// </summary> /// <param name="startingState"> The starting state of the state machine. </param> public ShowdownStateMachine(IShowdownState startingState) { currentState = startingState; InitializeTransitions(); }