diff --git a/Source/Engine/Serialization/JsonSerializer.cs b/Source/Engine/Serialization/JsonSerializer.cs
index 127fa4d87..b3bd51d6f 100644
--- a/Source/Engine/Serialization/JsonSerializer.cs
+++ b/Source/Engine/Serialization/JsonSerializer.cs
@@ -7,6 +7,7 @@ using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
+using FlaxEngine.GUI;
using FlaxEngine.Json.JsonCustomSerializers;
using FlaxEngine.Utilities;
using Newtonsoft.Json;
@@ -119,6 +120,115 @@ namespace FlaxEngine.Json
}
}
+ ///
+ /// Serialize SoftObjectReference as Guid in internal format.
+ ///
+ ///
+ internal class MarginConverter : JsonConverter
+ {
+ ///
+ public override void WriteJson(JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var valueMargin = (Margin)value;
+
+ writer.WriteStartObject();
+ {
+ writer.WritePropertyName("Left");
+ writer.WriteValue(valueMargin.Left);
+ writer.WritePropertyName("Right");
+ writer.WriteValue(valueMargin.Right);
+ writer.WritePropertyName("Top");
+ writer.WriteValue(valueMargin.Top);
+ writer.WritePropertyName("Bottom");
+ writer.WriteValue(valueMargin.Bottom);
+ }
+ writer.WriteEndObject();
+ }
+
+ ///
+ public override void WriteJsonDiff(JsonWriter writer, object value, object other, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var valueMargin = (Margin)value;
+ var otherMargin = (Margin)other;
+ writer.WriteStartObject();
+ if (!Mathf.NearEqual(valueMargin.Left, otherMargin.Left))
+ {
+ writer.WritePropertyName("Left");
+ writer.WriteValue(valueMargin.Left);
+ }
+ if (!Mathf.NearEqual(valueMargin.Right, otherMargin.Right))
+ {
+ writer.WritePropertyName("Right");
+ writer.WriteValue(valueMargin.Right);
+ }
+ if (!Mathf.NearEqual(valueMargin.Top, otherMargin.Top))
+ {
+ writer.WritePropertyName("Top");
+ writer.WriteValue(valueMargin.Top);
+ }
+ if (!Mathf.NearEqual(valueMargin.Bottom, otherMargin.Bottom))
+ {
+ writer.WritePropertyName("Bottom");
+ writer.WriteValue(valueMargin.Bottom);
+ }
+ writer.WriteEndObject();
+ }
+
+ ///
+ public override object ReadJson(JsonReader reader, Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var value = (Margin?)existingValue ?? new Margin();
+ if (reader.TokenType == JsonToken.StartObject)
+ {
+ while (reader.Read())
+ {
+ switch (reader.TokenType)
+ {
+ case JsonToken.PropertyName:
+ {
+ var propertyName = (string)reader.Value;
+ var propertyValue = (float)reader.ReadAsDouble();
+ switch (propertyName)
+ {
+ case "Left":
+ value.Left = propertyValue;
+ break;
+ case "Right":
+ value.Right = propertyValue;
+ break;
+ case "Top":
+ value.Top = propertyValue;
+ break;
+ case "Bottom":
+ value.Bottom = propertyValue;
+ break;
+ }
+ break;
+ }
+ case JsonToken.Comment: break;
+ default: return value;
+ }
+ }
+ }
+ return value;
+ }
+
+ ///
+ public override bool CanConvert(Type objectType)
+ {
+ return objectType == typeof(Margin);
+ }
+
+ ///
+ public override bool CanRead => true;
+
+ ///
+ public override bool CanWrite => true;
+
+ ///
+ public override bool CanWriteDiff => true;
+ }
+
/*
///
/// Serialize Guid values using `N` format
@@ -219,6 +329,7 @@ namespace FlaxEngine.Json
settings.Converters.Add(ObjectConverter);
settings.Converters.Add(new SceneReferenceConverter());
settings.Converters.Add(new SoftObjectReferenceConverter());
+ settings.Converters.Add(new MarginConverter());
settings.Converters.Add(new VersionConverter());
//settings.Converters.Add(new GuidConverter());
return settings;
diff --git a/Source/Platforms/DotNet/Newtonsoft.Json.dll b/Source/Platforms/DotNet/Newtonsoft.Json.dll
index 17df31d86..b08068dd3 100644
--- a/Source/Platforms/DotNet/Newtonsoft.Json.dll
+++ b/Source/Platforms/DotNet/Newtonsoft.Json.dll
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
-oid sha256:616780417730a6371909713a2d8150347870e67ed52803642caef37e8bda1891
-size 630272
+oid sha256:7ed0cb43a692d86f2d47bfc93475e554ee8a70b33187b1e1d2356a7d4f25fffa
+size 629760
diff --git a/Source/Platforms/DotNet/Newtonsoft.Json.pdb b/Source/Platforms/DotNet/Newtonsoft.Json.pdb
index 68e8489b6..9d8502e2c 100644
--- a/Source/Platforms/DotNet/Newtonsoft.Json.pdb
+++ b/Source/Platforms/DotNet/Newtonsoft.Json.pdb
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
-oid sha256:9d4fc76d2ef9b0cd7b88da95f4894d9cc924703af0b02e052f8e78446f75e2d9
-size 239080
+oid sha256:5e5b77e2864fee56c380d85c8d1488713c5ba5deacb9005d125d9e47629014e8
+size 249884
diff --git a/Source/Platforms/DotNet/Newtonsoft.Json.xml b/Source/Platforms/DotNet/Newtonsoft.Json.xml
index fb9404249..c1d3cfd3d 100644
--- a/Source/Platforms/DotNet/Newtonsoft.Json.xml
+++ b/Source/Platforms/DotNet/Newtonsoft.Json.xml
@@ -1691,6 +1691,15 @@
The value.
The calling serializer.
+
+
+ Writes the JSON representation of the object diff compared to other instance of the object (the same type).
+
+ The to write to.
+ The value.
+ The other value (the same type).
+ The calling serializer.
+
Reads the JSON representation of the object.
@@ -1722,6 +1731,12 @@
true if this can write JSON; otherwise, false.
+
+
+ Gets a value indicating whether this can write JSON for object difference.
+
+ true if this can write JSON diff; otherwise, false.
+
Converts an object to and from JSON.