using System; using System.Collections.Generic; namespace BITKit.StateMachine { public interface IState { void Initialize(); void OnStateEnter(IState old); void OnStateUpdate(); void OnStateExit(IState old, IState newState); } public interface IStateMachine where T : IState { T CurrentState { get; set; } IDictionary StateDictonary { get; } void TransitionState() where State : T { var nextState = StateDictonary.GetOrCreate(typeof(State)); TransitionState(nextState); } void TransitionState(State nextState) where State : T { var currentState = CurrentState; currentState?.OnStateExit(currentState, nextState); nextState?.OnStateEnter(currentState); CurrentState = nextState; } void ExitState(); void RecoveryState(); } }