示例#1
0
        private void CreateNode()
        {
            NodeMeta         nodeProto = BTEntity.Instance.GetNodeMeta(BTEntity.Instance.selectNodeName);
            BehaviorNodeData nodeData  = BTEntity.Instance.CreateNode((int)BTEntity.Instance.CurTree.Id, nodeProto.name);

            CreateNode(nodeData, MousePosToGraphPos(mMousePos));
        }
示例#2
0
 public NodeDesigner(BehaviorNodeData data)
 {
     NodeData     = data;
     DesignerData = new NodeDesignerProto();
     Init();
     UpdateChildren();
 }
示例#3
0
        private void CreateNode()
        {
            NodeMeta         nodeProto = BTEditor.Instance.GetComponent <BTNodeInfoComponent>().GetNodeMeta(BTEditor.Instance.selectNodeName);
            BehaviorNodeData nodeData  = BTEditor.Instance.CreateNode(nodeProto.name);

            CreateNode(nodeData, MousePosToGraphPos(mMousePos));
        }
示例#4
0
        public void SelectNode(BehaviorNodeData node)
        {
            selectedNode = node;
            NodeProto nodeProto = NodeDataToNodeProto(node);

            inputValueList = GetSelectNodeInputValueList(nodeProto);
        }
示例#5
0
        //有待优化
        private void ChangeNodeType(object obj)
        {
            string           nodeType  = (string)obj;
            NodeMeta         nodeProto = BTEntity.Instance.GetNodeMeta(nodeType);
            BehaviorNodeData nodeData  = BTEntity.Instance.CreateNode((int)BTEntity.Instance.CurTree.Id, nodeProto.name);
            NodeDesigner     oldNode   = mSelectedNode;
            NodeDesigner     newNode   = new NodeDesigner(nodeData);

            if (oldNode == RootNode)
            {
                newNode.NodeData.Id = RootNode.NodeData.Id;
                RootNode            = newNode;
                BehaviorTreeData oldTree = BTEntity.Instance.CurTree;
                BehaviorTreeData newTree = new BehaviorTreeData(oldTree.Id);
                newTree.classify          = oldTree.classify;
                newTree.Root              = nodeData;
                BTEntity.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);
            }
            BTEntity.Instance.ResetTreeId();
            Game.Scene.GetComponent <EventComponent>().Run(EventIdType.BehaviorTreeAfterChangeNodeType);
        }
示例#6
0
        public BehaviorNodeData CopyNode(BehaviorNodeData node)
        {
            BehaviorNodeData copyNode = new BehaviorNodeData();

            copyNode.name      = node.name;
            copyNode.describe  = node.describe;
            copyNode.Pos       = node.Pos;
            copyNode.args_dict = new BehaviorTreeArgsDict();
            foreach (var item in node.args_dict)
            {
                ValueBase valueBase = ValueBase.Clone(item.Value);
                copyNode.args_dict.Add(item.Key, valueBase);
            }
            List <BehaviorNodeData> list = new List <BehaviorNodeData>();

            foreach (var item in node.children)
            {
                list.Add(item);
            }
            foreach (var child in list)
            {
                copyNode.AddChild(CopyNode(child));
            }
            copyNode.ResetId();
            return(copyNode);
        }
示例#7
0
 public void PrintTree(BehaviorNodeData nodeData)
 {
     Log.Info($"PrintTree  :  {nodeData.Id} {nodeData}");
     foreach (BehaviorNodeData data in nodeData.children)
     {
         this.PrintTree(data);
     }
 }
示例#8
0
 public void printTree(BehaviorNodeData nodeData)
 {
     Log.Info($"printTree  :  {nodeData.nodeId} {nodeData}");
     foreach (var data in nodeData.children)
     {
         printTree(data);
     }
 }
示例#9
0
 private static void _ClearDebugState(BehaviorNodeData nodeData)
 {
     nodeData.NodeDeubgState = DebugState.Normal;
     foreach (BehaviorNodeData child in nodeData.children)
     {
         _ClearDebugState(child);
     }
 }
示例#10
0
        public void onCreateNode(params object[] list)
        {
            string  nodeName = (string)list[0];
            Vector2 pos      = (Vector2)list[1];

            NodeMeta         nodeProto = BTEditor.Instance.GetComponent <BTNodeInfoComponent>().GetNodeMeta(nodeName);
            BehaviorNodeData nodeData  = BTEditor.Instance.CreateNode(nodeProto.name);

            CreateNode(nodeData, pos);
        }
示例#11
0
        public void onCreateNode(params object[] list)
        {
            string  name = (string)list[0];
            Vector2 pos  = (Vector2)list[1];

            NodeMeta         nodeProto = BTEntity.Instance.GetNodeMeta(name);
            BehaviorNodeData nodeData  = BTEntity.Instance.CreateNode((int)BTEntity.Instance.CurTree.Id, nodeProto.name);

            CreateNode(nodeData, pos);
        }
