3using Newtonsoft.Json.Serialization;
4using Newtonsoft.Json.Linq;
5using System.Reflection;
13 public override void WriteJson(JsonWriter writer,
object value, JsonSerializer serializer)
15 JObject o =
new JObject();
17 o.Add(
"$type", value.GetType().AssemblyQualifiedName);
21 o.Add(
"00", matrix[0,0]);
22 o.Add(
"01", matrix[0,1]);
23 o.Add(
"02", matrix[0,2]);
24 o.Add(
"03", matrix[0,3]);
26 o.Add(
"10", matrix[1,0]);
27 o.Add(
"11", matrix[1,1]);
28 o.Add(
"12", matrix[1,2]);
29 o.Add(
"13", matrix[1,3]);
31 o.Add(
"20", matrix[2,0]);
32 o.Add(
"21", matrix[2,1]);
33 o.Add(
"22", matrix[2,2]);
34 o.Add(
"23", matrix[2,3]);
36 o.Add(
"30", matrix[3,0]);
37 o.Add(
"31", matrix[3,1]);
38 o.Add(
"32", matrix[3,2]);
39 o.Add(
"33", matrix[3,3]);
41 o.WriteTo(writer, serializer.Converters.ToArray());
44 public override object ReadJson(JsonReader reader, Type objectType,
object existingValue, JsonSerializer serializer)
46 JObject o = JObject.Load(reader);
48 Matrix4x4 matrix = Matrix4x4.identity;
50 matrix[0,0] = (float) o.GetValue(
"00");
51 matrix[0,1] = (float) o.GetValue(
"01");
52 matrix[0,2] = (float) o.GetValue(
"02");
53 matrix[0,3] = (float) o.GetValue(
"03");
55 matrix[1,0] = (float) o.GetValue(
"10");
56 matrix[1,1] = (float) o.GetValue(
"11");
57 matrix[1,2] = (float) o.GetValue(
"12");
58 matrix[1,3] = (float) o.GetValue(
"13");
60 matrix[2,0] = (float) o.GetValue(
"20");
61 matrix[2,1] = (float) o.GetValue(
"21");
62 matrix[2,2] = (float) o.GetValue(
"22");
63 matrix[2,3] = (float) o.GetValue(
"23");
65 matrix[3,0] = (float) o.GetValue(
"30");
66 matrix[3,1] = (float) o.GetValue(
"31");
67 matrix[3,2] = (float) o.GetValue(
"32");
68 matrix[3,3] = (float) o.GetValue(
"33");
75 return typeof(
UnityEngine.Matrix4x4).IsAssignableFrom(objectType);
override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
override bool CanConvert(Type objectType)
override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)