Exemplo n.º 1
0
 public static void DestroyTree(BehaviourTree tree)
 {
     _trees.Remove(tree);
     ScriptableObject.Destroy(tree);
 }
Exemplo n.º 2
0
 /// <summary>
 /// DANGER. Directly sets the tree reference to null.
 /// </summary>
 internal void ClearTree()
 {
     _parentTree = null;
 }
Exemplo n.º 3
0
 public BehaviourIterator(BehaviourTree tree, int levelOffset)
 {
     _tree        = tree;
     _traversal   = new IntStack(_tree.Height);
     _levelOffset = levelOffset;
 }
Exemplo n.º 4
0
        public static void IncludeTreeReferences(BehaviourTree mainTree)
        {
            var includes = mainTree.GetNodes <Include>();

            // Nothing to include.
            if (includes.Count == 0)
            {
                return;
            }

            var includedTrees = new BehaviourTree[includes.Count];

            for (int i = 0; i < includes.Count; ++i)
            {
                // Clone each individual tree independently.
                Include       include = includes[i];
                BehaviourTree subtree = Clone(include.tree);

                BehaviourNode includeParent = include.Parent;
                BehaviourNode subtreeRoot   = subtree.Root;

                if (includeParent)
                {
                    // The root node must now be the child of the parent of the include.
                    subtreeRoot._indexOrder = include._indexOrder;
                    includeParent.ForceSetChild(subtreeRoot);
                }

                else if (include.preOrderIndex == 0)
                {
                    // If the include node is the root, then just make the subtree the root.
                    mainTree.Root = subtreeRoot;
                }

#if UNITY_EDITOR
                Vector2 deltaFromSubrootToInclude = include.bonsaiNodePosition - subtreeRoot.bonsaiNodePosition;
#endif

                // The nodes of the included tree, must now reference the main tree.
                foreach (BehaviourNode b in subtree.AllNodes)
                {
                    b.ClearTree();
                    b.Tree = mainTree;

#if UNITY_EDITOR
                    // Offset the sub tree nodes so they are placed under the include node.
                    b.bonsaiNodePosition += deltaFromSubrootToInclude;
#endif
                }
            }

            // After everything is included, we need to resort the tree nodes in pre order with the new included nodes.
            mainTree.SortNodes();

            // Destory the cloned subtrees since we do not need them anymore.
            for (int i = 0; i < includedTrees.Length; ++i)
            {
                Destroy(includedTrees[i]);
            }

            // Destroy the includes
            for (int i = 0; i < includes.Count; ++i)
            {
                Destroy(includes[i]);
            }
        }
Exemplo n.º 5
0
        public static BehaviourNode GetInstanceVersion(BehaviourTree tree, BehaviourNode original)
        {
            int index = original.preOrderIndex;

            return(tree.allNodes[index]);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Gets the instantiated copy version of a behaviour node from its original version.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="tree">The instantiated tree.</param>
 /// <param name="original">The node in the original tree.</param>
 /// <returns></returns>
 public static T GetInstanceVersion <T>(BehaviourTree tree, BehaviourNode original) where T : BehaviourNode
 {
     return(GetInstanceVersion(tree, original) as T);
 }