From 97030b19404bd6cdd35c6a941ca9bdfcce0a6aeb Mon Sep 17 00:00:00 2001 From: SullyunShin Date: Thu, 6 Mar 2025 12:15:53 +0900 Subject: [PATCH] =?UTF-8?q?MessagePack=20IL2CPP=20=EB=B9=8C=EB=93=9C=20?= =?UTF-8?q?=EB=AC=B8=EC=A0=9C=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MessagePack Resolver 스크립트 빌드 후 추가 MessagePack Object Key type string -> integer 로 변경 MessagePackSerializerOptions에 Resolver 추가 --- Assets/Scripts/CustomMessagePackResolver.cs | 34 + .../Scripts/CustomMessagePackResolver.cs.meta | 2 + .../Scripts/GeneratedMessagePackResolver.cs | 758 ++++++++++++++++++ .../GeneratedMessagePackResolver.cs.meta | 2 + .../Scripts/XED/AssetTool/SaveLoadFBXData.cs | 127 +-- 5 files changed, 878 insertions(+), 45 deletions(-) create mode 100644 Assets/Scripts/CustomMessagePackResolver.cs create mode 100644 Assets/Scripts/CustomMessagePackResolver.cs.meta create mode 100644 Assets/Scripts/GeneratedMessagePackResolver.cs create mode 100644 Assets/Scripts/GeneratedMessagePackResolver.cs.meta diff --git a/Assets/Scripts/CustomMessagePackResolver.cs b/Assets/Scripts/CustomMessagePackResolver.cs new file mode 100644 index 00000000..cc50b54f --- /dev/null +++ b/Assets/Scripts/CustomMessagePackResolver.cs @@ -0,0 +1,34 @@ +using UnityEngine; +using MessagePack; +using MessagePack.Formatters; +using MessagePack.Resolvers; +using System; +using System.Collections.Generic; +public class CustomMessagePackResolver : IFormatterResolver +{ + public static readonly IFormatterResolver Instance = new CustomMessagePackResolver(); + + private static readonly Dictionary formatters = new Dictionary + { + { typeof(XED.Asset.MaterialPropertyData), new MessagePack.Formatters.XED.Asset.MaterialPropertyDataFormatter() }, + { typeof(XED.Asset.ModelData), new MessagePack.Formatters.XED.Asset.ModelDataFormatter() }, + { typeof(XED.Asset.SaveData), new MessagePack.Formatters.XED.Asset.SaveDataFormatter() }, + { typeof(XED.Asset.SavedModelData), new MessagePack.Formatters.XED.Asset.SavedModelDataFormatter() }, + { typeof(XED.Asset.SerializableMesh), new MessagePack.Formatters.XED.Asset.SerializableMeshFormatter() }, + { typeof(XED.Asset.SerializableQuaternion), new MessagePack.Formatters.XED.Asset.SerializableQuaternionFormatter() }, + { typeof(XED.Asset.SerializableVector2), new MessagePack.Formatters.XED.Asset.SerializableVector2Formatter() }, + { typeof(XED.Asset.SerializableVector3), new MessagePack.Formatters.XED.Asset.SerializableVector3Formatter() }, + { typeof(XED.Asset.SubmeshData), new MessagePack.Formatters.XED.Asset.SubmeshDataFormatter() }, + { typeof(XED.Asset.TextureData), new MessagePack.Formatters.XED.Asset.TextureDataFormatter() }, + { typeof(XED.Asset.TransformData), new MessagePack.Formatters.XED.Asset.TransformDataFormatter() }, + }; + + public IMessagePackFormatter GetFormatter() + { + if (formatters.TryGetValue(typeof(T), out var formatter)) + { + return (IMessagePackFormatter)formatter; + } + return StandardResolver.Instance.GetFormatter(); + } +} diff --git a/Assets/Scripts/CustomMessagePackResolver.cs.meta b/Assets/Scripts/CustomMessagePackResolver.cs.meta new file mode 100644 index 00000000..3c80afab --- /dev/null +++ b/Assets/Scripts/CustomMessagePackResolver.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 47d35b011d941df44a78fe2904fcc881 \ No newline at end of file diff --git a/Assets/Scripts/GeneratedMessagePackResolver.cs b/Assets/Scripts/GeneratedMessagePackResolver.cs new file mode 100644 index 00000000..b8a4e1a3 --- /dev/null +++ b/Assets/Scripts/GeneratedMessagePackResolver.cs @@ -0,0 +1,758 @@ +// +// THIS (.cs) FILE IS GENERATED BY MPC(MessagePack-CSharp). DO NOT CHANGE IT. +// + +#pragma warning disable 618 +#pragma warning disable 612 +#pragma warning disable 414 +#pragma warning disable 168 +#pragma warning disable CS1591 // document public APIs + +#pragma warning disable SA1312 // Variable names should begin with lower-case letter +#pragma warning disable SA1649 // File name should match first type name + +namespace MessagePack.Resolvers +{ + public class GeneratedResolver : global::MessagePack.IFormatterResolver + { + public static readonly global::MessagePack.IFormatterResolver Instance = new GeneratedResolver(); + + private GeneratedResolver() + { + } + + public global::MessagePack.Formatters.IMessagePackFormatter GetFormatter() + { + return FormatterCache.Formatter; + } + + private static class FormatterCache + { + internal static readonly global::MessagePack.Formatters.IMessagePackFormatter Formatter; + + static FormatterCache() + { + var f = GeneratedResolverGetFormatterHelper.GetFormatter(typeof(T)); + if (f != null) + { + Formatter = (global::MessagePack.Formatters.IMessagePackFormatter)f; + } + } + } + } + + internal static class GeneratedResolverGetFormatterHelper + { + private static readonly global::System.Collections.Generic.Dictionary lookup; + + static GeneratedResolverGetFormatterHelper() + { + lookup = new global::System.Collections.Generic.Dictionary(18) + { + { typeof(global::XED.Asset.MaterialPropertyData[]), 0 }, + { typeof(global::XED.Asset.ModelData[]), 1 }, + { typeof(global::XED.Asset.SavedModelData[]), 2 }, + { typeof(global::XED.Asset.SerializableVector2[]), 3 }, + { typeof(global::XED.Asset.SerializableVector3[]), 4 }, + { typeof(global::XED.Asset.SubmeshData[]), 5 }, + { typeof(global::XED.Asset.TextureData[]), 6 }, + { typeof(global::XED.Asset.MaterialPropertyData), 7 }, + { typeof(global::XED.Asset.ModelData), 8 }, + { typeof(global::XED.Asset.SaveData), 9 }, + { typeof(global::XED.Asset.SavedModelData), 10 }, + { typeof(global::XED.Asset.SerializableMesh), 11 }, + { typeof(global::XED.Asset.SerializableQuaternion), 12 }, + { typeof(global::XED.Asset.SerializableVector2), 13 }, + { typeof(global::XED.Asset.SerializableVector3), 14 }, + { typeof(global::XED.Asset.SubmeshData), 15 }, + { typeof(global::XED.Asset.TextureData), 16 }, + { typeof(global::XED.Asset.TransformData), 17 }, + }; + } + + internal static object GetFormatter(global::System.Type t) + { + int key; + if (!lookup.TryGetValue(t, out key)) + { + return null; + } + + switch (key) + { + case 0: return new global::MessagePack.Formatters.ArrayFormatter(); + case 1: return new global::MessagePack.Formatters.ArrayFormatter(); + case 2: return new global::MessagePack.Formatters.ArrayFormatter(); + case 3: return new global::MessagePack.Formatters.ArrayFormatter(); + case 4: return new global::MessagePack.Formatters.ArrayFormatter(); + case 5: return new global::MessagePack.Formatters.ArrayFormatter(); + case 6: return new global::MessagePack.Formatters.ArrayFormatter(); + case 7: return new MessagePack.Formatters.XED.Asset.MaterialPropertyDataFormatter(); + case 8: return new MessagePack.Formatters.XED.Asset.ModelDataFormatter(); + case 9: return new MessagePack.Formatters.XED.Asset.SaveDataFormatter(); + case 10: return new MessagePack.Formatters.XED.Asset.SavedModelDataFormatter(); + case 11: return new MessagePack.Formatters.XED.Asset.SerializableMeshFormatter(); + case 12: return new MessagePack.Formatters.XED.Asset.SerializableQuaternionFormatter(); + case 13: return new MessagePack.Formatters.XED.Asset.SerializableVector2Formatter(); + case 14: return new MessagePack.Formatters.XED.Asset.SerializableVector3Formatter(); + case 15: return new MessagePack.Formatters.XED.Asset.SubmeshDataFormatter(); + case 16: return new MessagePack.Formatters.XED.Asset.TextureDataFormatter(); + case 17: return new MessagePack.Formatters.XED.Asset.TransformDataFormatter(); + default: return null; + } + } + } +} + +#pragma warning restore 168 +#pragma warning restore 414 +#pragma warning restore 618 +#pragma warning restore 612 + +#pragma warning restore SA1312 // Variable names should begin with lower-case letter +#pragma warning restore SA1649 // File name should match first type name + + + + +// +// THIS (.cs) FILE IS GENERATED BY MPC(MessagePack-CSharp). DO NOT CHANGE IT. +// + +#pragma warning disable 618 +#pragma warning disable 612 +#pragma warning disable 414 +#pragma warning disable 168 +#pragma warning disable CS1591 // document public APIs + +#pragma warning disable SA1129 // Do not use default value type constructor +#pragma warning disable SA1309 // Field names should not begin with underscore +#pragma warning disable SA1312 // Variable names should begin with lower-case letter +#pragma warning disable SA1403 // File may only contain a single namespace +#pragma warning disable SA1649 // File name should match first type name + +namespace MessagePack.Formatters.XED.Asset +{ + public sealed class MaterialPropertyDataFormatter : global::MessagePack.Formatters.IMessagePackFormatter + { + + public void Serialize(ref global::MessagePack.MessagePackWriter writer, global::XED.Asset.MaterialPropertyData value, global::MessagePack.MessagePackSerializerOptions options) + { + if (value == null) + { + writer.WriteNil(); + return; + } + + global::MessagePack.IFormatterResolver formatterResolver = options.Resolver; + writer.WriteArrayHeader(11); + global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify(formatterResolver).Serialize(ref writer, value.baseColor, options); + writer.Write(value.metallic); + writer.Write(value.smoothness); + global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify(formatterResolver).Serialize(ref writer, value.emissionColor, options); + writer.Write(value.renderMode); + writer.Write(value.surfaceType); + writer.Write(value.blendMode); + writer.Write(value.occlusionStrength); + writer.Write(value.normalScale); + global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify(formatterResolver).Serialize(ref writer, value.texTypes, options); + global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify(formatterResolver).Serialize(ref writer, value.texUIDs, options); + } + + public global::XED.Asset.MaterialPropertyData Deserialize(ref global::MessagePack.MessagePackReader reader, global::MessagePack.MessagePackSerializerOptions options) + { + if (reader.TryReadNil()) + { + return null; + } + + options.Security.DepthStep(ref reader); + global::MessagePack.IFormatterResolver formatterResolver = options.Resolver; + var length = reader.ReadArrayHeader(); + var ____result = new global::XED.Asset.MaterialPropertyData(); + + for (int i = 0; i < length; i++) + { + switch (i) + { + case 0: + ____result.baseColor = global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify(formatterResolver).Deserialize(ref reader, options); + break; + case 1: + ____result.metallic = reader.ReadSingle(); + break; + case 2: + ____result.smoothness = reader.ReadSingle(); + break; + case 3: + ____result.emissionColor = global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify(formatterResolver).Deserialize(ref reader, options); + break; + case 4: + ____result.renderMode = reader.ReadInt32(); + break; + case 5: + ____result.surfaceType = reader.ReadInt32(); + break; + case 6: + ____result.blendMode = reader.ReadInt32(); + break; + case 7: + ____result.occlusionStrength = reader.ReadSingle(); + break; + case 8: + ____result.normalScale = reader.ReadSingle(); + break; + case 9: + ____result.texTypes = global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify(formatterResolver).Deserialize(ref reader, options); + break; + case 10: + ____result.texUIDs = global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify(formatterResolver).Deserialize(ref reader, options); + break; + default: + reader.Skip(); + break; + } + } + + reader.Depth--; + return ____result; + } + } + + public sealed class ModelDataFormatter : global::MessagePack.Formatters.IMessagePackFormatter + { + + public void Serialize(ref global::MessagePack.MessagePackWriter writer, global::XED.Asset.ModelData value, global::MessagePack.MessagePackSerializerOptions options) + { + if (value == null) + { + writer.WriteNil(); + return; + } + + global::MessagePack.IFormatterResolver formatterResolver = options.Resolver; + writer.WriteArrayHeader(3); + global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify(formatterResolver).Serialize(ref writer, value.transformData, options); + global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify(formatterResolver).Serialize(ref writer, value.mesh, options); + global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify(formatterResolver).Serialize(ref writer, value.materialProperties, options); + } + + public global::XED.Asset.ModelData Deserialize(ref global::MessagePack.MessagePackReader reader, global::MessagePack.MessagePackSerializerOptions options) + { + if (reader.TryReadNil()) + { + return null; + } + + options.Security.DepthStep(ref reader); + global::MessagePack.IFormatterResolver formatterResolver = options.Resolver; + var length = reader.ReadArrayHeader(); + var ____result = new global::XED.Asset.ModelData(); + + for (int i = 0; i < length; i++) + { + switch (i) + { + case 0: + ____result.transformData = global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify(formatterResolver).Deserialize(ref reader, options); + break; + case 1: + ____result.mesh = global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify(formatterResolver).Deserialize(ref reader, options); + break; + case 2: + ____result.materialProperties = global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify(formatterResolver).Deserialize(ref reader, options); + break; + default: + reader.Skip(); + break; + } + } + + reader.Depth--; + return ____result; + } + } + + public sealed class SaveDataFormatter : global::MessagePack.Formatters.IMessagePackFormatter + { + + public void Serialize(ref global::MessagePack.MessagePackWriter writer, global::XED.Asset.SaveData value, global::MessagePack.MessagePackSerializerOptions options) + { + if (value == null) + { + writer.WriteNil(); + return; + } + + global::MessagePack.IFormatterResolver formatterResolver = options.Resolver; + writer.WriteArrayHeader(2); + global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify(formatterResolver).Serialize(ref writer, value.modelDatas, options); + global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify(formatterResolver).Serialize(ref writer, value.textureDatas, options); + } + + public global::XED.Asset.SaveData Deserialize(ref global::MessagePack.MessagePackReader reader, global::MessagePack.MessagePackSerializerOptions options) + { + if (reader.TryReadNil()) + { + return null; + } + + options.Security.DepthStep(ref reader); + global::MessagePack.IFormatterResolver formatterResolver = options.Resolver; + var length = reader.ReadArrayHeader(); + var ____result = new global::XED.Asset.SaveData(); + + for (int i = 0; i < length; i++) + { + switch (i) + { + case 0: + ____result.modelDatas = global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify(formatterResolver).Deserialize(ref reader, options); + break; + case 1: + ____result.textureDatas = global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify(formatterResolver).Deserialize(ref reader, options); + break; + default: + reader.Skip(); + break; + } + } + + reader.Depth--; + return ____result; + } + } + + public sealed class SavedModelDataFormatter : global::MessagePack.Formatters.IMessagePackFormatter + { + + public void Serialize(ref global::MessagePack.MessagePackWriter writer, global::XED.Asset.SavedModelData value, global::MessagePack.MessagePackSerializerOptions options) + { + if (value == null) + { + writer.WriteNil(); + return; + } + + global::MessagePack.IFormatterResolver formatterResolver = options.Resolver; + writer.WriteArrayHeader(3); + global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify(formatterResolver).Serialize(ref writer, value.assetName, options); + global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify(formatterResolver).Serialize(ref writer, value.folderName, options); + global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify(formatterResolver).Serialize(ref writer, value.models, options); + } + + public global::XED.Asset.SavedModelData Deserialize(ref global::MessagePack.MessagePackReader reader, global::MessagePack.MessagePackSerializerOptions options) + { + if (reader.TryReadNil()) + { + return null; + } + + options.Security.DepthStep(ref reader); + global::MessagePack.IFormatterResolver formatterResolver = options.Resolver; + var length = reader.ReadArrayHeader(); + var ____result = new global::XED.Asset.SavedModelData(); + + for (int i = 0; i < length; i++) + { + switch (i) + { + case 0: + ____result.assetName = global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify(formatterResolver).Deserialize(ref reader, options); + break; + case 1: + ____result.folderName = global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify(formatterResolver).Deserialize(ref reader, options); + break; + case 2: + ____result.models = global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify(formatterResolver).Deserialize(ref reader, options); + break; + default: + reader.Skip(); + break; + } + } + + reader.Depth--; + return ____result; + } + } + + public sealed class SerializableMeshFormatter : global::MessagePack.Formatters.IMessagePackFormatter + { + + public void Serialize(ref global::MessagePack.MessagePackWriter writer, global::XED.Asset.SerializableMesh value, global::MessagePack.MessagePackSerializerOptions options) + { + if (value == null) + { + writer.WriteNil(); + return; + } + + global::MessagePack.IFormatterResolver formatterResolver = options.Resolver; + writer.WriteArrayHeader(4); + global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify(formatterResolver).Serialize(ref writer, value.vertices, options); + global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify(formatterResolver).Serialize(ref writer, value.normals, options); + global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify(formatterResolver).Serialize(ref writer, value.uv, options); + global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify(formatterResolver).Serialize(ref writer, value.submeshes, options); + } + + public global::XED.Asset.SerializableMesh Deserialize(ref global::MessagePack.MessagePackReader reader, global::MessagePack.MessagePackSerializerOptions options) + { + if (reader.TryReadNil()) + { + return null; + } + + options.Security.DepthStep(ref reader); + global::MessagePack.IFormatterResolver formatterResolver = options.Resolver; + var length = reader.ReadArrayHeader(); + var ____result = new global::XED.Asset.SerializableMesh(); + + for (int i = 0; i < length; i++) + { + switch (i) + { + case 0: + ____result.vertices = global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify(formatterResolver).Deserialize(ref reader, options); + break; + case 1: + ____result.normals = global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify(formatterResolver).Deserialize(ref reader, options); + break; + case 2: + ____result.uv = global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify(formatterResolver).Deserialize(ref reader, options); + break; + case 3: + ____result.submeshes = global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify(formatterResolver).Deserialize(ref reader, options); + break; + default: + reader.Skip(); + break; + } + } + + reader.Depth--; + return ____result; + } + } + + public sealed class SerializableQuaternionFormatter : global::MessagePack.Formatters.IMessagePackFormatter + { + + public void Serialize(ref global::MessagePack.MessagePackWriter writer, global::XED.Asset.SerializableQuaternion value, global::MessagePack.MessagePackSerializerOptions options) + { + writer.WriteArrayHeader(4); + writer.Write(value.x); + writer.Write(value.y); + writer.Write(value.z); + writer.Write(value.w); + } + + public global::XED.Asset.SerializableQuaternion Deserialize(ref global::MessagePack.MessagePackReader reader, global::MessagePack.MessagePackSerializerOptions options) + { + if (reader.TryReadNil()) + { + throw new global::System.InvalidOperationException("typecode is null, struct not supported"); + } + + options.Security.DepthStep(ref reader); + var length = reader.ReadArrayHeader(); + var ____result = new global::XED.Asset.SerializableQuaternion(); + + for (int i = 0; i < length; i++) + { + switch (i) + { + case 0: + ____result.x = reader.ReadSingle(); + break; + case 1: + ____result.y = reader.ReadSingle(); + break; + case 2: + ____result.z = reader.ReadSingle(); + break; + case 3: + ____result.w = reader.ReadSingle(); + break; + default: + reader.Skip(); + break; + } + } + + reader.Depth--; + return ____result; + } + } + + public sealed class SerializableVector2Formatter : global::MessagePack.Formatters.IMessagePackFormatter + { + + public void Serialize(ref global::MessagePack.MessagePackWriter writer, global::XED.Asset.SerializableVector2 value, global::MessagePack.MessagePackSerializerOptions options) + { + writer.WriteArrayHeader(2); + writer.Write(value.x); + writer.Write(value.y); + } + + public global::XED.Asset.SerializableVector2 Deserialize(ref global::MessagePack.MessagePackReader reader, global::MessagePack.MessagePackSerializerOptions options) + { + if (reader.TryReadNil()) + { + throw new global::System.InvalidOperationException("typecode is null, struct not supported"); + } + + options.Security.DepthStep(ref reader); + var length = reader.ReadArrayHeader(); + var __x__ = default(float); + var __y__ = default(float); + + for (int i = 0; i < length; i++) + { + switch (i) + { + case 0: + __x__ = reader.ReadSingle(); + break; + case 1: + __y__ = reader.ReadSingle(); + break; + default: + reader.Skip(); + break; + } + } + + var ____result = new global::XED.Asset.SerializableVector2(__x__, __y__); + reader.Depth--; + return ____result; + } + } + + public sealed class SerializableVector3Formatter : global::MessagePack.Formatters.IMessagePackFormatter + { + + public void Serialize(ref global::MessagePack.MessagePackWriter writer, global::XED.Asset.SerializableVector3 value, global::MessagePack.MessagePackSerializerOptions options) + { + writer.WriteArrayHeader(3); + writer.Write(value.x); + writer.Write(value.y); + writer.Write(value.z); + } + + public global::XED.Asset.SerializableVector3 Deserialize(ref global::MessagePack.MessagePackReader reader, global::MessagePack.MessagePackSerializerOptions options) + { + if (reader.TryReadNil()) + { + throw new global::System.InvalidOperationException("typecode is null, struct not supported"); + } + + options.Security.DepthStep(ref reader); + var length = reader.ReadArrayHeader(); + var __x__ = default(float); + var __y__ = default(float); + var __z__ = default(float); + + for (int i = 0; i < length; i++) + { + switch (i) + { + case 0: + __x__ = reader.ReadSingle(); + break; + case 1: + __y__ = reader.ReadSingle(); + break; + case 2: + __z__ = reader.ReadSingle(); + break; + default: + reader.Skip(); + break; + } + } + + var ____result = new global::XED.Asset.SerializableVector3(__x__, __y__, __z__); + reader.Depth--; + return ____result; + } + } + + public sealed class SubmeshDataFormatter : global::MessagePack.Formatters.IMessagePackFormatter + { + + public void Serialize(ref global::MessagePack.MessagePackWriter writer, global::XED.Asset.SubmeshData value, global::MessagePack.MessagePackSerializerOptions options) + { + if (value == null) + { + writer.WriteNil(); + return; + } + + global::MessagePack.IFormatterResolver formatterResolver = options.Resolver; + writer.WriteArrayHeader(2); + writer.Write(value.materialIndex); + global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify(formatterResolver).Serialize(ref writer, value.triangles, options); + } + + public global::XED.Asset.SubmeshData Deserialize(ref global::MessagePack.MessagePackReader reader, global::MessagePack.MessagePackSerializerOptions options) + { + if (reader.TryReadNil()) + { + return null; + } + + options.Security.DepthStep(ref reader); + global::MessagePack.IFormatterResolver formatterResolver = options.Resolver; + var length = reader.ReadArrayHeader(); + var ____result = new global::XED.Asset.SubmeshData(); + + for (int i = 0; i < length; i++) + { + switch (i) + { + case 0: + ____result.materialIndex = reader.ReadInt32(); + break; + case 1: + ____result.triangles = global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify(formatterResolver).Deserialize(ref reader, options); + break; + default: + reader.Skip(); + break; + } + } + + reader.Depth--; + return ____result; + } + } + + public sealed class TextureDataFormatter : global::MessagePack.Formatters.IMessagePackFormatter + { + + public void Serialize(ref global::MessagePack.MessagePackWriter writer, global::XED.Asset.TextureData value, global::MessagePack.MessagePackSerializerOptions options) + { + if (value == null) + { + writer.WriteNil(); + return; + } + + global::MessagePack.IFormatterResolver formatterResolver = options.Resolver; + writer.WriteArrayHeader(3); + global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify(formatterResolver).Serialize(ref writer, value.name, options); + global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify(formatterResolver).Serialize(ref writer, value.uid, options); + writer.Write(value.data); + } + + public global::XED.Asset.TextureData Deserialize(ref global::MessagePack.MessagePackReader reader, global::MessagePack.MessagePackSerializerOptions options) + { + if (reader.TryReadNil()) + { + return null; + } + + options.Security.DepthStep(ref reader); + global::MessagePack.IFormatterResolver formatterResolver = options.Resolver; + var length = reader.ReadArrayHeader(); + var __name__ = default(string); + var __uid__ = default(string); + var __data__ = default(byte[]); + //var ____result = new global::XED.Asset.TextureData(); + + for (int i = 0; i < length; i++) + { + switch (i) + { + case 0: + //____result.name = global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify(formatterResolver).Deserialize(ref reader, options); + __name__ = global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify(formatterResolver).Deserialize(ref reader, options); + break; + case 1: + //____result.uid = global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify(formatterResolver).Deserialize(ref reader, options); + __uid__ = global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify(formatterResolver).Deserialize(ref reader, options); + break; + case 2: + //____result.data = global::MessagePack.Internal.CodeGenHelpers.GetArrayFromNullableSequence(reader.ReadBytes()); + __data__ = global::MessagePack.Internal.CodeGenHelpers.GetArrayFromNullableSequence(reader.ReadBytes()); + break; + default: + reader.Skip(); + break; + } + } + + var ____result = new global::XED.Asset.TextureData(__name__, __uid__, __data__); + reader.Depth--; + return ____result; + } + } + + public sealed class TransformDataFormatter : global::MessagePack.Formatters.IMessagePackFormatter + { + + public void Serialize(ref global::MessagePack.MessagePackWriter writer, global::XED.Asset.TransformData value, global::MessagePack.MessagePackSerializerOptions options) + { + if (value == null) + { + writer.WriteNil(); + return; + } + + global::MessagePack.IFormatterResolver formatterResolver = options.Resolver; + writer.WriteArrayHeader(3); + global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify(formatterResolver).Serialize(ref writer, value.position, options); + global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify(formatterResolver).Serialize(ref writer, value.rotation, options); + global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify(formatterResolver).Serialize(ref writer, value.scale, options); + } + + public global::XED.Asset.TransformData Deserialize(ref global::MessagePack.MessagePackReader reader, global::MessagePack.MessagePackSerializerOptions options) + { + if (reader.TryReadNil()) + { + return null; + } + + options.Security.DepthStep(ref reader); + global::MessagePack.IFormatterResolver formatterResolver = options.Resolver; + var length = reader.ReadArrayHeader(); + var ____result = new global::XED.Asset.TransformData(); + + for (int i = 0; i < length; i++) + { + switch (i) + { + case 0: + ____result.position = global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify(formatterResolver).Deserialize(ref reader, options); + break; + case 1: + ____result.rotation = global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify(formatterResolver).Deserialize(ref reader, options); + break; + case 2: + ____result.scale = global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify(formatterResolver).Deserialize(ref reader, options); + break; + default: + reader.Skip(); + break; + } + } + + reader.Depth--; + return ____result; + } + } + +} + +#pragma warning restore 168 +#pragma warning restore 414 +#pragma warning restore 618 +#pragma warning restore 612 + +#pragma warning restore SA1129 // Do not use default value type constructor +#pragma warning restore SA1309 // Field names should not begin with underscore +#pragma warning restore SA1312 // Variable names should begin with lower-case letter +#pragma warning restore SA1403 // File may only contain a single namespace +#pragma warning restore SA1649 // File name should match first type name + diff --git a/Assets/Scripts/GeneratedMessagePackResolver.cs.meta b/Assets/Scripts/GeneratedMessagePackResolver.cs.meta new file mode 100644 index 00000000..a5296bb5 --- /dev/null +++ b/Assets/Scripts/GeneratedMessagePackResolver.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: bab1dbb292003874992b64c18aaea648 \ No newline at end of file diff --git a/Assets/Scripts/XED/AssetTool/SaveLoadFBXData.cs b/Assets/Scripts/XED/AssetTool/SaveLoadFBXData.cs index 76ebc826..95e4dfb9 100644 --- a/Assets/Scripts/XED/AssetTool/SaveLoadFBXData.cs +++ b/Assets/Scripts/XED/AssetTool/SaveLoadFBXData.cs @@ -12,6 +12,7 @@ using Newtonsoft.Json; using System.Text; using System.Linq; using UnityEngine.EventSystems; +using MessagePack.Resolvers; namespace XED.Asset { @@ -28,12 +29,14 @@ namespace XED.Asset private SharedMaterial sharedMaterial; private MessagePackFileManager fileManager; private bool isSaveTaskComplete = true; - private bool isLoadTaskComplete = true; + private bool isLoadTaskComplete = true; void Start() { saveData = new SaveData(); sharedMaterial = new SharedMaterial(); fileManager = new MessagePackFileManager(); + fileManager.Initialize(); + identifier = identifier.Length == 0 ? "defaultAssetData" : identifier; StartCoroutine(CoroutineLoadLocalFiles()); string baseDataPath = Application.streamingAssetsPath + "/baseAssetData"; @@ -261,6 +264,7 @@ namespace XED.Asset if (task.Result == null) { Debug.LogError("Error on loading local data."); + Debug.LogError("Error file location : " + filePath); isLoadTaskComplete = true; yield break; } @@ -569,6 +573,13 @@ namespace XED.Asset { dicTextureIDs[tex] = texUID; Texture2D readableTex = GetReadableTexture(tex); + //TextureData textureData = new TextureData() + //{ + // name = tex.name, + // uid = texUID, + // data = readableTex.EncodeToPNG() + //}; + //textureDatas.Add(textureData); textureDatas.Add(new TextureData(tex.name, texUID, readableTex.EncodeToPNG())); } return texUID; @@ -592,19 +603,19 @@ namespace XED.Asset [MessagePackObject] public class SaveData { - [Key("ModelData")] + [Key(0)] public SavedModelData[] modelDatas; - [Key("TextureData")] + [Key(1)] public TextureData[] textureDatas; } [MessagePackObject] public class SavedModelData { - [Key("AssetName")] + [Key(0)] public string assetName; - [Key("FolderName")] + [Key(1)] public string folderName; - [Key("ModelArray")] + [Key(2)] public ModelData[] models; public void SaveData(GameObject modelObject, SharedMaterial sharedMaterial) { @@ -656,21 +667,21 @@ namespace XED.Asset [MessagePackObject] public class ModelData { - [Key("TransformData")] + [Key(0)] public TransformData transformData; - [Key("MeshData")] + [Key(1)] public SerializableMesh mesh; - [Key("MaterialData")] + [Key(2)] public MaterialPropertyData[] materialProperties; } [MessagePackObject] public class TransformData { - [Key("Position")] + [Key(0)] public SerializableVector3 position; - [Key("Rotation")] + [Key(1)] public SerializableQuaternion rotation; - [Key("Scale")] + [Key(2)] public SerializableVector3 scale; public void SetData(Transform transform) { @@ -692,13 +703,13 @@ namespace XED.Asset [MessagePackObject] public class SerializableMesh { - [Key("Vertices")] + [Key(0)] public SerializableVector3[] vertices; - [Key("Normals")] + [Key(1)] public SerializableVector3[] normals; - [Key("UVs")] + [Key(2)] public SerializableVector2[] uv; - [Key("Submeshes")] + [Key(3)] public SubmeshData[] submeshes; public void SetData(Mesh mesh) { @@ -735,20 +746,22 @@ namespace XED.Asset [MessagePackObject] public class SubmeshData { - [Key("MaterialIndex")] + [Key(0)] public int materialIndex; - [Key("Triangles")] + [Key(1)] public int[] triangles; } [MessagePackObject] public struct SerializableVector3 { - [Key("V3x")] + [Key(0)] public float x; - [Key("V3y")] + [Key(1)] public float y; - [Key("V3z")] + [Key(2)] public float z; + + [SerializationConstructor] public SerializableVector3(float x, float y, float z) { this.x = x; @@ -771,10 +784,12 @@ namespace XED.Asset [MessagePackObject] public struct SerializableVector2 { - [Key("V2x")] + [Key(0)] public float x; - [Key("V2y")] + [Key(1)] public float y; + + [SerializationConstructor] public SerializableVector2(float x, float y) { this.x = x; @@ -796,13 +811,13 @@ namespace XED.Asset [MessagePackObject] public struct SerializableQuaternion { - [Key("Qx")] + [Key(0)] public float x; - [Key("Qy")] + [Key(1)] public float y; - [Key("Qz")] + [Key(2)] public float z; - [Key("Qw")] + [Key(3)] public float w; public void FromQuaternion(Quaternion q) { x = q.x; y = q.y; z = q.z; w = q.w; } @@ -811,27 +826,27 @@ namespace XED.Asset [MessagePackObject] public class MaterialPropertyData { - [Key("BaseColor")] + [Key(0)] public float[] baseColor; - [Key("Metallic")] + [Key(1)] public float metallic; - [Key("Smoothness")] + [Key(2)] public float smoothness; - [Key("Emission")] + [Key(3)] public float[] emissionColor; - [Key("RenderMode")] + [Key(4)] public int renderMode; - [Key("SurfaceType")] + [Key(5)] public int surfaceType; - [Key("BlendMode")] + [Key(6)] public int blendMode; - [Key("OcclusionStrength")] + [Key(7)] public float occlusionStrength; - [Key("NormalScale")] + [Key(8)] public float normalScale; - [Key("TextureTypes")] + [Key(9)] public string[] texTypes; - [Key("TextureUIDs")] + [Key(10)] public string[] texUIDs; public void SetData(Material material) @@ -946,12 +961,14 @@ namespace XED.Asset [MessagePackObject] public class TextureData { - [Key("TextureName")] + [Key(0)] public string name; - [Key("TextureUID")] + [Key(1)] public string uid; - [Key("TextureData")] + [Key(2)] public byte[] data; + + [SerializationConstructor] public TextureData(string name, string uid, byte[] data) { this.name = name; @@ -962,10 +979,22 @@ namespace XED.Asset } public class MessagePackFileManager { + public void Initialize() + { + StaticCompositeResolver.Instance.Register( + GeneratedResolver.Instance, + StandardResolver.Instance + ); + MessagePackSerializer.DefaultOptions = MessagePackSerializerOptions.Standard.WithResolver( + StaticCompositeResolver.Instance + ); + } public async Task LoadAsync(string filePath) { - var lz4Option = MessagePackSerializerOptions.Standard.WithCompression(MessagePackCompression.Lz4Block); - byte[] readByte; + var lz4Option = MessagePackSerializerOptions.Standard. + WithCompression(MessagePackCompression.Lz4Block). + WithResolver(StaticCompositeResolver.Instance); + byte[] readByte = null; T deserailze = default(T); try { @@ -975,13 +1004,21 @@ public class MessagePackFileManager catch (Exception ex) { Debug.LogError($"Task Error: {ex.Message}\n{ex.StackTrace}"); + int byteLength = 0; + if (readByte != null) + { + byteLength = (int)readByte.Length; + } + Debug.LogError("Read Byte Size : " + byteLength.ToString()); } return deserailze; } public async Task SaveAsync(string filePath, T data) { - var lz4Option = MessagePackSerializerOptions.Standard.WithCompression(MessagePackCompression.Lz4Block); + var lz4Option = MessagePackSerializerOptions.Standard. + WithCompression(MessagePackCompression.Lz4Block). + WithResolver(StaticCompositeResolver.Instance); try { byte[] bytes = MessagePackSerializer.Serialize(data, lz4Option); @@ -991,5 +1028,5 @@ public class MessagePackFileManager { Debug.LogError($"Task Error: {ex.Message}\n{ex.StackTrace}"); } - } + } } \ No newline at end of file