3using Newtonsoft.Json.Serialization;
4using Newtonsoft.Json.Linq;
5using System.Reflection;
16 public override void WriteObjectJson(JsonWriter writer,
object value, JsonSerializer serializer)
18 JObject o =
new JObject();
22 o.Add(
"$type", value.GetType().AssemblyQualifiedName);
24 o.Add(
"vertices", JArray.FromObject(m.vertices, serializer));
25 o.Add(
"bindposes", JArray.FromObject(m.bindposes, serializer));
26 o.Add(
"boneWeights", JArray.FromObject(m.boneWeights, serializer));
27 o.Add(
"colors", JArray.FromObject(m.colors, serializer));
28 o.Add(
"colors32", JArray.FromObject(m.colors32, serializer));
29 o.Add(
"normals", JArray.FromObject(m.normals, serializer));
30 o.Add(
"tangents", JArray.FromObject(m.tangents, serializer));
31 o.Add(
"uv", JArray.FromObject(m.uv, serializer));
32 o.Add(
"uv2", JArray.FromObject(m.uv2, serializer));
33 o.Add(
"uv3", JArray.FromObject(m.uv3, serializer));
34 o.Add(
"uv4", JArray.FromObject(m.uv4, serializer));
36 o.Add(
"subMeshCount", m.subMeshCount);
38 for(
int i = 0; i < m.subMeshCount; i++)
40 o.Add(
"meshTopology" + i, (
int) m.GetTopology(i));
41 o.Add(
"submesh" + i, JArray.FromObject(m.GetTriangles(i)));
45 o.Add(
"hideFlags", (
int) m.hideFlags);
46 o.Add(
"name", m.name);
47 o.WriteTo(writer, serializer.Converters.ToArray());
50 public override object ReadJsonObject(JObject o, Type objectType,
object existingValue, JsonSerializer serializer)
54 Matrix4x4[] bindposes = o.GetValue(
"bindposes").ToObject<Matrix4x4[]>();
55 BoneWeight[] boneWeights = o.GetValue(
"boneWeights").ToObject<BoneWeight[]>();
56 Color[] colors = o.GetValue(
"colors").ToObject<
Color[]>();
57 Color32[] colors32 = o.GetValue(
"colors32").ToObject<Color32[]>();
58 Vector3[] normals = o.GetValue(
"normals").ToObject<Vector3[]>();
59 Vector4[] tangents = o.GetValue(
"tangents").ToObject<Vector4[]>();
60 Vector2[] uv = o.GetValue(
"uv").ToObject<Vector2[]>();
61 Vector2[] uv2 = o.GetValue(
"uv2").ToObject<Vector2[]>();
62 Vector2[] uv3 = o.GetValue(
"uv3").ToObject<Vector2[]>();
63 Vector2[] uv4 = o.GetValue(
"uv4").ToObject<Vector2[]>();
64 Vector3[] vertices = o.GetValue(
"vertices").ToObject<Vector3[]>();
66 m.vertices = vertices;
67 m.bindposes = bindposes;
68 m.boneWeights = boneWeights;
70 m.colors32 = colors32;
72 m.tangents = tangents;
78 int subMeshCount = (int) o.GetValue(
"subMeshCount");
79 m.subMeshCount = subMeshCount;
81 for(
int i = 0; i < subMeshCount; i++)
83 int[] indices = (
int[]) o.GetValue(
"submesh" + i).ToObject<
int[]>();
84 MeshTopology topo = (MeshTopology) (
int) o.GetValue(
"meshTopology" + i);
85 m.SetIndices(indices, topo, i);
88 m.hideFlags = (HideFlags) (
int) o.GetValue(
"hideFlags");
89 m.name = o.GetValue(
"name").ToObject<
string>();
override void WriteObjectJson(JsonWriter writer, object value, JsonSerializer serializer)
override object ReadJsonObject(JObject o, Type objectType, object existingValue, JsonSerializer serializer)