Пример #1
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);
        }
Пример #2
0
        private static object GetDefaultValue(Type type, NodeFieldBaseAttribute att)
        {
            if (att.DefaultValue != null)
            {
                if ((BehaviorTreeArgsDict.IsEnumType(type) && BTEnvKey.None != att.DefaultValue.ToString()) || !BehaviorTreeArgsDict.IsEnumType(type))
                {
                    return(att.DefaultValue);
                }
            }
            object value = null;

            if (BehaviorTreeArgsDict.IsDoubleType(type))
            {
                value = default(double);
            }
            else if (BehaviorTreeArgsDict.IsStringType(type))
            {
                value = default(string);
            }
            else if (BehaviorTreeArgsDict.IsFloatType(type))
            {
                value = default(float);
            }
            else if (BehaviorTreeArgsDict.IsBoolType(type))
            {
                value = default(bool);
            }
            else if (BehaviorTreeArgsDict.IsIntType(type))
            {
                value = default(int);
            }
            else if (BehaviorTreeArgsDict.IsLongType(type))
            {
                value = default(long);
            }
            else if (BehaviorTreeArgsDict.IsIntArrType(type))
            {
                value = default(int[]);
            }
            else if (BehaviorTreeArgsDict.IsLongArrType(type))
            {
                value = default(long[]);
            }
            else if (BehaviorTreeArgsDict.IsDoubleArrType(type))
            {
                value = default(double[]);
            }
            else if (BehaviorTreeArgsDict.IsFloatArrType(type))
            {
                value = default(float[]);
            }
            else if (BehaviorTreeArgsDict.IsStringArrType(type))
            {
                value = default(string[]);
            }
            else if (BehaviorTreeArgsDict.IsObjectType(type))
            {
                value = default(Object);
            }
            else if (BehaviorTreeArgsDict.IsEnumType(type))
            {
                Array array = Enum.GetValues(type);
                value = array.GetValue(0).ToString();
            }
            else if (BehaviorTreeArgsDict.IsUnitConfigArrayType(type))
            {
            }
            else if (BehaviorTreeArgsDict.IsSpriteArrayType(type))
            {
                value = default(Sprite[]);
            }
            else if (BehaviorTreeArgsDict.IsObjectArrayType(type))
            {
                value = default(Object[]);
            }
            else if (BehaviorTreeArgsDict.IsConvertble(type))
            {
                value = 1f;
            }
            else
            {
                Log.Error($"行为树节点暂时未支持此类型:{type}!");
                return(null);
            }
            return(value);
        }
Пример #3
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);
     }
 }