public static StateFSM stateFsmFromEnumState(enumStates _state) { var query = AllStates.Where(a => a.fsmState == _state); if (query.Count() > 0) { return(query.First()); } else { Debug.Log("FSMError - couldnt find state"); return(null); } }
public static void InvokeEvent(enumEvents _event) { Debug.Log("FSMLog - invoking event " + _event.ToString()); if (currentState.HasConsequence(_event)) { if (currentState.exit != null) { currentState.exit(); } enumStates nextState = currentState.NextState(_event); var query = AllStates.Where(a => a.fsmState == nextState); currentState = stateFsmFromEnumState(nextState); if (currentState.enter != null) { currentState.enter(); } Debug.Log("FSMLog - Entering state " + currentState.fsmState.ToString()); } else { Debug.Log("FSMERROR - state " + currentState.fsmState + " has no consequence for the event " + _event); } // StateFSM tempState ; }
public void AddConsequence(enumEvents _fsmEvent, enumStates _nextFsmState) { consequences.Add(_fsmEvent, _nextFsmState); }
public StateFSM(enumStates _fsmState, Dictionary <enumEvents, enumStates> _consequences) { consequences = _consequences; fsmState = _fsmState; }
public StateFSM(enumStates _fsmState) { consequences = new Dictionary <enumEvents, enumStates>(); fsmState = _fsmState; }
//======================================================================// // Call this function to change state // //======================================================================// public void stateManager(int value) { States = (enumStates)value; }
public static void ForceState(enumStates _state) { currentState = stateFsmFromEnumState(_state); }
public static void AddEventConsequence(enumStates _fromState, enumEvents _event, enumStates _toState) { stateFsmFromEnumState(_fromState).AddConsequence(_event, _toState); }
public static void AddOnEnterCall(enumStates _state, Action _method) { stateFsmFromEnumState(_state).enter += _method; }
public static void AddOnExitCall(enumStates _state, Action _method) { stateFsmFromEnumState(_state).exit += _method; }
public static void AddOneState(enumStates _state) { AllStates.Add(new StateFSM(_state)); }
public static bool InState(enumStates _state) { return(currentState == stateFsmFromEnumState(_state)); }