/// <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="currentState"> the original state. </param> /// <param name="nextState"> the destination state. </param> public ShowdownStateTransition(ShowdownState.ShowdownStateType currentState, ShowdownState.ShowdownStateType nextState) { this.currentState = currentState; this.nextState = nextState; }
/// <summary> /// Requests a next state. /// </summary> /// <param name="nextState"> the next state we want. </param> /// <returns> returns a valid next state or null. </returns> private IShowdownState GetNextState(ShowdownState.ShowdownStateType nextState) { return(ValidateStateTransition(nextState)); }