Esempio n. 1
0
        //If any child fails retunrs failure
        public override BTNodeStates Execute()
        {
            if (_currentNode == null && _nodeQueue.Count > 0)
            {
                _currentNode = _nodeQueue.Dequeue();
            }

            BTNodeStates nodeStatus = _currentNode.Execute();

            switch (nodeStatus)
            {
            case BTNodeStates.FAILURE:
                return(_nodeState = BTNodeStates.FAILURE);

            case BTNodeStates.SUCCESS:
                if (_nodeQueue.Count > 0)
                {
                    _currentNode = _nodeQueue.Dequeue();
                }
                else
                {
                    return(_nodeState = BTNodeStates.SUCCESS);
                }
                break;

            case BTNodeStates.RUNNING:
                _nodeState = BTNodeStates.RUNNING;
                break;

            default:
                return(_nodeState = BTNodeStates.SUCCESS);
            }

            return(BTNodeStates.RUNNING);
        }
Esempio n. 2
0
        public override void Execute()
        {
            stateMachine.Update();

            if (_behvourTree != null)
            {
                BTNodeStates state = _behvourTree.Behave();
                if (state == BTNodeStates.SUCCESS)
                {
                    if (onUnitFinishTurn != null)
                    {
                        onUnitFinishTurn.Invoke(this);
                    }
                }

                if (state == BTNodeStates.FAILURE) // not using at the moment
                {
                    if (onUnitFinishTurn != null)
                    {
                        onUnitFinishTurn.Invoke(this);
                    }
                }
            }
        }
Esempio n. 3
0
 public BTNodeStates Behave()
 {
     return(_currentStatus = _rootNode.Execute());
 }