public void AddState(String stateID, State state) { // Default the state id to the next number if one hasn't been set if (stateID == "") stateID = m_States.Count.ToString(); // Add to the state buffer. m_States.Add(stateID, state); // Initiliase the state ( should never crash but safety check none the less ) if ( m_States.ElementAt( (m_States.Count - 1) ).Value != null ) m_States.ElementAt ( (m_States.Count - 1) ).Value.Initialise(); }
public void ChangeState(String stateID) { // Try and find the state is if (m_States.ContainsKey(stateID)) { // Close the current state if (m_CurrentState != null) m_CurrentState.OnExit(); // Save it as the previous state m_PreviousState = m_CurrentState; // Try and get the current state bool result = m_States.TryGetValue(stateID, out m_CurrentState); // Open the new state m_CurrentState.OnEnter(); } }