hadashiA / VYaml

The extra fast, low memory footprint YAML library for C#, focued on .NET and Unity.
MIT License
292 stars 15 forks source link

Is it possible to preset a UnityResolvers in VYaml.Unity #91

Open MonoLogueChi opened 5 months ago

MonoLogueChi commented 5 months ago

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 commented 5 months ago

Do you have any plans to implement this feature? I implemented part of it myself, can I PR to the warehouse? Is there anything I need to pay attention to when submitting a PR? image

hadashiA commented 5 months ago

@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.

MonoLogueChi commented 5 months ago

@hadashiA

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

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

MonoLogueChi commented 5 months ago

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();
        }
    }
MonoLogueChi commented 5 months ago

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

hadashiA commented 4 months ago

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 :)

hadashiA commented 1 month ago

I decided to port it to the main repo. #106