diff --git a/AssetStudio/Classes/Material.cs b/AssetStudio/Classes/Material.cs index 4569d52..9d444f3 100644 --- a/AssetStudio/Classes/Material.cs +++ b/AssetStudio/Classes/Material.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using Newtonsoft.Json; +using System.Collections.Generic; namespace AssetStudio { @@ -22,9 +23,13 @@ namespace AssetStudio public class UnityPropertySheet { + [JsonConverter(typeof(KVPConverter))] public List> m_TexEnvs; + [JsonConverter(typeof(KVPConverter))] public List> m_Ints; + [JsonConverter(typeof(KVPConverter))] public List> m_Floats; + [JsonConverter(typeof(KVPConverter))] public List> m_Colors; public UnityPropertySheet(ObjectReader reader) diff --git a/AssetStudio/Helpers/KVPConverter.cs b/AssetStudio/Helpers/KVPConverter.cs new file mode 100644 index 0000000..ab1120a --- /dev/null +++ b/AssetStudio/Helpers/KVPConverter.cs @@ -0,0 +1,35 @@ +using Newtonsoft.Json; +using System; +using System.Collections; +using System.Collections.Generic; + +namespace AssetStudio; +public class KVPConverter : JsonConverter +{ + public KVPConverter() : base() { } + + public override bool CanConvert(Type objectType) + { + throw new NotImplementedException(); + } + + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + { + throw new NotImplementedException(); + } + + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + { + var list = (IList)value; + writer.WriteStartObject(); + foreach (var val in list) + { + if (val is KeyValuePair kvp) + { + writer.WritePropertyName(kvp.Key.ToString()); + serializer.Serialize(writer, kvp.Value); + } + } + writer.WriteEndObject(); + } +}