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

Deserializing Unity YAML #574

Closed
andreykhorkov opened this issue Feb 4, 2021 · 1 comment
Closed

Deserializing Unity YAML #574

andreykhorkov opened this issue Feb 4, 2021 · 1 comment

Comments

@andreykhorkov
Copy link

Hi. I'd like to use the library to deserialize Unity's material *.mat files which are Unity YAML. They have some information that library can't recognize as valid YAML. At least I don't know how to do it with the library yet.

.mat files starts with something like this:

%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
  serializedVersion: 6

I could procedurally delete first 3 lines from it and add "---" to the beginning, but is there a better way of doing it?

@EdwardCooke
Copy link
Collaborator

This code deserialized your yaml into an object.

        public void DeserializeUnityTags()
        {
            var yaml = @"%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
  serializedVersion: 6";
            var deserializer = new DeserializerBuilder()
                .WithTagMapping(new YamlDotNet.Core.TagName("tag:unity3d.com,2011:21"), typeof(Unity))
                .Build();
            var result = deserializer.Deserialize<Unity>(yaml);

        }

        public class Unity
        {
            public Mat Material { get; set; }
            public class Mat
            {
                [YamlMember(Alias = "serializedVersion")]
                public int SerializedVersion { get; set; }
            }
        }

I'm closing this issue. Let me know if you have any further questions.

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