-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Based on commit c4ce7e5 Created by CircleCI job Build #1218 https://circleci.com/gh/jilleJr/Newtonsoft.Json-for-Unity.Converters/1218
- Loading branch information
Showing
12 changed files
with
104 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,4 +27,4 @@ | |
"define": "HAVE_MODULE_PHYSICS2D" | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
|
||
using System.Runtime.CompilerServices; | ||
|
||
[assembly: InternalsVisibleTo("Newtonsoft.Json.UnityConverters.Addressables")] | ||
[assembly: InternalsVisibleTo("Newtonsoft.Json.UnityConverters.Editor")] | ||
[assembly: InternalsVisibleTo("Newtonsoft.Json.UnityConverters.Tests")] | ||
[assembly: InternalsVisibleTo("Newtonsoft.Json.UnityConverters.Tests.Addressables")] |
2 changes: 1 addition & 1 deletion
2
UnityConverters/Properties.meta → UnityConverters/Addressables.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System; | ||
using Newtonsoft.Json.UnityConverters.Helpers; | ||
using UnityEngine.AddressableAssets; | ||
|
||
namespace Newtonsoft.Json.UnityConverters.Addressables | ||
{ | ||
public class AssetReferenceConverter : JsonConverter | ||
{ | ||
public override bool CanConvert(Type objectType) | ||
{ | ||
return objectType == typeof(AssetReference); | ||
} | ||
|
||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) | ||
{ | ||
if (reader.TokenType == JsonToken.Null) | ||
{ | ||
return null; | ||
} | ||
|
||
if (reader.TokenType == JsonToken.String && reader.Value is string stringValue) | ||
{ | ||
return new AssetReference(stringValue); | ||
} | ||
else | ||
{ | ||
throw reader.CreateSerializationException($"Expected string when reading UnityEngine.Addressables.AssetReference type, got '{reader.TokenType}' <{reader.Value}>."); | ||
} | ||
} | ||
|
||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) | ||
{ | ||
if (value is null || string.IsNullOrEmpty(((AssetReference)value).AssetGUID)) | ||
{ | ||
writer.WriteNull(); | ||
} | ||
else | ||
{ | ||
writer.WriteValue(((AssetReference)value).AssetGUID); | ||
} | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...onverters/Properties/AssemblyInfo.cs.meta → ...ressables/AssetReferenceConverter.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
24 changes: 24 additions & 0 deletions
24
UnityConverters/Addressables/Newtonsoft.Json.UnityConverters.Addressables.asmdef
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"name": "Newtonsoft.Json.UnityConverters.Addressables", | ||
"references": [ | ||
"Unity.Addressables", | ||
"Newtonsoft.Json.UnityConverters" | ||
], | ||
"optionalUnityReferences": [], | ||
"includePlatforms": [], | ||
"excludePlatforms": [], | ||
"allowUnsafeCode": false, | ||
"overrideReferences": false, | ||
"precompiledReferences": [], | ||
"autoReferenced": true, | ||
"defineConstraints": [ | ||
"HAVE_MODULE_ADDRESSABLES" | ||
], | ||
"versionDefines": [ | ||
{ | ||
"name": "com.unity.addressables", | ||
"expression": "", | ||
"define": "HAVE_MODULE_ADDRESSABLES" | ||
} | ||
] | ||
} |
7 changes: 7 additions & 0 deletions
7
UnityConverters/Addressables/Newtonsoft.Json.UnityConverters.Addressables.asmdef.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters