Example #1
0
        private List <NodeFieldDesc> _GetNodeOutPutEnvKeyList(NodeProto nodeProto, NodeProto inputNode, NodeFieldDesc desc = null)
        {
            if (nodeProto.nodeId >= inputNode.nodeId)
            {
                return(new List <NodeFieldDesc>());
            }
            List <NodeFieldDesc> list = new List <NodeFieldDesc>();

            if (desc == null)
            {
                list = ExportNodeTypeConfig.GetNodeFieldInOutPutDescList(nodeProto.name, typeof(NodeOutputAttribute));
            }
            else
            {
                list = ExportNodeTypeConfig.GetNodeFieldInOutPutFilterDescList(nodeProto.name, typeof(NodeOutputAttribute), desc.envKeyType);
            }
            for (int i = 0; i < list.Count; i++)
            {
                object value = nodeProto.args_dict.GetTreeDictValue(list[i].type, list[i].name);
                list[i].value = value;
            }

            foreach (NodeProto childProto in nodeProto.children)
            {
                list.AddRange(_GetNodeOutPutEnvKeyList(childProto, inputNode, desc));
            }
            return(list);
        }
Example #2
0
        private List <NodeFieldDesc> GetFieldDescList(NodeProto nodeProto, Type type)
        {
            List <NodeFieldDesc> list = ExportNodeTypeConfig.GetNodeFieldInOutPutDescList(nodeProto.name, type);

            foreach (NodeProto childProto in nodeProto.children)
            {
                list.AddRange(GetFieldDescList(childProto, type));
            }
            return(list);
        }
Example #3
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);
        }
Example #4
0
 public static bool HasNodeField(NodeProto node, Type searchType, string prefabPath)
 {
     FieldInfo[] fieldInfos = ExportNodeTypeConfig.GetFieldInfos(node.name);
     foreach (var fieldInfo in fieldInfos)
     {
         if (fieldInfo.FieldType == searchType)
         {
             Log.Info($"{prefabPath}");
             return(true);
         }
     }
     for (int i = 0; i < node.children.Count; i++)
     {
         if (HasNodeField(node.children[i], searchType, prefabPath))
         {
             return(true);
         }
     }
     return(false);
 }
Example #5
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);
        }
Example #6
0
        public List <string> GetSelectNodeInputValueList(NodeProto nodeProto)
        {
            List <string>        resultList = new List <string>();
            List <NodeFieldDesc> list       = ExportNodeTypeConfig.GetNodeFieldInOutPutDescList(nodeProto.name, typeof(NodeInputAttribute));

            foreach (var desc in list)
            {
                if (!nodeProto.args_dict.ContainsKey(desc.name))
                {
                    ValueBase valueBase = new ValueBase();
                    nodeProto.args_dict.Add(desc.name, valueBase);
                }
                if (string.IsNullOrEmpty(nodeProto.args_dict[desc.name].enumValue))
                {
                    nodeProto.args_dict[desc.name].enumValue = BTEnvKey.None;
                }
                string value = nodeProto.args_dict.GetTreeDictValue(desc.type, desc.name)?.ToString();
                resultList.Add(value);
            }
            return(resultList);
        }
Example #7
0
        public void RemoveUnusedArgs(NodeProto nodeProto)
        {
            ClientNodeTypeProto proto      = ExportNodeTypeConfig.GetNodeTypeProtoFromDll(nodeProto.name);
            List <string>       unUsedList = new List <string>();

            foreach (var item in nodeProto.args_dict)
            {
                if (!proto.new_args_desc.Exists(a => (a.name == item.Key)))
                {
                    unUsedList.Add(item.Key);
                }
            }
            foreach (var item in unUsedList)
            {
                nodeProto.args_dict.Remove(item);
            }
            for (int i = 0; i < nodeProto.children.Count; i++)
            {
                RemoveUnusedArgs(nodeProto.children[i]);
            }
        }
        public List <string> Filter(List <string> list, string text)
        {
            List <string> result1 = new List <string>();
            string        selectType;

            if (mEnumNodeTypeSelection == 0)
            {
                selectType = "All";
                result1    = list;
            }
            else
            {
                selectType = Enum.GetName(typeof(NodeClassifyType), mEnumNodeTypeSelection - 1);
                foreach (var name in list)
                {
                    ClientNodeTypeProto proto = ExportNodeTypeConfig.GetNodeTypeProtoFromDll(name);
                    if (selectType == proto.classify)
                    {
                        result1.Add(name);
                    }
                }
            }

            if (string.IsNullOrEmpty(text))
            {
                return(result1);
            }

            List <string> result2 = new List <string>();

            foreach (var name in result1)
            {
                ClientNodeTypeProto proto = ExportNodeTypeConfig.GetNodeTypeProtoFromDll(name);
                if (name.ToUpper().Contains(text.ToUpper()) || proto.describe.ToUpper().Contains(text.ToUpper()))
                {
                    result2.Add(name);
                }
            }
            return(result2);
        }
