Is it possible to preset a UnityResolvers in VYaml.Unity
MonoLogueChi opened this issue · 7 comments
In some cases, I will need to serialize and deserialize Unity types, such as Vector3, Color, etc. Although I implemented part of it myself, I would like to have a UnityResolvers that contains commonly used Unity types and is automatically enabled when using Unity. Just like MessagePack-CSharp.
@MonoLogueChi Thanks so much. PR is welcome.
I don't have a detailed contribution rule. If there is no problem, I would like to adopt it.
EDIT:
Ah, that reminds me, if we want to include Unity-dependent code, you can put it in /Unity
directory in /VYaml.Unity/Assets/VYaml/Runtime/.
It might cause problems with testing on the .net side. We will probably need to exclude the unity folder.
https://github.com/hadashiA/VYaml/blob/master/VYaml/VYaml.csproj#L42
However, I can rework this after I merge your commits.
Okay, I'll try not to break the original code and keep the style consistent.
The serialization I implemented is similar to the style of MessagePack-CSharp, that is
Color
Color32
->[r,g,b,a]
Vector3
Vector3Int
->[x,y,z]
This will not only make it easier to edit the configuration file, but will also be more efficient.
The parser that needs to be implemented will refer to Newtonsoft.Json-for-Unity.Converters
If I need to create a tool class and place some public code, where should I create it? The code is similar to this
internal static class Utils
{
public static void WriteFloatArrayWithFlowStyle(ref Utf8YamlEmitter emitter, IEnumerable<float> value,
YamlSerializationContext context)
{
emitter.BeginSequence(SequenceStyle.Flow);
foreach (var f in value) emitter.WriteFloat(f);
emitter.EndSequence();
}
public static void WriteByteArrayWithFlowStyle(ref Utf8YamlEmitter emitter, IEnumerable<byte> value,
YamlSerializationContext context)
{
emitter.BeginSequence(SequenceStyle.Flow);
foreach (var b in value) emitter.WriteInt32(b);
emitter.EndSequence();
}
public static void WriteIntArrayWithFlowStyle(ref Utf8YamlEmitter emitter, IEnumerable<int> value,
YamlSerializationContext context)
{
emitter.BeginSequence(SequenceStyle.Flow);
foreach (var i in value) emitter.WriteInt32(i);
emitter.EndSequence();
}
}
I have been sorting out the code recently and found that instead of merging it into VYaml, creating a VYaml.UnityResolvers project myself may be a better choice. The reasons are as follows
- Will affect VYaml .net side testing
- Creating UnityResolvers does not require modifying VYaml code
- The serialization and deserialization methods are written according to my habits and may not be recognized by everyone, causing the VYaml project to be affected.
Thanks for the good work !
VYaml would like to focus on Unity.
I would like to add similar functionality to the main repo using your code as a reference :)