/// <summary> /// Updates the state machine. This should be invoked periodically. /// </summary> public void Update() { if (CurrentStep == null) { Reset(); } CurrentStep.Update(); if (CurrentStep.ReachedExit != null) { var nextSteps = FindNextSteps(CurrentStep, CurrentStep.ReachedExit); if (nextSteps.Count() > 1) { throw new NotImplementedException(); } var nextStep = nextSteps.FirstOrDefault(); CurrentStep.Leave(); CurrentStep = nextStep; if (nextStep != null) { nextStep.Enter(); Console.WriteLine("New step: " + nextStep.GetType().Name); } else { Console.WriteLine("Process finished!"); IsFinished = true; } } }