Yaml的格式比较奇葩,和我们一直使用的json,xml都不同
1.MappingNode就不说了,
2.SalarNode是重点,和Json等很不同,下面这2个都是SalarNode;!!!都是
m_TransformParent: {fileID: 0}
m_IsPrefabParent: 1
3.数组Node也比较好理解
m_RemovedComponents: []
一个简单的yaml
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1001 &100100000
Prefab:
m_ObjectHideFlags: 1
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications: []
m_RemovedComponents: []
m_ParentPrefab: {fileID: 0}
m_RootGameObject: {fileID: 1569158505684088}
m_IsPrefabParent: 1
--- !u!1 &1569158505684088
GameObject:
(省略几千行)
绕了一个弯,再绕一个弯
static string GetPrefabGameObjectId(YamlNode node_prefab)
{
YamlMappingNode map_prefab = node_prefab as YamlMappingNode;
var item = map_prefab.Children[new YamlScalarNode("m_RootGameObject")];
YamlMappingNode map_item = item as YamlMappingNode;
string fileId = "";
//TODO:暂时不知道怎么取第一个节点
foreach (var k_v in map_item.Children)
{
//取一个简单值,绕晕你,再绕晕你。。。。就问你服不服
fileId = ((YamlScalarNode)k_v.Value).Value;
break;
}
return fileId;
}
结果: