Ejemplo n.º 1
0
        public void SetNextState(T state)
        {
            bool found = states.TryGetValue(state, out StateMachineState <T> stateData);

            if (!found)
            {
                throw new Exception();
            }

            nextState = stateData;

            if (!idle)
            {
                return;
            }

            Next();
        }
Ejemplo n.º 2
0
        private bool TryNext()
        {
            if (nextState == null)
            {
                return(false);
            }

            if (CurrentState != null)
            {
                bool foundConnection = CurrentState.Connections.Contains(nextState.StateId);

                if (!foundConnection)
                {
                    throw new Exception();
                }

                bool found = states.TryGetValue(nextState.StateId, out StateMachineState <T> stateData);

                if (!found)
                {
                    throw new Exception();
                }

                CurrentState.StateAction.OnExit();
            }

            CurrentState = nextState;

            nextState = null;

            CurrentState.StateAction?.OnEnter();

            CurrentState.StateAction.OnRun(this);

            return(true);
        }