Example #1
0
        private NodeSearchResult FindNode(BehaviorTree behaviourTree, BehaviourTreeBranchBuilder customBranch)
        {
            BehaviorNode rootNode = behaviourTree.RootNode;

            string[] pathNodeNames = customBranch.PathNodeNames;

            if (customBranch.BehaviourTreeType == BehaviorTreeIDEnum.CoreAITree)
            {
                BehaviorNode     parent            = rootNode;
                NodeSearchResult nodeSearchResults = null;
                for (int i = 0; i < pathNodeNames.Length; i++)
                {
                    nodeSearchResults = FindNode(parent, pathNodeNames[i]);
                    if (nodeSearchResults != null)
                    {
                        parent = nodeSearchResults.Node;
                    }
                }

                if (nodeSearchResults != null)
                {
                    string name = (string)AccessTools.Field(typeof(BehaviorNode), "name").GetValue(nodeSearchResults.Node);
                    Main.LogDebug($"[FindNode] Found target from path '{customBranch.Path}'. Target found was '{name}'");
                    return(nodeSearchResults);
                }
            }

            return(null);
        }
Example #2
0
 public void LoadCustomBehaviourSequences(BehaviorTree behaviourTree, BehaviorTreeIDEnum behaviourTreeType, AbstractActor unit)
 {
     if (injectionBranchRoots.ContainsKey(behaviourTreeType))
     {
         List <BehaviourTreeBranchBuilder> customBehaviourBranches = injectionBranchRoots[behaviourTreeType];
         foreach (BehaviourTreeBranchBuilder customBehaviourBranch in customBehaviourBranches)
         {
             NodeSearchResult nodeSearchResults = FindNode(behaviourTree, customBehaviourBranch);
             if (nodeSearchResults != null)
             {
                 AddCustomBehaviourVariableScopes(unit);
                 customBehaviourBranch.Build(behaviourTree, nodeSearchResults.ParentNode, nodeSearchResults.NodeIndex, nodeSearchResults.Node, unit);
             }
         }
     }
 }
 public static NodeSearchResult CreateNodeSearchResult(int nodeID, int parentID, int level)
 {
     NodeSearchResult nodeSearchResult = new NodeSearchResult();
     nodeSearchResult.NodeID = nodeID;
     nodeSearchResult.ParentID = parentID;
     nodeSearchResult.Level = level;
     return nodeSearchResult;
 }
 public void AddToNodeSearchResults(NodeSearchResult nodeSearchResult)
 {
     base.AddObject("NodeSearchResults", nodeSearchResult);
 }