/// <summary>
        /// Ticks the iterator.
        /// </summary>
        public void Update()
        {
            callOnEnterOnQueuedNodes();

            int           index = _traversal.Peek();
            BehaviourNode node  = _tree.allNodes[index];

            _lastStatusReturned = node.Run();

#if UNITY_EDITOR
            node.SetStatusEditor(_lastStatusReturned);
#endif

            if (_lastStatusReturned != BehaviourNode.Status.Running)
            {
                node.OnExit();
                _traversal.Pop();
                callOnChildExit(node);
            }

            if (_traversal.Count == 0)
            {
                OnDone();
            }
        }
        private void stepBackAbort()
        {
            int index = _traversal.Pop();

            BehaviourNode node = _tree.allNodes[index];

            node.OnExit();

#if UNITY_EDITOR
            node.SetStatusEditor(BehaviourNode.StatusEditor.Aborted);
#endif
        }
Beispiel #3
0
        private BehaviourNode PopNode()
        {
            int           index = traversal.Pop();
            BehaviourNode node  = tree.Nodes[index];

            if (node.IsComposite())
            {
                for (int i = 0; i < node.ChildCount(); i++)
                {
                    node.GetChildAt(i).OnCompositeParentExit();
                }
            }

            node.OnExit();
            return(node);
        }
        private BehaviourNode PopNode()
        {
            int           index = _traversal.Pop();
            BehaviourNode node  = _tree.allNodes[index];

            node.OnExit();

            // Guard against empty branch tick pop.
            // This could occur if a node was aborted then interrupted in succession.
            // TODO: Test this further.
            if (_branchTicks.Count != 0 && node.CanTickOnBranch())
            {
                _branchTicks.Pop();
            }

            return(node);
        }
        /// <summary>
        /// Only interrupts the subtree until a parallel node.
        /// </summary>
        /// <param name="subtree"></param>
        internal void stepBackInterrupt(BehaviourNode subtree, bool bFullInterrupt = false)
        {
            while (_traversal.Count != 0 && _traversal.Peek() != subtree.preOrderIndex)
            {
                int index = _traversal.Pop();

                BehaviourNode node = _tree.allNodes[index];
                node.OnExit();
#if UNITY_EDITOR
                node.SetStatusEditor(BehaviourNode.StatusEditor.Interruption);
#endif
            }

            if (bFullInterrupt && _traversal.Count != 0)
            {
                int index = _traversal.Pop();

                BehaviourNode node = _tree.allNodes[index];
                node.OnExit();
#if UNITY_EDITOR
                node.SetStatusEditor(BehaviourNode.StatusEditor.Interruption);
#endif
            }
        }