1. Introduction
Official github repository
YAML: YAML Ain't Markup Language (YAML is not a markup language).
Use Unity2021.3 or later.
Install through Unity Package Manager: https://github.com/hadashiA/VYaml.git?path=VYaml.Unity/Assets/VYaml#0.13.1
ps: .yaml or .yml is the file suffix of this format.
2. Description
2.1 Grammar
- # indicates a single line comment, multi-line comments are not supported
- Use spaces for indentation to indicate hierarchical relationships, and the same levels must be aligned
- Case Sensitive
- Use - to indicate the beginning of the document, and use... to indicate the end of the document.
- Use > to indicate a newline, use | to also indicate a shift but retain the newline character
2.2 Data types
- Object: a collection of key-values, such as mapping/hashes/dictionary
- Array: Values arranged in order, such as sequence / list
- Scalars: a single indivisible value
2.3 Objects
The object key-value pair uses a colon structure to represent key: value, and a space must be added after the colon. You can also use key:{k1: v1, k2: v2, …}
for a more complex object format. You can use a question mark plus a space to represent a complex key, and a colon plus a space to represent a value.
2.4 Array
Lines starting with - represent an array
2.5 Scalar
string: 这是字符串
boolean: 这是布尔值
int: 这是整数
float: 这是浮点数
null: 这是Null
date: 这是时间,格式必须是yyyy-MM-dd
datetime: 这是日期,2023-07-10T09:00:00+08:00,时间和日期直接用T连接,最后使用+代表时区
2.6 Quotes
& is used to establish an anchor point, << means to merge into the current data, and * is used to refer to the anchor point.
common: &id001
name: 张三
sex: man
math:
<<: *id001
score: 100
history:
<<: *id001
score: 95
Equivalent to:
common:
name: 张三
sex: man
math:
name: 张三
sex: man
score: 100
history:
name: 张三
sex: man
score: 95
3. Use
View the official ReadMe
personal learning address
Object serialization is achieved through Serialize and SerializeToString, and string deserialization is achieved through Deserialize and DeserializeAsync.
ps: Please learn more complex structures by yourself~