Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        public BehaviorTreeData BehaviorTreeConfigToTreeData(BehaviorTreeConfig config)
        {
            BehaviorTreeData tree = new BehaviorTreeData();

            tree.Root = NodeConfigToNodeData(config.RootNodeConfig);
            return(tree);
        }
Ejemplo n.º 3
0
        //有待优化
        private void ChangeNodeType(object obj)
        {
            string nodeType  = (string)obj;
            var    nodeProto = BehaviorManager.GetInstance().GetNodeTypeProto(nodeType);
            var    nodeData  = BehaviorManager.GetInstance().CreateNode((int)BehaviorManager.GetInstance().CurTree.Id, nodeProto.name);
            var    oldNode   = mSelectedNode;
            var    newNode   = new NodeDesigner(nodeData);

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

            foreach (var child in oldNode.Children)
            {
                newNode.AddChild(child);
            }
            BehaviorManager.GetInstance().ResetTreeId();
            Game.Scene.GetComponent <EventComponent>().Run(EventIdType.BehaviorTreeAfterChangeNodeType);
        }
Ejemplo n.º 4
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);
        }