示例#12
0
 private void SetDebugState(BehaviorTree tree, int nodeId)
 {
     if (this.BehaviorTreeConfig != null && tree.behaviorTreeConfig.gameObject.name == this.BehaviorTreeConfig.gameObject.name)
     {
         BehaviorNodeData nodeData = GetNodeData(CurTree.Root, nodeId);
         if (nodeData != null)
         {
             nodeData.NodeDeubgState = DebugState.True;
         }
     }
 }
示例#13
0
 private void SetDebugState(int nodeId)
 {
     if (this.BehaviorTreeConfig != null)
     {
         BehaviorNodeData nodeData = GetNodeData(CurTree.Root, nodeId);
         if (nodeData != null)
         {
             nodeData.NodeDeubgState = DebugState.True;
         }
     }
 }
示例#14
0
 public BehaviorNodeData GetNode(BehaviorNodeData nodeData, int nodeId)
 {
     if (nodeData.Id == nodeId)
     {
         return(nodeData);
     }
     foreach (BehaviorNodeData data in nodeData.children)
     {
         return(GetNode(data, nodeId));
     }
     return(null);
 }
示例#15
0
        public BehaviorNodeData CreateNode(int treeId, string nodeName)
        {
            if (!mName2NodeProtoDict.ContainsKey(nodeName))
            {
                Debug.LogError($"节点类型:{nodeName}不存在");
                return(null);
            }
            BehaviorNodeData node = new BehaviorNodeData(nodeName);

            node.nodeId = AutoNodeId();
            node.name   = nodeName;
            return(node);
        }
示例#16
0
 public void PasteNode()
 {
     if (mCutNode != null && mCutNode != mSelectedNode)
     {
         ConnectNode(mCutNode, mSelectedNode);
     }
     if (mCopyNode != null && mCopyNode != mSelectedNode)
     {
         BehaviorNodeData data = BTEntity.Instance.CopyNode(mCopyNode.NodeData);
         BTEntity.Instance.ResetTreeId();
         NodeDesigner node = CreateNode(data, Vector2.zero);
         ConnectNode(node, mSelectedNode);
     }
 }
示例#17
0
        public List <string> GetNodeOutPutEnvKeyList(BehaviorNodeData nodeData, NodeFieldDesc desc = null)
        {
            NodeProto            rootNode  = this.BehaviorNodeDataToNodeProto(CurTree.Root);
            NodeProto            inputNode = this.BehaviorNodeDataToNodeProto(nodeData);
            List <NodeFieldDesc> descList  = _GetNodeOutPutEnvKeyList(rootNode, inputNode, desc);
            List <string>        list      = new List <string>();

            foreach (NodeFieldDesc item in descList)
            {
                string str = item.value?.ToString() ?? "";
                list.Add(str);
            }
            return(list);
        }
示例#18
0
        public BehaviorNodeConfig BehaviorNodeDataToNodeConfig(BehaviorNodeData nodeData)
        {
            GameObject         go         = new GameObject();
            BehaviorNodeConfig nodeConfig = go.AddComponent <BehaviorNodeConfig>();

            nodeConfig.id       = nodeData.Id;
            nodeConfig.name     = nodeData.Name;
            go.name             = nodeData.Name;
            nodeConfig.describe = nodeData.Desc;
            List <string> unUseList = new List <string>();

            foreach (KeyValuePair <string, object> args in nodeData.Args.Dict())
            {
                if (!NodeMetaHelper.NodeHasField(nodeData.Name, args.Key))
                {
                    unUseList.Add(args.Key);
                    continue;
                }
                Type originType = NodeMetaHelper.GetFieldType(nodeData.Name, args.Key);
                try
                {
                    string    fieldName     = args.Key;
                    object    fieldValue    = args.Value;
                    Type      type          = BTTypeManager.GetBTType(originType);
                    Component comp          = go.AddComponent(type);
                    FieldInfo fieldNameInfo = type.GetField("fieldName");
                    fieldNameInfo.SetValue(comp, fieldName);
                    FieldInfo fieldValueinfo = type.GetField("fieldValue");
                    if (TypeHelper.IsEnumType(originType))
                    {
                        fieldValue = fieldValue.ToString();
                    }
                    fieldValueinfo.SetValue(comp, fieldValue);
                }
                catch (Exception e)
                {
                    throw new Exception($"transform failed,nodeName:{nodeData.Name}  fieldName:{args.Key} fieldType:{originType}", e);
                }
            }
            foreach (string key in unUseList)
            {
                nodeData.Args.Remove(key);
            }
            foreach (BehaviorNodeData child in nodeData.children)
            {
                BehaviorNodeConfig childConfig = this.BehaviorNodeDataToNodeConfig(child);
                childConfig.gameObject.transform.parent = nodeConfig.gameObject.transform;
            }
            return(nodeConfig);
        }
