Beispiel #1
0
    public void FinishTask()
    {
        --taskCounter;

        // If there are no mor tasks, we're ready
        if (taskCounter == 0)
        {
            actionState = MachineActionState.READY;
        }

        Debug.Log("Task counter: " + taskCounter);
    }
Beispiel #2
0
    private void SwitchState()
    {
        // We switch to another state
        if (states.Count > 0)
        {
            currentState = states.Dequeue();
        }
        else
        {
            // No more states
            currentState = NULL_STATE;
        }

        currentState.Init();
        actionState = MachineActionState.BUSY;
    }
Beispiel #3
0
    /// <summary>
    /// This is where we create our state machine. It's called once
    /// at the beginning.
    /// </summary>
    private void Init()
    {
        states         = new Queue <AutomatonState>();
        activeMessages = new List <Message>();

        states.Enqueue(new AutomatonState(stateObjects[0]));
        states.Enqueue(new AutomatonState(stateObjects[1]));
        states.Enqueue(new AutomatonState(stateObjects[1], stateObjects[2]));
        // state gear to bucket, change doc image
        states.Enqueue(new AutomatonState(stateObjects[1].GetComponent <GearDocState>()));
        states.Enqueue(new AutomatonState(stateObjects[2].GetComponent <VaultMasterKeyState>()));

        currentState = states.Dequeue();
        actionState  = MachineActionState.BUSY;

        //StartStateMachine();
    }
Beispiel #4
0
    void Update()
    {
        // TODO Always tick the current state, this may change
        // and tick every X instead of every frame

        if (isRunning)
        {
            if (actionState == MachineActionState.BUSY && taskCounter == 0)
            {
                actionState = MachineActionState.READY;
            }
            currentState.Tick();


            if (actionState == MachineActionState.READY)
            {
                SwitchState();
            }
        }
    }