Unity 的场景格式使用 YAML 数据序列化语言的一个自定义子集。YAML 是一种开放格式;请访问 YAML 网站以获取相关文档。有关 Unity 中使用的 YAML 的更多信息,请阅读 UnityYAML 文档。
该文件将场景中的每个对象编写为单独的 YAML 文档。---
序列介绍了文件中的每个对象。在此背景下,术语“对象”通指游戏对象、组件和其他场景数据;每一项都需要在场景文件中有自己的 YAML 文档。以下示例显示了序列化对象的基本结构:
--- !u!1 &6
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
importerVersion: 3
m_Component:
- 4: {fileID: 8}
- 33: {fileID: 12}
- 65: {fileID: 13}
- 23: {fileID: 11}
m_Layer: 0
m_Name: Cube
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
第一行在文档标记后面包含字符串 !u!1 &6
。!u!
之后的第一个数字表示对象的类(在此示例中表示游戏对象)。& 符号后面的数字是文件中非重复的对象 ID 号,但该数字是任意分配给每个对象的。每个对象的可序列化属性由如下行表示:
m_Name: Cube
属性通常以 m_
为前缀,但其他部分遵循脚本参考中定义的属性名称。以下示例显示了在文件中接下来定义的第二个对象:
--- !u!4 &8
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 6}
m_LocalRotation: {x: 0.000000, y: 0.000000, z: 0.000000, w: 1.000000}
m_LocalPosition: {x: -2.618721, y: 1.028581, z: 1.131627}
m_LocalScale: {x: 1.000000, y: 1.000000, z: 1.000000}
m_Children: []
m_Father: {fileID: 0}
以下示例显示了一个附加到由上面 YAML 文档定义的游戏对象的变换组件。{fileID:6}
用于表示文件中的对象 ID 为 6 的游戏对象。
m_GameObject: {fileID: 6}
…
可以使用十进制表示形式或 IEEE 754 格式的十六进制数字(由 0x 前缀表示)来表示浮点数。Unity 使用 IEEE 754 表示法对值进行无损编码以及写入没有短十进制表示形式的浮点值。Unity 以十六进制写入数字时,总是会在括号中写入十进制格式以便于调试,但在加载文件时实际只解析十六进制。要手动编辑这些值,请删除十六进制,然后输入十进制数。以下示例显示了一些浮点值的有效表示形式(均代表数字 1):
myValue: 0x3F800000
myValue: 1
myValue: 1.000
myValue: 0x3f800000(1)
myValue: 0.1e1
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.