public override Status Run()
        {
            if (IsAnyChildWithStatus(Status.Failure))
            {
                return(Status.Failure);
            }

            if (AreAllChildrenWithStatus(Status.Success))
            {
                return(Status.Success);
            }

            // Process the sub-iterators.
            for (int i = 0; i < subIterators.Count; ++i)
            {
                // Keep updating the iterators that are not done.
                BehaviourIterator itr = subIterators[i];
                if (itr.IsRunning)
                {
                    itr.Update();
                }
            }

            // Parallel iterators still running.
            return(Status.Running);
        }
Example #2
0
        public override Status Run()
        {
            // All iterators done.
            // Since there was no success interruption, that means
            // all iterators returned failure, so the parallel node
            // returns failure aswell.
            if (IsDone)
            {
                return(Status.Failure);
            }

            // Process the sub-iterators.
            for (int i = 0; i < _subIterators.Count; ++i)
            {
                BehaviourIterator itr = _subIterators[i];

                // Keep updating the iterators that are not done.
                if (itr.IsRunning)
                {
                    itr.Update();
                }

                // Iterator finished, it must have returned Success or Failure.
                // If the iterator returned success, then interrupt the parallel process
                // and have the parallel node return success.
                else if (itr.LastStatusReturned == Status.Success)
                {
                    return(Status.Success);
                }
            }

            // Parallel iterators still running.
            return(Status.Running);
        }
Example #3
0
        public override void OnExit()
        {
            for (int i = 0; i < _subIterators.Count; ++i)
            {
                BehaviourIterator itr = _subIterators[i];

                if (itr.IsRunning)
                {
                    Tree.Interrupt(_children[i], true);
                }
            }
        }
Example #4
0
        /// <summary>
        /// Sets the number of sub-iterators to the number of children.
        /// </summary>
        public void SyncSubIterators()
        {
            _subIterators = new List <BehaviourIterator>(_children.Count);

            // Set the new iterators. All of the sub-iterators have this parallel node as the root.
            foreach (var child in _children)
            {
                // Offset the level order by +1 since the parallel parent is not included
                // in the subtree child iterator traversal stack.
                var sub = new BehaviourIterator(Tree, levelOrder + 1);
                sub.OnDone += incrementDone;

                _subIterators.Add(sub);
            }
        }
Example #5
0
        /// <summary>
        /// Highlights nodes that are being re-evaluated, like abort nodes or
        /// children under reactive parents.
        /// </summary>
        /// <param name="node"></param>
        private void highlightAsReevaluated(BonsaiNode node)
        {
            if (!EditorApplication.isPlaying)
            {
                return;
            }

            BehaviourIterator itr = node.behaviour.Iterator;

            if (itr != null && itr.IsRunning)
            {
                var           aborter     = node.behaviour as ConditionalAbort;
                BehaviourNode currentNode = window.tree.GetNode(itr.CurrentIndex);

                // Only highlight the abort if the current running node can be aborted by it.
                if (aborter && ConditionalAbort.IsAbortable(aborter, currentNode))
                {
                    backgroundStyle.normal.background = _reevaluateHighlightTex;
                }
            }
        }