Exemple #1
0
        //有待优化
        private void ChangeNodeType(object obj)
        {
            string           nodeType  = (string)obj;
            NodeMeta         nodeProto = BTEditor.Instance.GetComponent <BTNodeInfoComponent>().GetNodeMeta(nodeType);
            BehaviorNodeData nodeData  = BTEditor.Instance.CreateNode(nodeProto.name);
            NodeDesigner     oldNode   = mSelectedNode;
            NodeDesigner     newNode   = new NodeDesigner(nodeData);

            if (oldNode == RootNode)
            {
                newNode.NodeData.Id = RootNode.NodeData.Id;
                RootNode            = newNode;
                BehaviorTreeData oldTree = BTEditor.Instance.CurTree;
                BehaviorTreeData newTree = new BehaviorTreeData()
                {
                    classify = oldTree.classify,
                    Root     = nodeData
                };
                BTEditor.Instance.CurTree = newTree;
            }
            else
            {
                int idx = oldNode.Parent.Children.IndexOf(oldNode);
                oldNode.Parent.AddChild(newNode, idx);
                oldNode.Parent.RemoveChild(oldNode);
            }

            foreach (NodeDesigner child in oldNode.Children)
            {
                newNode.AddChild(child);
            }
            BTEditor.Instance.ResetTreeId();
            Game.EventSystem.Run(EventIdType.BehaviorTreeAfterChangeNodeType);
        }
Exemple #2
0
        public BehaviorTreeConfig BehaviorTreeDataToConfig(BehaviorTreeData tree)
        {
            GameObject         curTreeGo = Object.Instantiate(CurTreeGO);
            BehaviorTreeConfig config    = curTreeGo.GetComponent <BehaviorTreeConfig>();

            if (config == null)
            {
                config = curTreeGo.AddComponent <BehaviorTreeConfig>();
            }
            foreach (Transform child in config.gameObject.transform)
            {
                Object.DestroyImmediate(child.gameObject);
            }
            try
            {
                config.RootNodeConfig = this.BehaviorNodeDataToNodeConfig(tree.Root);
            }
            catch (Exception e)
            {
                Log.Error($"tree name : {tree.BehaviorNodeData.Name} {e}");
            }

            config.RootNodeConfig.gameObject.transform.parent = config.gameObject.transform;
            return(config);
        }
Exemple #3
0
        public BehaviorTreeData BehaviorTreeConfigToTreeData(BehaviorTreeConfig config)
        {
            BehaviorTreeData tree = new BehaviorTreeData {
                Root = NodeConfigToNodeData(config.RootNodeConfig)
            };

            return(tree);
        }