示例#19
0
        public BehaviorNodeConfig NodeDataToNodeConfig(BehaviorNodeData nodeData)
        {
            GameObject         go         = new GameObject();
            BehaviorNodeConfig nodeConfig = go.AddComponent <BehaviorNodeConfig>();

            nodeConfig.id             = nodeData.nodeId;
            ((Object)nodeConfig).name = nodeData.name;
            go.name             = nodeData.name;
            nodeConfig.describe = nodeData.describe;
            List <string> unUseList = new List <string>();

            foreach (var args in nodeData.args_dict)
            {
                if (!ExportNodeTypeConfig.NodeHasField(nodeData.name, args.Key))
                {
                    unUseList.Add(args.Key);
                    continue;
                }
                Type originType = ExportNodeTypeConfig.GetFieldType(nodeData.name, args.Key);
                try
                {
                    string    fieldName     = args.Key;
                    object    fieldValue    = args.Value.GetValueByType(originType);
                    Type      type          = BTTypeManager.GetBTType(originType);
                    Component comp          = go.AddComponent(type);
                    FieldInfo fieldNameInfo = type.GetField("fieldName");
                    fieldNameInfo.SetValue(comp, fieldName);
                    FieldInfo fieldValueinfo = type.GetField("fieldValue");
                    if (BehaviorTreeArgsDict.IsEnumType(originType))
                    {
                        fieldValue = fieldValue.ToString();
                    }
                    fieldValueinfo.SetValue(comp, fieldValue);
                }
                catch (Exception e)
                {
                    throw new Exception($"transform failed,nodeName:{nodeData.name}  fieldName:{args.Key} fieldType:{originType}", e);
                }
            }
            foreach (string key in unUseList)
            {
                nodeData.args_dict.Remove(key);
            }
            foreach (var child in nodeData.children)
            {
                BehaviorNodeConfig childConfig = NodeDataToNodeConfig(child);
                childConfig.gameObject.transform.parent = nodeConfig.gameObject.transform;
            }
            return(nodeConfig);
        }
示例#20
0
        //private List<NodeFieldDesc> GetFieldDescList(NodeProto nodeProto, Type type)
        //{
        //	List<NodeFieldDesc> list = NodeMetaHelper.GetNodeFieldInOutPutDescList(nodeProto.name, type);
        //	foreach (NodeProto childProto in nodeProto.children)
        //	{
        //		list.AddRange(GetFieldDescList(childProto, type));
        //	}
        //	return list;
        //}

        public BehaviorNodeData CreateNode(string nodeName)
        {
            if (!this.GetComponent <BTNodeInfoComponent>().ContainsKey(nodeName))
            {
                Debug.LogError($"节点类型:{nodeName}不存在");
                return(null);
            }
            BehaviorNodeData node = new BehaviorNodeData(nodeName)
            {
                Id   = AutoNodeId(),
                Name = nodeName
            };

            return(node);
        }
示例#21
0
        public BehaviorNodeData NodeProtoToNodeData(NodeProto nodeProto)
        {
            BehaviorNodeData nodeData = new BehaviorNodeData();

            nodeData.nodeId    = nodeProto.nodeId;
            nodeData.name      = nodeProto.name;
            nodeData.describe  = nodeProto.describe;
            nodeData.args_dict = nodeProto.args_dict;
            nodeData.children  = new List <BehaviorNodeData>();
            foreach (var child in nodeProto.children)
            {
                nodeData.children.Add(this.NodeProtoToNodeData(child));
            }
            return(nodeData);
        }
示例#22
0
        public List <string> GetCanInPutEnvKeyList(BehaviorNodeData nodeData, NodeFieldDesc desc)
        {
            List <string>    list1   = Instance.GetNodeOutPutEnvKeyList(nodeData, desc);
            HashSet <string> hashSet = new HashSet <string>();

            foreach (string item in list1)
            {
                hashSet.Add(item);
            }
            List <string> resultList = new List <string>();

            foreach (string item in hashSet)
            {
                resultList.Add(item);
            }
            return(resultList);
        }
示例#23
0
        public NodeProto BehaviorNodeDataToNodeProto(BehaviorNodeData nodeData)
        {
            NodeProto nodeProto = new NodeProto
            {
                Id       = nodeData.Id,
                Name     = nodeData.Name,
                Desc     = nodeData.Desc,
                Args     = nodeData.Args,
                children = new List <NodeProto>()
            };

            foreach (BehaviorNodeData child in nodeData.children)
            {
                nodeProto.children.Add(this.BehaviorNodeDataToNodeProto(child));
            }
            return(nodeProto);
        }
