コード例 #1
0
        private BehaviorTree CreateTree(GameObject go)
        {
            NodeBase rootNode = GameObjectToNode(go);

            if (rootNode == null)
            {
                Debug.LogError("create root failed");
                return(null);
            }

            ProcessChildrenForTrans(go.transform, rootNode);

            BehaviorTree behaviorTree = CreatorUtils.NewBehaviorTree(rootNode);

            if (Validate())
            {
                string fullPath = GetFullPathForTree(go);
                SaveBehaviorTree(behaviorTree, new BytesAssetProcessor(), fullPath);
                Debug.Log("Created successfully!\n" + fullPath + "\n" + behaviorTree.DumpTree());
                return(behaviorTree);
            }
            else
            {
                return(null);
            }
        }
コード例 #2
0
        public BehaviorTree Load(string filePath)
        {
            if (!File.Exists(filePath))
            {
                return(null);
            }

            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(filePath);
            XmlElement root = xmlDoc.SelectSingleNode("root") as XmlElement;

            BehaviorTree behaviorTree = CreatorUtils.NewBehaviorTree(XmlElementToBTNode(root));

            return(behaviorTree);
        }
コード例 #3
0
        private void ProcessChildrenForTrans(Transform parentTrans, NodeBase parentNode)
        {
            foreach (Transform t in parentTrans)
            {
                var node = GameObjectToNode(t.gameObject);
                if (node == null)
                {
                    continue;
                }

                NodeParent parent = parentNode as NodeParent;
                if (parent != null)
                {
                    CreatorUtils.AddChild(parent, node);
                    ProcessChildrenForTrans(t, node);
                    continue;
                }
            }
        }
コード例 #4
0
        public BehaviorTree Build(out string err, out NodeBase node)
        {
            while (this.stack.Count > 1)
            {
                this.EndCurrent();
            }

            BehaviorTree behaviorTree = CreatorUtils.NewBehaviorTree(stack.Pop());

            if (behaviorTree.Validate(out err, out node))
            {
                return(behaviorTree);
            }
            else
            {
                DefaultLogger logger = new DefaultLogger();
                logger.Error(err);
                return(null);
            }
        }