public void Add(MiniFSMHandler <TEnum> state) { if (machineStates.ContainsKey(state.State)) { Debug.LogError($"Already contains {state.State}"); return; } machineStates.Add(state.State, state); }
public void StartMachine(TEnum initialState) { if (!machineStates.ContainsKey(initialState)) { return; } _currentState = initialState; _currentHandler = machineStates[initialState]; machineStates[initialState].Enter(); }
public void ChangeState(TEnum nextState) { // avoid changing to the same state if (EqualsState(_currentState, nextState)) { return; } _previousState = _currentState; _currentState = nextState; _currentHandler = machineStates[_currentState]; // exit the prev state, enter the next state machineStates[_previousState].Exit(); _currentHandler.Enter(); // fire the changed event if we have a listener OnStateChanged?.Invoke(_previousState, _currentState); }