Ejemplo n.º 1
0
 public override bool printHead(ref object data, Type type)
 {
     btnStype.alignment = TextAnchor.MiddleRight;
     EditorGUILayout.LabelField("[List<" + type.GetGenericArguments()[0].Name + ">]");
     if (GUILayout.Button("+", btnStype, GUILayout.Width(20f)))
     {
         if (data == null)
         {
             data = InstanceUtility.InstanceOfType(type);
         }
         else
         {
             var list = data as IList;
             InstanceUtility.resizeList(list, list.Count + 1);
         }
         return(true);
     }
     if (GUILayout.Button("-", btnStype, GUILayout.Width(20)))
     {
         if (data == null)
         {
             return(false);
         }
         var list = data as IList;
         if (list.Count == 0)
         {
             return(false);
         }
         InstanceUtility.resizeList(list, list.Count - 1);
         return(true);
     }
     return(false);
 }
Ejemplo n.º 2
0
 public override bool printHead(ref object data, Type type)
 {
     btnStype.alignment = TextAnchor.MiddleRight;
     EditorGUILayout.LabelField("[Array of " + type.GetElementType().Name + "]");
     if (GUILayout.Button("+", btnStype, GUILayout.Width(20f)))
     {
         if (data == null)
         {
             data = InstanceUtility.InstanceOfType(type);
         }
         else
         {
             var array    = data as Array;
             var newArray = InstanceUtility.resizeArray(array, array.Length + 1);
             data = newArray;
         }
         return(true);
     }
     if (GUILayout.Button("-", btnStype, GUILayout.Width(20)))
     {
         if (data == null)
         {
             return(false);
         }
         var array = data as Array;
         if (array.Length == 0)
         {
             return(false);
         }
         var newArray = InstanceUtility.resizeArray(array, array.Length - 1);
         data = newArray;
         return(true);
     }
     return(false);
 }
Ejemplo n.º 3
0
        private static void WriteConfigAsJson(Type type, string folder)
        {
            var exportFields = type.GetFields(BindingFlags.Public | BindingFlags.Instance);

            if (exportFields.Length == 0)
            {
                return;
            }
            _serializer.Config.CustomDateTimeFormatString = "G";
            _serializer.AddConverter(new MyCustomEnumConverter());
            _serializer.AddConverter(new MyDictionaryConverter());
            var ins = InstanceUtility.InstanceOfType(type);

            foreach (var field in exportFields)
            {
                if (field.GetValue(ins) == null)
                {
                    var value = InstanceUtility.InstanceOfType(field.FieldType);
                    field.SetValue(ins, value);
                }
                XlsxNameAttribute xlxsName     = (XlsxNameAttribute)Attribute.GetCustomAttribute(field, typeof(XlsxNameAttribute));
                string            jsonFilename = xlxsName != null ? xlxsName.xlsxName : field.Name;
                var    file = Path.Combine(folder, jsonFilename + ".json");
                fsData data;
                _serializer.TrySerialize(field.FieldType, field.GetValue(ins), out data).AssertSuccess();
                WriteDataToJson(file, data);
                if (TypeUtility.HasAttribute <LocaleAttribute>(field.FieldType))
                {
                    file = Path.Combine(folder, jsonFilename + ".locale.json");
                    _serializer.TrySerialize(typeof(Dictionary <string, LocaleJsonObject>), localeDict, out data).AssertSuccess();
                    WriteDataToJson(file, data);
                }
            }
        }
Ejemplo n.º 4
0
    public override bool printHead(ref object data, Type type)
    {
        btnStype.alignment = TextAnchor.MiddleRight;
        var args      = type.GetGenericArguments();
        var keyType   = args[0];
        var valueType = args[1];

        EditorGUILayout.LabelField("[Dict<" + keyType.Name + ", " + valueType.Name + ">]");
        if (GUILayout.Button("+", btnStype, GUILayout.Width(20f)))
        {
            if (data == null)
            {
                data = InstanceUtility.InstanceOfType(type);
            }
            else
            {
                InstanceUtility.addKeyValuePair(data as IDictionary, keyType, valueType);
            }
            return(true);
        }
        return(false);
    }