public static NodeResult StandardNodeExecute(this SOTree node)
    {
        if (node == null)
        {
            UnityEngine.Debug.Log("Empty node slot in the tree");
            return(NodeResult.None);
        }
        if (!node.isActive)
        {
            return(NodeResult.Disabled);
        }
        ISOTagNode istn = node as ISOTagNode;

        if (istn != null && istn.tag != "")
        {
            //UnityEngine.Debug.Log(node.GetType());
            TagExecute(node, istn);
            return(NodeResult.None);
        }
        else
        {
            return(node.Execute());
        }
        //return NodeResult.Success;
    }
示例#2
0
 public static T DeepCopyTree <T>(T other) where T : SOTree
 {
     if (other as SOTreeNode != null)
     {
         // creates copies of children, then copies node, and reconnects new children to new node.
         SOTreeNode    o           = other as SOTreeNode;
         List <SOTree> newChildren = new List <SOTree>();
         for (int i = 0; i < o.nodes.Count; i++)
         {
             newChildren.Add(DeepCopyTree(o.nodes[i]));
         }
         o = DeepCopy(o);
         o.nodes.Clear();
         for (int i = 0; i < newChildren.Count; i++)
         {
             o.nodes.Add(newChildren[i]);
         }
         return(o as T);
     }
     if (other as SOParentNode != null)
     {
         SOParentNode o  = other as SOParentNode;
         SOTree       oc = DeepCopyTree(o.child);
         o       = DeepCopy(o);
         o.child = oc;
         return(o as T);
     }
     if (other as SOTreeLeaf != null)
     {
         return(DeepCopy(other) as T);
     }
     return(null);
 }
    public static NodeResult TagExecute(SOTree node, object ISOtagNode)
    {
        TreeBehaviour source = SOTree.source as TreeBehaviour;

        if (source == null)
        {
            UnityEngine.Debug.LogError("A tagged node under tagged node is not supported, because tagged nodes assign non-TreeBehaviour sources." +
                                       "Sources can currently be accessed only by root, not by child AiTargetrs.");
        }
        // Execute node n times on every source, with a copy of a node.
        // Performance: Create copy of the tree only once, then replace that node with reference node to the library which contains 1 subtree for every targeter.
        AITargeter[] sources = TreeBehaviour.GetAiSourcesByTagUnderRoot(source, ((ISOTagNode)ISOtagNode).tag);
        if (sources.Length == 0)
        {
            UnityEngine.Debug.Log("No sources with tag(" + ((ISOTagNode)ISOtagNode).tag);
        }
        for (int i = 0; i < sources.Length; i++)
        {
            SOTree.source = sources[i];
            //SOTree.DeepCopyTree(node).Execute();
            node.Execute();
        }
        SOTree.source = source;
        return(NodeResult.None);
    }
 internal void Add(SOTree node)
 {
     if (nodes == null)
     {
         nodes = new List <SOTree>();
     }
     nodes.Add(node);
 }