撰写了文章 更新于 2021-12-06 10:51:12
Articy Importer Guide - 01 基本对象处理
01 基本对象处理 Basic Object Handling
当你从 articy:draft 中导出数据到Unity时,使用 articy importer 插件,将能够根据你的内容生成数据库,并为所有数据创建C#类型和属性。本篇文章将介绍如何获取这些数据。
When you export your data from articy:draft to your Unity project, the articy importer plugin will populate a database with your data and create C# classes and properties for everything. This article will cover how to access that data.
本篇文章将包含如下内容:
This topic contains the following sections:
- 简单对象获取 Simple Object Access
- 进阶对象获取 Advanced Object Access
- 相关连接 See Also
简单对象获取 Simple Object Access
最基本的 articy 对象获取方法,是直接从数据库中取得:
The most basic way to access an articy object is to query it directly from the database:
// 通过技术名称获取对象
ArticyObject manfred1 = ArticyDatabase.GetObject("Chr_Manfred");
同样也能手动转换 ArticyObject,也可以用 GetObject 方法返回特定的类型:
You can either cast the ArticyObject manually, or ask the GetObject method to return a specific type:
// 通过确切类型和技术名称获取一个对象
Player_Character manfred2 = ArticyDatabase.GetObject<Player_Character>("Chr_Manfred");
该案例中,我们提供了 Player_Character 这一模板名称,返回的对象将被自动地转换为该类型。变量 manfred2 现在引用了 Player_Character 类型的实体(entity),而我们可以访问它的所有属性:
// 我们可以访问所有导出的属性
Debug.Log( manfred2.Text );
// 当然也可以设置属性
manfred2.DisplayName = "Advanced Manfred 2.0";
技术名称(Technical Name)并非是查询数据库的唯一途径。另一个办法是用 articy 对象独有的对象id:
The Technical Name is not the only way to query the database for an object. Another one is to use the unique object id every articy object has:
var manfred3 = ArticyDatabase.GetObject(0x1000001000010C6);
// ↑以十六进制表示
// ↓以十进制表示
var manfred4 = ArticyDatabase.GetObject(72057598332899526);
注意 | 该插件包含将对象的ID转换为其十六进制字符串表示法的方法,反之亦然。 参见ToHex(Int64) |
|---|
Articy并不要求技术名称独一无二。事实上,完全可以把一个名字分配给多个对象,并使用技术名称获取到所有同名对象。
Articy doesn’t require Technical Names to be unique. In fact, it can be useful to assign the same name to multiple objects and use it to get all objects with the same Technical Name.
List<ArticyObject> allManfreds = ArticyDatabase.GetObjects("Chr_Manfred");在这种情况下,要获取特定对象,请使用具有唯一 id 的 GetObject(id)。
To get a specific object in that case use GetObject(id) with the unique id instead.
注意 |
|---|
由于出错的可能性很高,建议不要为 articy:draft 的多个对象故意分配相同的技术名称。 要将某些对象组合在一起,请使用自定义模板并按其类型查询对象。 有关如何按类型查询对象的信息,请参见基本对象处理。 Due to the high potential for errors it is not recommended to deliberately assign the same Technical Name to multiple objects inside articy:draft. To group certain objects together, rather use custom templates and query the objects by their type. See Basic Object handling on how to query objects by type. |
进阶对象获取 Advanced Object Access
有时你会想获取某个特定类型的所有对象。 此时可使用ArticyDatabase包含的GetAllOfType<TObject>()方法。任何标准的articy对象类型都可用于指定,使用自定义的模板亦可。
Sometimes you want all objects of a specified type. The ArticyDatabase contains the function GetAllOfType<TObject> () for this. you can specify any of the standard articy object types, or your own templates when calling it:
var allmyItems = ArticyDatabase.GetAllOfType<Item>();为进一步过滤返回的道具列表,还可使用LINQ指定其他条件。 请参阅Microsoft的LINQ文档,了解如何编写LINQ语句。 下面的示例仅选取了价格高于100的item类型对象。
To further filter the list of returned items you can also use LINQ to specify additional conditions. Please see the LINQ documentation by Microsoft on how to write LINQ statements. The example below selects all objects of type item that have by only selecting ones with a gold cost greater than 100.
var allExpensiveItems = ArticyDatabase.GetAllOfType<Item>().Where( aItem => aItem.Template.Item.GoldCost > 100).ToList();

注意