Skip to content

Commit

Permalink
ConverterInitializer now trys to load and modify the DefaultSettings …
Browse files Browse the repository at this point in the history
…first.
  • Loading branch information
DeathTBO committed Jul 9, 2019
1 parent db2dccb commit 257ba10
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions Assets/Newtonsoft.Json.Unity/ConverterInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ static void OnBeforeSceneLoadRuntimeMethod()

//Called when scripts are recompiled.
//This is so Json.Net works in Editor Windows
#if UNITY_EDITOR
#if UNITY_EDITOR
[UnityEditor.Callbacks.DidReloadScripts]
static void OnScriptsReloaded()
{
Initialize();
}
#endif
#endif

static void Initialize()
{
Expand All @@ -33,17 +33,15 @@ static void Initialize()
//These properties return a new instance of the class, so during serialization
//They cause an endless loop
//These custom converters only save the x/y/z/w values
JsonConvert.DefaultSettings = () => new JsonSerializerSettings
{
Converters = new List<JsonConverter>
{
new JsonVector2Converter(),
new JsonVector3Converter(),
new JsonVector4Converter(),
new JsonQuaternionConverter()
}
};
JsonSerializerSettings currentSettings = JsonConvert.DefaultSettings?.Invoke() ?? new JsonSerializerSettings();

currentSettings.Converters.Add(new JsonVector2Converter());
currentSettings.Converters.Add(new JsonVector3Converter());
currentSettings.Converters.Add(new JsonVector4Converter());
currentSettings.Converters.Add(new JsonQuaternionConverter());

JsonConvert.DefaultSettings = () => currentSettings;

initialized = true;
}
}
Expand Down

0 comments on commit 257ba10

Please sign in to comment.