Esempio n. 1
0
    public void Add(MiniFSMHandler <TEnum> state)
    {
        if (machineStates.ContainsKey(state.State))
        {
            Debug.LogError($"Already contains {state.State}");
            return;
        }

        machineStates.Add(state.State, state);
    }
Esempio n. 2
0
    public void StartMachine(TEnum initialState)
    {
        if (!machineStates.ContainsKey(initialState))
        {
            return;
        }

        _currentState   = initialState;
        _currentHandler = machineStates[initialState];
        machineStates[initialState].Enter();
    }
Esempio n. 3
0
    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);
    }