public void EnqueueTimeout(object data = null)
 {
     lock (_commandEnqueueLock)
     {
         _commandQueue.Add(StateMachineCommand.Timeout(data));
     }
 }
 public void EnqueueEvent(Enum evt, object data = null)
 {
     lock (_commandEnqueueLock)
     {
         _commandQueue.Add(StateMachineCommand.Event(evt, data));
     }
 }
        private void ChangeState(
            ChasisState newState, StateMachineCommand newPlayCommand, StateMachineCommand newStopCommand, Action onNewState)
        {
            lock (shared) {
                state = newState;


                onNewState?.Invoke();
                StateChanged?.Invoke(state);
            }
        }
        public void EnqueueTransition(Enum transition, object data = null)
        {
            if (Equals(transition, StateMachineBaseTransition.Cancel))
            {
                throw new NotSupportedException("use \"StateMachine.Cancel()\" instead of enqueueing a cancel transition");
            }

            lock (_commandEnqueueLock)
            {
                _commandQueue.Add(StateMachineCommand.Transition(transition, data));
            }
        }
        public void Cancel(string reason = "undefined")
        {
            Logger.LogError($"cancelling Statemaschine with reason: {reason}");
            _transitionCts.Cancel();

            lock (new[] { _commandEnqueueLock, _commandDequeueLock })
            {
                while (_commandQueue.Count > 0)
                {
                    _commandQueue.Take();
                }

                _commandQueue.Add(StateMachineCommand.Transition(StateMachineBaseTransition.Cancel));

                _transitionCts = new CancellationTokenSource();
            }
        }
Esempio n. 6
0
    // Update is called once per frame
    void Update()
    {
        if (state == 0)
        {
        }

        if (state == 1)
        {
            if (PC >= commands.Count)
            {
                state = 0;                 // end of program / state
            }
            else
            {
                currentCommand = commands [PC];
                switch (currentCommand.command)
                {
                case StateMachineCommand.Delay:
                    timer = 0.0f;
                    state = 100;
                    break;
                }
            }
        }


        if (state == 100)           // delay instruction
        {
            timer += Time.deltaTime;
            if (timer > currentCommand.fValue)
            {
                state = 1000;
            }
        }

        if (state == 1000)
        {
            ++PC;
            state = 1;
        }
    }