Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
MonoLogueChi opened this issue Feb 5, 2024 · 7 comments
Open

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

MonoLogueChi opened this issue Feb 5, 2024 · 7 comments

Comments

@MonoLogueChi
Copy link

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
Copy link
Author

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
Copy link
Owner

hadashiA commented Feb 8, 2024

@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
Copy link
Author

MonoLogueChi commented Feb 8, 2024

@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

  • 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

@MonoLogueChi
Copy link
Author

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
Copy link
Author

MonoLogueChi commented Feb 9, 2024

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.

@hadashiA
Copy link
Owner

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
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants