/// <summary> /// Pushes state by instance of the class triggering OnEnterState for the /// pushed state and if not silent OnExitState for the previous state in the stack /// </summary> /// <param name="state"></param> /// <param name="isSilent"></param> /// <exception cref="EvaluateException"></exception> public void PushState(StateMB <T> state, bool isSilent = false) { if (!statesRegister.ContainsKey(state.GetType())) { throw new EvaluateException( "State " + state + " not registered yet!"); } Log("Operation: Push, state: " + state.GetType(), "purple"); if (stack.Count > 0 && !isSilent) { var previous = stack.Peek(); previous.OnExitState(); } stack.Push(state); state.OnEnterState(); }
/// <summary> /// Checks if a an StateType is the current state. /// </summary> /// <param name="state"></param> /// <returns></returns> /// <exception cref="ArgumentNullException"></exception> public bool IsCurrent(StateMB <T> state) { if (state == null) { throw new ArgumentNullException(); } var current = PeekState(); if (current == null) { return(false); } return(current.GetType() == state.GetType()); }