예제 #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));
        }
예제 #2
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);
        }
예제 #3
0
 public NodeDesigner(BehaviorNodeData data)
 {
     NodeData     = data;
     DesignerData = new NodeDesignerProto();
     Init();
     UpdateChildren();
 }
예제 #4
0
파일: BTEditor.cs 프로젝트: HusKka/NiuNiu
 private static void _ClearDebugState(BehaviorNodeData nodeData)
 {
     nodeData.NodeDeubgState = DebugState.Normal;
     foreach (BehaviorNodeData child in nodeData.children)
     {
         _ClearDebugState(child);
     }
 }
예제 #5
0
파일: BTEditor.cs 프로젝트: HusKka/NiuNiu
 public void PrintTree(BehaviorNodeData nodeData)
 {
     Log.Info($"PrintTree  :  {nodeData.Id} {nodeData}");
     foreach (BehaviorNodeData data in nodeData.children)
     {
         this.PrintTree(data);
     }
 }
예제 #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);
        }
예제 #7
0
파일: BTEditor.cs 프로젝트: HusKka/NiuNiu
 private void SetDebugState(int nodeId)
 {
     if (this.BehaviorTreeConfig != null)
     {
         BehaviorNodeData nodeData = GetNodeData(CurTree.Root, nodeId);
         if (nodeData != null)
         {
             nodeData.NodeDeubgState = DebugState.True;
         }
     }
 }
예제 #8
0
파일: BTEditor.cs 프로젝트: HusKka/NiuNiu
 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);
 }
예제 #9
0
파일: BTEditor.cs 프로젝트: HusKka/NiuNiu
        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);
        }
예제 #10
0
파일: BTEditor.cs 프로젝트: HusKka/NiuNiu
        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);
        }
예제 #11
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);
     }
 }
예제 #12
0
파일: BTEditor.cs 프로젝트: HusKka/NiuNiu
        //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);
        }
예제 #13
0
파일: BTEditor.cs 프로젝트: HusKka/NiuNiu
        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);
        }
예제 #14
0
파일: BTEditor.cs 프로젝트: HusKka/NiuNiu
        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);
        }
예제 #15
0
파일: BTEditor.cs 프로젝트: HusKka/NiuNiu
        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);
        }
예제 #16
0
파일: BTEditor.cs 프로젝트: HusKka/NiuNiu
        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);
        }
예제 #17
0
파일: BTEditor.cs 프로젝트: HusKka/NiuNiu
        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);
        }
예제 #18
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);
        }
예제 #19
0
파일: BTEditor.cs 프로젝트: HusKka/NiuNiu
        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);
        }
예제 #20
0
파일: BTEditor.cs 프로젝트: HusKka/NiuNiu
        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);
        }
예제 #21
0
파일: BTEditor.cs 프로젝트: HusKka/NiuNiu
        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);
        }
예제 #22
0
 public void onSelectNode(params object[] list)
 {
     mCurBehaviorNode = (BehaviorNodeData)list[0];
     GUI.FocusControl("");
 }
예제 #23
0
 public void onMouseInNode(BehaviorNodeData nodeData, NodeDesigner nodeDesigner)
 {
     this.GraphDesigner.onMouseInNode(nodeData, nodeDesigner);
 }
예제 #24
0
 public BehaviorNodeData RemoveChild(BehaviorNodeData node)
 {
     node.Parent = null;
     children.Remove(node);
     return(node);
 }
예제 #25
0
파일: BTEditor.cs 프로젝트: HusKka/NiuNiu
        public void SelectNode(BehaviorNodeData node)
        {
            NodeProto nodeProto = this.BehaviorNodeDataToNodeProto(node);

            inputValueList = GetSelectNodeInputValueList(nodeProto);
        }
예제 #26
0
 //默认添加到末尾
 public void AddChild(BehaviorNodeData node, int index = -1)
 {
     index = index == -1? this.Children.Count : index;
     children.Insert(index, node);
     node.Parent = this;
 }