Example #9
0
        public bool CheckNodeInput(NodeProto nodeProto)
        {
            List <NodeFieldDesc> list = ExportNodeTypeConfig.GetNodeFieldInOutPutDescList(nodeProto.name, typeof(NodeInputAttribute));

            foreach (var desc in list)
            {
                List <string> canInputList = GetCanInPutEnvKeyList(NodeProtoToNodeData(nodeProto), desc);
                string        value        = nodeProto.args_dict.GetTreeDictValue(desc.type, desc.name)?.ToString();
                List <string> resultList   = canInputList.FindAll(str => { return(str == value); });
                if (resultList.Count == 0)
                {
                    Log.Error($"{nodeProto.name}节点(id:{nodeProto.nodeId})的{value}输入值非法!");
                    return(false);
                }
            }
            foreach (var child in nodeProto.children)
            {
                if (!CheckNodeInput(child))
                {
                    return(false);
                }
            }
            return(true);
        }
Example #10
0
        //节点配置 get set
        public ClientNodeTypeProto GetNodeTypeProto(string name)
        {
            ClientNodeTypeProto proto = ExportNodeTypeConfig.GetNodeTypeProtoFromDll(name);

            return(proto);
        }
Example #11
0
 public void LoadNodeTypeProto()
 {
     mName2NodeProtoDict = ExportNodeTypeConfig.ExportToDict();
 }
