Beispiel #1
0
 public override NodeResult Execute()
 {
     if (children.Count == 1)
     {
         Node child = children[0];
         if (child.status == Status.Success || child.status == Status.Failure)
         {
             return(NodeResult.From(child.status));
         }
         return(child.runningNodeResult);
     }
     return(NodeResult.failure);
 }
Beispiel #2
0
        public override NodeResult Execute()
        {
            Node node = GetChild();

            if (node == null || limitReached)
            {
                return(NodeResult.failure);
            }
            if (node.status == Status.Success || node.status == Status.Failure)
            {
                return(NodeResult.From(node.status));
            }
            return(node.runningNodeResult);
        }
Beispiel #3
0
        public override NodeResult Execute()
        {
            // Return fialure when subtree is not defined
            if (tree == null)
            {
                return(NodeResult.failure);
            }
            Node root = tree.GetRoot();

            if (root.status == Status.Success || root.status == Status.Failure)
            {
                return(NodeResult.From(root.status));
            }
            return(root.runningNodeResult);
        }
        public override NodeResult Execute()
        {
            Node node = GetChild();

            if (node == null)
            {
                return(NodeResult.failure);
            }
            if (node.status == Status.Success || node.status == Status.Failure)
            {
                return(NodeResult.From(node.status));
            }
            if (roll > probability.Value)
            {
                return(NodeResult.failure);
            }
            return(node.runningNodeResult);
        }
Beispiel #5
0
        public override NodeResult Execute()
        {
            Node node = GetChild();

            if (node == null)
            {
                return(NodeResult.failure);
            }
            if (node.status == Status.Success || node.status == Status.Failure)
            {
                return(NodeResult.From(node.status));
            }
            lastConditionCheckResult = Check();
            if (lastConditionCheckResult == false)
            {
                return(NodeResult.failure);
            }
            return(node.runningNodeResult);
        }
Beispiel #6
0
        /// <summary>
        /// Update tree state.
        /// </summary>
        public void Tick()
        {
            _TickMarker.Begin();
            // Fire Tick event
            onTick.Invoke();

            // Check if there are any interrupting nodes
            EvaluateInterruptions();

            // Max number of traversed nodes
            int executionLimit = maxExecutionsPerTick;

            // Traverse tree
            while (executionStack.Count > 0)
            {
                if (executionLimit == 0)
                {
                    _TickMarker.End();
                    return;
                }
                executionLimit -= 1;

                // Execute last element in stack
                Node       currentNode = executionStack[executionStack.Count - 1];
                NodeResult nodeResult  = currentNode.Execute();
                // Set new status
                currentNode.status = nodeResult.status;
                if (nodeResult.status == Status.Running)
                {
                    // If node is running, then stop execution or continue children
                    Node child = nodeResult.child;
                    if (child == null)
                    {
                        // Stop execution and continue next tick
                        _TickMarker.End();
                        return;
                    }
                    else
                    {
                        // Add child to execution stack and execute it in next loop
                        executionStack.Add(child);
                        executionLog.Add(child);
                        // IMPORTANT: Priority must be > 0 and assigned in this order
                        child.runtimePriority = executionLog.Count;
                        child.OnAllowInterrupt();
                        child.OnEnter();
                        #if UNITY_EDITOR
                        // Stop execution if breakpoint is set on this node
                        if (child.breakpoint)
                        {
                            Debug.Break();
                            UnityEditor.Selection.activeGameObject = this.gameObject;
                            Debug.Log("MBT Breakpoint: " + child.title, this);
                            _TickMarker.End();
                            return;
                        }
                        #endif
                        continue;
                    }
                }
                else
                {
                    // Remove last node from stack and move up (closer to root)
                    currentNode.OnExit();
                    executionStack.RemoveAt(executionStack.Count - 1);
                }
            }

            // Run this when execution stack is empty and BT should repeat
            if (repeatOnFinish)
            {
                Restart();
            }
            _TickMarker.End();
        }