示例#24
0
        public BehaviorNodeData NodeProtoToBehaviorNodeData(NodeProto nodeProto)
        {
            BehaviorNodeData nodeData = new BehaviorNodeData
            {
                Id       = nodeProto.Id,
                Name     = nodeProto.Name,
                Desc     = nodeProto.Desc,
                Args     = nodeProto.Args,
                children = new List <BehaviorNodeData>()
            };

            foreach (NodeProto child in nodeProto.children)
            {
                nodeData.children.Add(this.NodeProtoToBehaviorNodeData(child));
            }
            return(nodeData);
        }
示例#25
0
        public BehaviorNodeData GetNodeData(BehaviorNodeData nodeData, int nodeId)
        {
            BehaviorNodeData result = null;

            if (nodeData.Id == nodeId)
            {
                return(nodeData);
            }
            foreach (BehaviorNodeData child in nodeData.children)
            {
                result = GetNodeData(child, nodeId);
                if (result != null)
                {
                    break;
                }
            }
            return(result);
        }
示例#26
0
        public NodeProto NodeDataToNodeProto(BehaviorNodeData nodeData)
        {
            NodeProto nodeProto = new NodeProto();

            nodeProto.nodeId   = nodeData.nodeId;
            nodeProto.name     = nodeData.name;
            nodeProto.describe = nodeData.describe;

            nodeProto.nodeIdList = new List <int>();
            nodeProto.args_dict  = nodeData.args_dict;
            nodeProto.children   = new List <NodeProto>();
            foreach (var child in nodeData.children)
            {
                nodeProto.children.Add(NodeDataToNodeProto(child));
                nodeProto.nodeIdList.Add(child.nodeId);
            }
            return(nodeProto);
        }
示例#27
0
        public NodeDesigner CreateNode(BehaviorNodeData nodeData, Vector2 pos)
        {
            NodeDesigner node = new NodeDesigner(nodeData);

            node.Pos = pos == Vector2.zero? CenterPosInBorder() : pos;
            if (mSelectedNode != null)
            {
                mSelectedNode.AddChild(node);
                mSelectedNode.AutoSort();
            }
            else
            {
                mDetachedNodes.Add(node);
            }
            BehaviorManager.GetInstance().ResetTreeId();
            Game.Scene.GetComponent <EventComponent>().Run(EventIdType.BehaviorTreeCreateNode, node);
            return(node);
        }
示例#28
0
        public BehaviorNodeData NodeConfigToNodeData(BehaviorNodeConfig nodeProto)
        {
            BehaviorNodeData nodeData = new BehaviorNodeData()
            {
                Id       = nodeProto.id,
                Name     = nodeProto.name,
                Desc     = nodeProto.describe,
                Args     = nodeProto.GetArgsDict(),
                children = new List <BehaviorNodeData>()
            };

            foreach (Transform child in nodeProto.gameObject.transform)
            {
                BehaviorNodeConfig nodeConfig = child.gameObject.GetComponent <BehaviorNodeConfig>();
                BehaviorNodeData   childData  = NodeConfigToNodeData(nodeConfig);
                nodeData.children.Add(childData);
            }
            return(nodeData);
        }
示例#29
0
        public bool IsHighLight(BehaviorNodeData node)
        {
            NodeProto            nodeProto = NodeDataToNodeProto(node);
            List <NodeFieldDesc> list      = ExportNodeTypeConfig.GetNodeFieldInOutPutDescList(nodeProto.name, typeof(NodeOutputAttribute));

            foreach (var desc in list)
            {
                if (!nodeProto.args_dict.ContainsKey(desc.name))
                {
                    continue;
                }
                string        value      = nodeProto.args_dict.GetTreeDictValue(desc.type, desc.name)?.ToString();
                List <string> resultList = inputValueList.FindAll(str => { return(str == value); });
                if (resultList.Count > 0)
                {
                    return(true);
                }
            }
            return(false);
        }
示例#30
0
        public bool IsHighLight(BehaviorNodeData node)
        {
            NodeProto            nodeProto = this.BehaviorNodeDataToNodeProto(node);
            List <NodeFieldDesc> list      = NodeMetaHelper.GetNodeFieldInOutPutDescList(nodeProto.Name, typeof(NodeOutputAttribute));

            foreach (NodeFieldDesc desc in list)
            {
                if (!nodeProto.Args.ContainsKey(desc.name))
                {
                    continue;
                }
                string        value      = nodeProto.Args.Get(desc.name)?.ToString();
                List <string> resultList = inputValueList.FindAll(str => { return(str == value); });
                if (resultList.Count > 0)
                {
                    return(true);
                }
            }
            return(false);
        }