using System.Collections.Generic;
public delegate void BaseDelegate();
public class FSM<T>
{
private T currentState;
private Dictionary<T, BaseDelegate> states;
public void AddCallBack(T state,BaseDelegate stateDelegate )
{
if (states!=null&&!states.ContainsKey(state))
{
states.Add(state, stateDelegate);
}
}
public FSM(T defaultState)
{
states = new Dictionary<T, BaseDelegate>();
currentState = defaultState;
}
public void ChangeState(T state)
{
currentState = state;
}
public void Update()
{
if (states!=null&&states.ContainsKey(currentState))
{
BaseDelegate state = states[currentState];
if (state != null)
{
state();
}
}
}
}