mirror of
https://github.com/aelurum/AssetStudio.git
synced 2025-05-25 05:40:21 -04:00
Fix parsing via typetree of old Material assets
- Fixed parsing via typetree of Material assets from Unity version <5.6
This commit is contained in:
parent
fca937e5e6
commit
316837dfdf
@ -515,7 +515,7 @@ namespace AssetStudio
|
|||||||
|
|
||||||
var jsonOptions = new JsonSerializerOptions
|
var jsonOptions = new JsonSerializerOptions
|
||||||
{
|
{
|
||||||
Converters = { new JsonConverterHelper.ByteArrayConverter(), new JsonConverterHelper.PPtrConverter() },
|
Converters = { new JsonConverterHelper.ByteArrayConverter(), new JsonConverterHelper.PPtrConverter(), new JsonConverterHelper.KVPConverter() },
|
||||||
NumberHandling = JsonNumberHandling.AllowNamedFloatingPointLiterals,
|
NumberHandling = JsonNumberHandling.AllowNamedFloatingPointLiterals,
|
||||||
PropertyNameCaseInsensitive = true,
|
PropertyNameCaseInsensitive = true,
|
||||||
IncludeFields = true,
|
IncludeFields = true,
|
||||||
|
53
AssetStudio/JsonConverterHelpers/KVPConverter.cs
Normal file
53
AssetStudio/JsonConverterHelpers/KVPConverter.cs
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace AssetStudio
|
||||||
|
{
|
||||||
|
public static partial class JsonConverterHelper
|
||||||
|
{
|
||||||
|
public class KVPConverter : JsonConverterFactory
|
||||||
|
{
|
||||||
|
public override bool CanConvert(Type typeToConvert)
|
||||||
|
{
|
||||||
|
if (!typeToConvert.IsGenericType)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
var generic = typeToConvert.GetGenericTypeDefinition();
|
||||||
|
return generic == typeof(KeyValuePair<,>);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override JsonConverter CreateConverter(Type type, JsonSerializerOptions options)
|
||||||
|
{
|
||||||
|
var kvpArgs = type.GetGenericArguments();
|
||||||
|
return (JsonConverter)Activator.CreateInstance(typeof(KVPConverter<,>).MakeGenericType(kvpArgs));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class KVPConverter<TKey, TValue> : JsonConverter<KeyValuePair<TKey, TValue>>
|
||||||
|
{
|
||||||
|
public override KeyValuePair<TKey, TValue> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||||
|
{
|
||||||
|
//startKvpObject
|
||||||
|
reader.Read(); //propName
|
||||||
|
reader.Read(); //keyType
|
||||||
|
var key = reader.TokenType == JsonTokenType.StartObject
|
||||||
|
? JsonSerializer.Deserialize<Dictionary<string, TKey>>(ref reader).Values.First()
|
||||||
|
: JsonSerializer.Deserialize<TKey>(ref reader);
|
||||||
|
reader.Read(); //propName
|
||||||
|
reader.Read(); //startObject
|
||||||
|
var value = JsonSerializer.Deserialize<TValue>(ref reader, options);
|
||||||
|
reader.Read(); //endKvpObject
|
||||||
|
|
||||||
|
return new KeyValuePair<TKey, TValue>(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Write(Utf8JsonWriter writer, KeyValuePair<TKey, TValue> value, JsonSerializerOptions options)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user