Skip to content

Commit 4506a61

Browse files
committed
Json.NET Unity Converters 1.5.0
Based on commit b8559b8 Created by CircleCI job Build #1336 https://circleci.com/gh/jilleJr/Newtonsoft.Json-for-Unity.Converters/1336
1 parent 6064d12 commit 4506a61

File tree

5 files changed

+20
-6
lines changed

5 files changed

+20
-6
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Unity Converters for Newtonsoft.Json changelog
22

3+
## 1.5.0 (2022-08-16)
4+
5+
- Added support for `UnityEngine.AddressableAssets.AssetReferenceT<T>`, in
6+
addition to the existing support for the non-generic `AssetReference` version
7+
introduced in v1.4.0.
8+
9+
Thanks [@kyverr](https://github.com/kyverr) for the implementation ([#71](https://github.com/jilleJr/Newtonsoft.Json-for-Unity.Converters/pull/71))
10+
311
## 1.4.0 (2022-02-05)
412

513
- Added support for `UnityEngine.AddressableAssets.AssetReference`.

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2019 Kalle Jillheden (jilleJr)
3+
Copyright (c) 2019 Kalle Fagerberg (jilleJr)
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy of
66
this software and associated documentation files (the "Software"), to deal in

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Please see the [CHANGELOG.md][package-changelog] file inside this package.
2929

3030
This package is licensed under The MIT License (MIT)
3131

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

3535
See full copyrights in [LICENSE.md][package-license] inside repository

UnityConverters/Addressables/AssetReferenceConverter.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class AssetReferenceConverter : JsonConverter
88
{
99
public override bool CanConvert(Type objectType)
1010
{
11-
return objectType == typeof(AssetReference);
11+
return objectType == typeof(AssetReference) || (objectType.IsGenericType && objectType.GetGenericTypeDefinition() == typeof(AssetReferenceT<>));
1212
}
1313

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

2121
if (reader.TokenType == JsonToken.String && reader.Value is string stringValue)
2222
{
23-
return new AssetReference(stringValue);
23+
if (objectType.IsGenericType && objectType.GetGenericTypeDefinition() == typeof(AssetReferenceT<>))
24+
{
25+
return Activator.CreateInstance(objectType, stringValue);
26+
} else
27+
{
28+
return new AssetReference(stringValue);
29+
}
2430
}
2531
else
2632
{

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"name": "jillejr.newtonsoft.json-for-unity.converters",
33
"displayName": "Json.NET Converters of Unity types",
4-
"version": "1.4.0",
4+
"version": "1.5.0",
55
"unity": "2018.1",
6-
"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",
6+
"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",
77
"main": "index.js",
88
"scripts": {
99
"test": "echo \"Error: no test specified\" && exit 1"

0 commit comments

Comments
 (0)