Ejemplo n.º 1
0
    void DefineNode()
    {
        currentNode = GetRootNode();

        currentNode._Inject(_ctx);
        var state = currentNode.Start();

        if (state != BehaviourNode <X> .State.IN_PROGRESS)
        {
            currentNode = null;
            Debug.LogWarning("[BehaviourTree] Execution of the tree was instantaneous");
        }
    }
    public override State Update()
    {
        var state = _current.Recalculate() ? _current.Start() : _current.Update();

        if (state == State.FAILURE)
        {
            return(CalculateState(State.FAILURE));
        }
        else if (state == State.SUCCESS)
        {
            return(ToNextNode());
        }
        else
        {
            return(State.IN_PROGRESS);
        }
    }
Ejemplo n.º 3
0
    State DefineNode()
    {
        foreach (var s in _childs)
        {
            var pick = s.shouldPick(ctx);

            if (pick)
            {
                _currentNode = s.node;
                _currentNode._Inject(ctx);

                var state = _currentNode.Start();

                return(state);
            }
        }

        return(State.SUCCESS);
    }
    State ToNextNode()
    {
        while (_childs.MoveNext())
        {
            _current = _childs.Current;

            _current._Inject(ctx);
            var state = _current.Start();

            if (state == State.FAILURE)
            {
                return(CalculateState(State.FAILURE));
            }
            else if (state == State.IN_PROGRESS)
            {
                return(State.IN_PROGRESS);
            }
        }

        return(CalculateState(State.SUCCESS));
    }
Ejemplo n.º 5
0
    IEnumerator Routine()
    {
        while (true)
        {
            if (currentNode == null)
            {
                DefineNode();
            }

            if (currentNode != null)
            {
                var state = currentNode.Recalculate() ? currentNode.Start() : currentNode.Update();

                if (state != BehaviourNode <X> .State.IN_PROGRESS)
                {
                    currentNode = null;
                }
            }

            yield return(null);
        }
    }
Ejemplo n.º 6
0
 public override State Update()
 {
     return(_currentNode.Recalculate() ? _currentNode.Start() : _currentNode.Update());
 }