真Unity3D_文件格式meta prefab scene等关联文件管理等剖析与Yaml的关系第二章

Yaml的格式比较奇葩,和我们一直使用的json,xml都不同

YAML格式文件d3个关键概念

1.MappingNode就不说了, 

2.SalarNode是重点,和Json等很不同,下面这2个都是SalarNode;!!!都是

m_TransformParent: {fileID: 0}
m_IsPrefabParent: 1

3.数组Node也比较好理解

m_RemovedComponents: []

搞清楚上面YAML的重点概念,其实就很好处理了

一个简单的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;
    }

结果:

你可能感兴趣的:(每天一点u3d)