public void GotoState(AnimalStateType key) { // if this state doesn't exist, return if (!states.ContainsKey(key)) { return; } // if there is a current state, // end the state properly by calling exit if (currState != null) { currState.Exit(); } // remember the previous state // and set the current state prevState = currState; CurrentState = key; currState = states[CurrentState]; // start the new current state // by entering it currState.Enter(); }
public void AddState(AnimalStateType newType, AnimalState newState) { // add the new state with the matching key states.Add(newType, newState); // initialize the new state, passing this FSM states[newType].Initialize(this); }
public AnimalState GetState(AnimalStateType type) { // returns state if it exists, // else null if (states.ContainsKey(type)) { return(states[type]); } else { return(null); } }