Exemplo n.º 1
0
    // Update is called once per frame
    private void Update()
    {
        BrainTransition triggeredTransition = null;

        foreach (KeyValuePair <string, BrainTransition> transition in sm_currentState.transitions)
        {
            if (transition.Value.isTriggered)
            {
                triggeredTransition          = transition.Value;
                transition.Value.isTriggered = false;
                break;
            }
        }

        if (triggeredTransition != null)
        {
            BrainNode targetState = triggeredTransition.targetState;

            triggeredTransition.ExecuteTransition();

            sm_currentState = targetState;
        }
        else
        {
            sm_currentState.Execute();
            if (m_nextState != null)
            {
                sm_currentState = m_nextState;
                m_nextState     = null;
            }
        }
    }
Exemplo n.º 2
0
    //public BrainNode bt_currentState;

    //public Dictionary<string, BrainTask> bt_states;
    //public Dictionary<string, BrainAction> bt_actions;

    //public BehaviorTree()
    //{
    //    bt_states = new Dictionary<string, BrainTask>();
    //    bt_actions = new Dictionary<string, BrainAction>();
    //}

    public void StartBehavior()
    {
        bt_initialNode.Execute();
    }
Exemplo n.º 3
0
    public void ExecuteTransition()
    {
        transitionAction?.Invoke();

        targetState.Execute();
    }