示例#1
0
文件: BTEditor.cs 项目: HusKka/NiuNiu
        private static List <NodeFieldDesc> _GetNodeOutPutEnvKeyList(NodeProto nodeProto, NodeProto inputNode, NodeFieldDesc desc = null)
        {
            if (nodeProto.Id >= inputNode.Id)
            {
                return(new List <NodeFieldDesc>());
            }
            List <NodeFieldDesc> list = new List <NodeFieldDesc>();

            if (desc == null)
            {
                list = NodeMetaHelper.GetNodeFieldInOutPutDescList(nodeProto.Name, typeof(NodeOutputAttribute));
            }
            else
            {
                list = NodeMetaHelper.GetNodeFieldInOutPutFilterDescList(nodeProto.Name, typeof(NodeOutputAttribute), desc.envKeyType);
            }
            for (int i = 0; i < list.Count; i++)
            {
                object value = nodeProto.Args.Get(list[i].name);
                list[i].value = value;
            }

            foreach (NodeProto childProto in nodeProto.children)
            {
                list.AddRange(_GetNodeOutPutEnvKeyList(childProto, inputNode, desc));
            }
            return(list);
        }
示例#2
0
文件: BTEditor.cs 项目: HusKka/NiuNiu
        public List <string> GetSelectNodeInputValueList(NodeProto nodeProto)
        {
            List <string>        resultList = new List <string>();
            List <NodeFieldDesc> list       = NodeMetaHelper.GetNodeFieldInOutPutDescList(nodeProto.Name, typeof(NodeInputAttribute));

            foreach (NodeFieldDesc desc in list)
            {
                string value = nodeProto.Args.Get(desc.name)?.ToString();
                resultList.Add(value);
            }
            return(resultList);
        }
示例#3
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);
        }
示例#4
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);
        }
示例#5
0
 public static bool HasNodeField(NodeProto node, Type searchType, string prefabPath)
 {
     FieldInfo[] fieldInfos = NodeMetaHelper.GetFieldInfos(node.Name);
     foreach (FieldInfo 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);
 }
示例#6
0
        public void LoadNodeTypeProto()
        {
            this.nameNodeMetas = NodeMetaHelper.ExportToDict();

            foreach (NodeMeta nodeType in this.nameNodeMetas.Values)
            {
                if (nodeType.isDeprecated)
                {
                    continue;
                }
                string classify = nodeType.classify;
                if (classify == "")
                {
                    classify = "未分类";
                }
                if (!this.classifyNodeMetas.ContainsKey(classify))
                {
                    this.classifyNodeMetas.Add(classify, new List <NodeMeta>());
                }
                this.classifyNodeMetas[classify].Add(nodeType);
            }
        }
示例#7
0
文件: BTEditor.cs 项目: HusKka/NiuNiu
        public bool CheckNodeInput(NodeProto nodeProto)
        {
            List <NodeFieldDesc> list = NodeMetaHelper.GetNodeFieldInOutPutDescList(nodeProto.Name, typeof(NodeInputAttribute));

            foreach (NodeFieldDesc desc in list)
            {
                List <string> canInputList = GetCanInPutEnvKeyList(this.NodeProtoToBehaviorNodeData(nodeProto), desc);
                string        value        = nodeProto.Args.Get(desc.name)?.ToString();
                List <string> resultList   = canInputList.FindAll(str => str == value);
                if (resultList.Count == 0)
                {
                    Log.Error($"{nodeProto.Name}节点(id:{nodeProto.Id})的{value}输入值非法!");
                    return(false);
                }
            }
            foreach (NodeProto child in nodeProto.children)
            {
                if (!CheckNodeInput(child))
                {
                    return(false);
                }
            }
            return(true);
        }
示例#8
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 = NodeMetaHelper.GetFieldType(nodeName, desc.name);
                NodeMeta      nodeMeta  = BTEditor.Instance.GetComponent <BTNodeInfoComponent>().GetNodeMeta(nodeName);

                // 如果不存在这个参数,给一个默认的
                if (!mCurBehaviorNode.Args.ContainsKey(desc.name))
                {
                    object obj = desc.value ?? BTTypeManager.GetDefaultValue(fieldType);
                    mCurBehaviorNode.Args.Add(desc.name, obj);
                }

                object newValue = null;
                if (TypeHelper.IsStringType(fieldType))
                {
                    if (nodeParamType == NodeParamType.Input)
                    {
                        newValue = InputEnumFieldValue(desc);
                    }
                    else if (nodeParamType == NodeParamType.Output && nodeMeta.classify == NodeClassifyType.Root.ToString())
                    {
                        newValue = ConstTextFieldValue(desc);
                    }
                    else
                    {
                        newValue = TextFieldValue(desc);
                    }
                }
                else if (TypeHelper.IsFloatType(fieldType))
                {
                    newValue = FloatFieldValue(desc);
                }
                else if (TypeHelper.IsDoubleType(fieldType))
                {
                    newValue = DoubletFieldValue(desc);
                }
                else if (TypeHelper.IsIntType(fieldType))
                {
                    newValue = IntFieldValue(desc);
                }
                else if (TypeHelper.IsLongType(fieldType))
                {
                    newValue = LongFieldValue(desc);
                }
                else if (TypeHelper.IsBoolType(fieldType))
                {
                    newValue = BoolFieldValue(desc);
                }
                else if (TypeHelper.IsObjectType(fieldType))
                {
                    newValue = ObjectFieldValue(desc);
                }
                else if (TypeHelper.IsIntArrType(fieldType))
                {
                    newValue = IntArrFieldValue(desc);
                }
                else if (TypeHelper.IsLongArrType(fieldType))
                {
                    newValue = LongArrFieldValue(desc);
                }
                else if (TypeHelper.IsStringArrType(fieldType))
                {
                    newValue = StrArrFieldValue(desc);
                }
                else if (TypeHelper.IsFloatArrType(fieldType))
                {
                    newValue = FloatArrFieldValue(desc);
                }
                else if (TypeHelper.IsDoubleArrType(fieldType))
                {
                    newValue = DoubleArrFieldValue(desc);
                }
                else if (TypeHelper.IsEnumType(fieldType))
                {
                    newValue = EnumFieldValue(desc);
                }
                else if (TypeHelper.IsObjectArrayType(fieldType))
                {
                    newValue = ObjectArrFieldValue(desc);
                }
                else
                {
                    Log.Error($"行为树节点暂时未支持此类型:{fieldType}!");
                    return;
                }
                mCurBehaviorNode.Args.SetKeyValueComp(desc.name, newValue);
            }
        }