Example #12
0
 private void DrawProp(string nodeName, List <NodeFieldDesc> fieldList, NodeParamType nodeParamType)
 {
     for (int i = 0; i < fieldList.Count; i++)
     {
         NodeFieldDesc       desc       = fieldList[i];
         Type                fieldType  = ExportNodeTypeConfig.GetFieldType(nodeName, desc.name);
         ClientNodeTypeProto clientNode = ExportNodeTypeConfig.GetNodeTypeProtoFromDll(nodeName);
         object              newValue   = null;
         if (!mCurBehaviorNode.args_dict.ContainsKey(desc.name))
         {
             mCurBehaviorNode.args_dict.Add(desc.name, new ValueBase());
         }
         if (BehaviorTreeArgsDict.IsStringType(fieldType))
         {
             if (nodeParamType == NodeParamType.Input)
             {
                 newValue = InputEnumFieldValue(desc);
             }
             else if (nodeParamType == NodeParamType.Output && clientNode.classify == NodeClassifyType.Root.ToString())
             {
                 newValue = ConstTextFieldValue(desc);
             }
             else
             {
                 newValue = TextFieldValue(desc);
             }
         }
         else if (BehaviorTreeArgsDict.IsFloatType(fieldType))
         {
             newValue = FloatFieldValue(desc);
         }
         else if (BehaviorTreeArgsDict.IsDoubleType(fieldType))
         {
             newValue = DoubletFieldValue(desc);
         }
         else if (BehaviorTreeArgsDict.IsIntType(fieldType))
         {
             newValue = IntFieldValue(desc);
         }
         else if (BehaviorTreeArgsDict.IsLongType(fieldType))
         {
             newValue = LongFieldValue(desc);
         }
         else if (BehaviorTreeArgsDict.IsBoolType(fieldType))
         {
             newValue = BoolFieldValue(desc);
         }
         else if (BehaviorTreeArgsDict.IsObjectType(fieldType))
         {
             newValue = ObjectFieldValue(desc);
         }
         else if (BehaviorTreeArgsDict.IsIntArrType(fieldType))
         {
             newValue = IntArrFieldValue(desc);
         }
         else if (BehaviorTreeArgsDict.IsLongArrType(fieldType))
         {
             newValue = LongArrFieldValue(desc);
         }
         else if (BehaviorTreeArgsDict.IsStringArrType(fieldType))
         {
             newValue = StrArrFieldValue(desc);
         }
         else if (BehaviorTreeArgsDict.IsFloatArrType(fieldType))
         {
             newValue = FloatArrFieldValue(desc);
         }
         else if (BehaviorTreeArgsDict.IsDoubleArrType(fieldType))
         {
             newValue = DoubleArrFieldValue(desc);
         }
         else if (BehaviorTreeArgsDict.IsEnumType(fieldType))
         {
             if (nodeParamType == NodeParamType.Input)
             {
                 newValue = InputEnumFieldValue(desc);
             }
             else if (nodeParamType == NodeParamType.Output)
             {
                 newValue = OutPutEnumFieldValue(desc);
             }
             else
             {
                 newValue = EnumFieldValue(desc);
             }
         }
         else if (BehaviorTreeArgsDict.IsObjectArrayType(fieldType))
         {
             newValue = ObjectArrFieldValue(desc);
         }
         else
         {
             Log.Error($"行为树节点暂时未支持此类型:{fieldType}!");
             return;
         }
         mCurBehaviorNode.args_dict.SetKeyValueComp(fieldType, desc.name, newValue);
     }
 }
        public string DrawSearchList()
        {
            List <string> targetList = new List <string>();

            if (mSubWinType == SubWinType.CreateNode)
            {
                targetList = GraphDesigner.GetCanCreateList();
            }
            else if (mSubWinType == SubWinType.ReplaceNode)
            {
                targetList = GraphDesigner.GetCanRepalceList();
            }

            List <string> nodeNameList = Filter(targetList, mSearchNode);

            GUILayout.BeginHorizontal();
            GUI.SetNextControlName("Search");
            this.mSearchNode = GUILayout.TextField(this.mSearchNode, GUI.skin.FindStyle("ToolbarSeachTextField"));
            GUI.FocusControl("Search");
            GUILayout.EndHorizontal();
            //
            toolbarRect = new Rect(0f, 15f + 20, mWidth, 25f);
            Rect boxRect = new Rect(0f, toolbarRect.height, this.mWidth, (Screen.height - toolbarRect.height) - 21f + 10);

            GUILayout.BeginArea(toolbarRect, EditorStyles.toolbar);
            GUILayout.BeginHorizontal();

            GUILayout.Label("Filter");
            Array         strArr  = Enum.GetValues(typeof(NodeClassifyType));
            List <string> strList = new List <string>();

            strList.Add("All");
            foreach (var str in strArr)
            {
                strList.Add(str.ToString());
            }
            mEnumNodeTypeArr       = strList.ToArray();
            mEnumNodeTypeSelection = EditorGUILayout.Popup(mEnumNodeTypeSelection, mEnumNodeTypeArr);
            if (GUILayout.Button("Clear"))
            {
                ClearNodes();
            }
            GUILayout.EndHorizontal();
            GUILayout.EndArea();
            //

            GUILayout.BeginArea(new Rect(0, 0, windowRect.width, windowRect.height));
            float topSpace = 60;

            this.mTreeScrollPos = GUI.BeginScrollView(new Rect(0f, topSpace, windowRect.width, windowRect.height - topSpace), this.mTreeScrollPos,
                                                      new Rect(0f, 0f, windowRect.width - 20f, nodeNameList.Count * 19), false, true);

            foreach (var name in nodeNameList)
            {
                ClientNodeTypeProto proto = ExportNodeTypeConfig.GetNodeTypeProtoFromDll(name);
                if (GUILayout.Button(name + $"({proto.describe})", GetButtonStyle()))
                {
                    if (SubWinType.CreateNode == mSubWinType)
                    {
                        GraphDesigner.onCreateNode(name, Vector2.zero);
                    }
                    else if (SubWinType.ReplaceNode == mSubWinType)
                    {
                        GraphDesigner.onChangeNodeType(name, Vector2.zero);
                    }
                    BehaviorDesignerWindow.Instance.CloseSubWin();
                }
            }

            GUI.EndScrollView();
            GUILayout.EndArea();

            return("");
        }