generated from EIA485/NeosTemplate
-
Notifications
You must be signed in to change notification settings - Fork 4
/
yamltestig.txt
202 lines (162 loc) · 5.15 KB
/
yamltestig.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
using System.Collections.Generic;
using System.IO;
using System;
using YamlDotNet.Core;
using YamlDotNet.Core.Events;
using YamlDotNet.Serialization;
public class Program
{
public static void Main()
{
//objwithdict obj = new objwithdict();
string createdobj = @"
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &6171425307844536358
GameObject:
m_ObjectHideFlags: 76687
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 6171425307844310086}
m_Layer: 0
m_Name: Middle Distal.L
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &6171425307844310086
Transform:
m_ObjectHideFlags: 39288904
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6171425307844536358}
m_LocalRotation: {x: -0.000566836, y: -0.12217824, z: 0.019729836, w: 0.9923119}
m_LocalPosition: {x: -1.4901161e-10, y: 0.00067465537, z: -7.8231094e-10}
m_LocalScale: {x: 1.0000001, y: 0.9999999, z: 1}
m_Children:
- {fileID: 6171425307844310088}
m_Father: {fileID: 6171425307844310094}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}";
//obj.dictionary.Add("key", "value");
//obj.dictionary.Add("key2", "value2");
List<IUnityObject> unityprefabobjects = new List<IUnityObject>();
var input = new StringReader(createdobj);
var deserializer = new DeserializerBuilder().WithNodeTypeResolver(new UnityNodeTypeResolver()).IgnoreUnmatchedProperties().Build();
var parser = new Parser(input);
parser.Consume<StreamStart>();
DocumentStart variable;
while (parser.Accept<DocumentStart>(out variable) == true){
// Deserialize the document
UnityEngineObjectWrapper doc = deserializer.Deserialize<UnityEngineObjectWrapper>(parser);
doc.Result().id = UnityNodeTypeResolver.anchor;
unityprefabobjects.Add(doc.Result());
Console.WriteLine(doc.Result().GetType().ToString());
}
//Console.WriteLine(((GameObject)unityprefabobjects[0]));
}
}
public class UnityEngineObjectWrapper
{
public GameObject GameObject;
public Transform Transform;
public UnityEngineObjectWrapper()
{
}
public IUnityObject Result()
{
return new List<IUnityObject>(){
GameObject,
Transform
}.Find(i => i != null);
}
}
public class GameObject: IUnityObject
{
public string m_Name;
public int m_IsActive = 1;
public ulong id { get; set; }
public int m_ObjectHideFlags { get; set; }
public GameObject()
{
}
}
public interface IUnityObject{
ulong id {get; set;}
int m_ObjectHideFlags { get; set; }
}
[Serializable]
public class Transform: IUnityObject{
public Dictionary<string, ulong> m_GameObject;
public Dictionary<string, float> m_LocalRotation;
public Dictionary<string, float> m_LocalPosition;
public Dictionary<string, float> m_LocalScale;
public Dictionary<string, ulong> m_Father;
public ulong id {get; set;}
public int m_FatherID;
public int m_GameObjectID;
public int m_ObjectHideFlags { get; set; }
public Transform()
{
}
}
class UnityNodeTypeResolver : INodeTypeResolver
{
private const string UnityTagPrefix = "tag:unity3d.com,2011:";
public static ulong anchor = 0;
public bool Resolve(NodeEvent nodeEvent, ref Type currentType)
{
Console.WriteLine("hello");
Console.WriteLine(nodeEvent);
if (nodeEvent.Tag != null && nodeEvent.Tag.Value.StartsWith(UnityTagPrefix))
{
int unityObjectId;
if (!int.TryParse(nodeEvent.Tag.Value.Replace(UnityTagPrefix, ""), out unityObjectId))
return false;
Type unityObjectName;
if (UnityObjectMapping.IdToTypeName.TryGetValue(unityObjectId, out unityObjectName))
{
try
{
if (currentType != null){
anchor = ulong.Parse(nodeEvent.Anchor.Value);
currentType = typeof(UnityEngineObjectWrapper);
return true;
}
// do default behaviour
// see https://github.com/aaubry/YamlDotNet/blob/master/YamlDotNet/Serialization/NodeTypeResolvers/DefaultContainersNodeTypeResolver.cs
if (nodeEvent is SequenceStart)
{
currentType = typeof(List<object>);
return true;
}
if (nodeEvent is MappingStart)
{
currentType = typeof(Dictionary<object, object>);
return true;
}
}
catch
{
//anchor = ulong.Parse(nodeEvent.Anchor.Value);
currentType = typeof(UnityEngineObjectWrapper);
return false;
}
}
}
return false;
}
}
class UnityObjectMapping
{
public static Dictionary<int, Type> IdToTypeName = new Dictionary<int, Type>()
{
{ 1, typeof(GameObject) },
{ 4, typeof(Transform) }
};
}