Skip to content

Commit

Permalink
Json.NET Unity Converters 1.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
applejag committed Aug 16, 2022
1 parent 6064d12 commit 4506a61
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Unity Converters for Newtonsoft.Json changelog

## 1.5.0 (2022-08-16)

- Added support for `UnityEngine.AddressableAssets.AssetReferenceT<T>`, in
addition to the existing support for the non-generic `AssetReference` version
introduced in v1.4.0.

Thanks [@kyverr](https://github.com/kyverr) for the implementation ([#71](https://github.com/jilleJr/Newtonsoft.Json-for-Unity.Converters/pull/71))

## 1.4.0 (2022-02-05)

- Added support for `UnityEngine.AddressableAssets.AssetReference`.
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2019 Kalle Jillheden (jilleJr)
Copyright (c) 2019 Kalle Fagerberg (jilleJr)

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Please see the [CHANGELOG.md][package-changelog] file inside this package.

This package is licensed under The MIT License (MIT)

Copyright (c) 2019 Kalle Jillheden (jilleJr)
Copyright (c) 2019 Kalle Fagerberg (jilleJr)
<https://github.com/jilleJr/Newtonsoft.Json-for-Unity.Converters>

See full copyrights in [LICENSE.md][package-license] inside repository
Expand Down
10 changes: 8 additions & 2 deletions UnityConverters/Addressables/AssetReferenceConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class AssetReferenceConverter : JsonConverter
{
public override bool CanConvert(Type objectType)
{
return objectType == typeof(AssetReference);
return objectType == typeof(AssetReference) || (objectType.IsGenericType && objectType.GetGenericTypeDefinition() == typeof(AssetReferenceT<>));
}

public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
Expand All @@ -20,7 +20,13 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist

if (reader.TokenType == JsonToken.String && reader.Value is string stringValue)
{
return new AssetReference(stringValue);
if (objectType.IsGenericType && objectType.GetGenericTypeDefinition() == typeof(AssetReferenceT<>))
{
return Activator.CreateInstance(objectType, stringValue);
} else
{
return new AssetReference(stringValue);
}
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "jillejr.newtonsoft.json-for-unity.converters",
"displayName": "Json.NET Converters of Unity types",
"version": "1.4.0",
"version": "1.5.0",
"unity": "2018.1",
"description": "This package contains converters to and from common Unity types for Newtonsoft.Json. Types such as Vector2, Vector3, Matrix4x4, Quaternions, Color, even ScriptableObject, and more.\n\nGoes hand in hand with the jillejr.newtonsoft.json-for-unity package.\n\nThis package is licensed under The MIT License (MIT)\n\nCopyright © 2019 Kalle Jillheden (jilleJr)\nhttps://github.com/jilleJr/Newtonsoft.Json-for-Unity.Converters\n\nCopyright © 2020 Wanzyee Studio\nhttp://wanzyeestudio.blogspot.com/2017/03/jsonnet-converters.html\n\nCopyright © 2007 ParentElement\nhttps://github.com/ianmacgillivray/Json-NET-for-Unity\n\nCopyright © 2017 .NET Foundation and Contributors\nhttps://github.com/dotnet/runtime\n\nSee full copyrights in LICENSE.md inside package",
"description": "This package contains converters to and from common Unity types for Newtonsoft.Json. Types such as Vector2, Vector3, Matrix4x4, Quaternions, Color, even ScriptableObject, and more.\n\nGoes hand in hand with the jillejr.newtonsoft.json-for-unity package.\n\nThis package is licensed under The MIT License (MIT)\n\nCopyright © 2019 Kalle Fagerberg (jilleJr)\nhttps://github.com/jilleJr/Newtonsoft.Json-for-Unity.Converters\n\nCopyright © 2020 Wanzyee Studio\nhttp://wanzyeestudio.blogspot.com/2017/03/jsonnet-converters.html\n\nCopyright © 2007 ParentElement\nhttps://github.com/ianmacgillivray/Json-NET-for-Unity\n\nCopyright © 2017 .NET Foundation and Contributors\nhttps://github.com/dotnet/runtime\n\nSee full copyrights in LICENSE.md inside package",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
Expand Down

0 comments on commit 4506a61

Please sign in to comment.