Esempio n. 1
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));
        }
Esempio n. 2
0
 public NodeDesigner(BehaviorNodeData data)
 {
     NodeData     = data;
     DesignerData = new NodeDesignerProto();
     Init();
     UpdateChildren();
 }
Esempio n. 3
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);
        }
Esempio n. 4
0
 public void PrintTree(BehaviorNodeData nodeData)
 {
     Log.Info($"PrintTree  :  {nodeData.Id} {nodeData}");
     foreach (BehaviorNodeData data in nodeData.children)
     {
         this.PrintTree(data);
     }
 }
Esempio n. 5
0
 private static void _ClearDebugState(BehaviorNodeData nodeData)
 {
     nodeData.NodeDeubgState = DebugState.Normal;
     foreach (BehaviorNodeData child in nodeData.children)
     {
         _ClearDebugState(child);
     }
 }
Esempio n. 6
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);
        }
Esempio n. 7
0
 private void SetDebugState(int nodeId)
 {
     if (this.BehaviorTreeConfig != null)
     {
         BehaviorNodeData nodeData = GetNodeData(CurTree.Root, nodeId);
         if (nodeData != null)
         {
             nodeData.NodeDeubgState = DebugState.True;
         }
     }
 }
Esempio n. 8
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);
 }
Esempio n. 9
0
 public void PasteNode()
 {
     if (mCutNode != null && mCutNode != mSelectedNode)
     {
         ConnectNode(mCutNode, mSelectedNode);
     }
     if (mCopyNode != null && mCopyNode != mSelectedNode)
     {
         BehaviorNodeData data = BTEditor.Instance.CopyNode(mCopyNode.NodeData);
         BTEditor.Instance.ResetTreeId();
         NodeDesigner node = CreateNode(data, Vector2.zero);
         ConnectNode(node, mSelectedNode);
     }
 }
Esempio n. 10
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);
        }
Esempio n. 11
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);
        }
Esempio n. 12
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);
        }
Esempio n. 13
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);
        }
Esempio n. 14
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);
        }
Esempio n. 15
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);
        }
Esempio n. 16
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);
        }
Esempio n. 17
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);
        }
Esempio n. 18
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);
        }
Esempio n. 19
0
        public NodeDesigner CreateNode(BehaviorNodeData nodeData, Vector2 pos)
        {
            NodeDesigner node = new NodeDesigner(nodeData)
            {
                Pos = pos == Vector2.zero ? CenterPosInBorder() : pos
            };

            if (mSelectedNode != null)
            {
                mSelectedNode.AddChild(node);
                mSelectedNode.AutoSort();
            }
            else
            {
                mDetachedNodes.Add(node);
            }
            BTEditor.Instance.ResetTreeId();
            Game.EventSystem.Run(EventIdType.BehaviorTreeCreateNode, node);
            return(node);
        }
Esempio n. 20
0
        public BehaviorNodeData CopyNode(BehaviorNodeData node)
        {
            BehaviorNodeData copyNode = new BehaviorNodeData
            {
                Name = node.Name,
                Desc = node.Desc,
                Pos  = node.Pos,
                Args = node.Args.Clone()
            };
            List <BehaviorNodeData> list = new List <BehaviorNodeData>();

            foreach (BehaviorNodeData item in node.children)
            {
                list.Add(item);
            }
            foreach (BehaviorNodeData child in list)
            {
                copyNode.AddChild(CopyNode(child));
            }
            copyNode.ResetId();
            return(copyNode);
        }
Esempio n. 21
0
        public string[] GetCanInPutEnvKeyArray(BehaviorNodeData nodeData, NodeFieldDesc desc)
        {
            List <string> list1 = new List <string>();

            list1.AddRange(Instance.GetNodeOutPutEnvKeyList(nodeData, desc));
            list1.Add(BTEnvKey.None);
            HashSet <string> hashSet = new HashSet <string>();

            foreach (string item in list1)
            {
                hashSet.Add(item);
            }

            string[] strArr = new string[hashSet.Count];
            int      i      = 0;

            foreach (string str in hashSet)
            {
                strArr[i++] = str;
            }
            return(strArr);
        }
Esempio n. 22
0
 public void onSelectNode(params object[] list)
 {
     mCurBehaviorNode = (BehaviorNodeData)list[0];
     GUI.FocusControl("");
 }
Esempio n. 23
0
        public void SelectNode(BehaviorNodeData node)
        {
            NodeProto nodeProto = this.BehaviorNodeDataToNodeProto(node);

            inputValueList = GetSelectNodeInputValueList(nodeProto);
        }
Esempio n. 24
0
 //默认添加到末尾
 public void AddChild(BehaviorNodeData node, int index = -1)
 {
     index = index == -1? this.Children.Count : index;
     children.Insert(index, node);
     node.Parent = this;
 }
Esempio n. 25
0
 public BehaviorNodeData RemoveChild(BehaviorNodeData node)
 {
     node.Parent = null;
     children.Remove(node);
     return(node);
 }
Esempio n. 26
0
 public void onMouseInNode(BehaviorNodeData nodeData, NodeDesigner nodeDesigner)
 {
     this.GraphDesigner.onMouseInNode(nodeData, nodeDesigner);
 }