撰写了文章 发布于 2020-05-01 11:35:27
Articy Importer Guide - 05 对象模板
对象模板 Object Templates
导出数据的其中一部分是对象模板,所以,了解它们与articy对象的关系,它们如何工作,以及如何在unity里面使用不同类型,也是本指南的一部分。
Part of your exported data are Object Templates and understanding their relationship with your articy objects, how they work and how to use the different types inside unity is part of this guide.
本篇包含以下内容:
This topic contains the following sections:
- articy:draft对象模板入门
Primer to articy:drafts object templates - 理解对象及其模板
Understanding Objects with Templates - 获取功能和属性
Accessing Features and properties - 使用特定属性类型
Working with specific property types - 通过功能获取对象
Access object by feature - 模板属性元数据和约束
Template property meta data and constraints - 相关链接
See Also
articy:draft对象模板入门
Primer to articy:drafts object templates

如果您从未使用过articy:draft模板系统,或者需要对articy:draft模板系统进行过小小的梳理,请继续阅读,否则可以跳过本节
If you have never worked with or need a small brush up about the articy:draft template system, read on otherwise you can skip this section
Every object in articy:draft (Entity, FlowFragment, Location etc.) has a predefined set of hardcoded properties like DisplayName, TechnicalName, ID, Text, Attachments etc.. When designing more complex projects using articy:draft you will sooner or later arrive at a point you wish an articy object had a specific property. Lets say your game needs every NPC to contain a property stating how much gold it is worth when killed, now the obvious articy type would be to use an Entity for the NPCs but how do you create a property for the gold? Introducing model templates:
下方是一串列表,包含了模板系统的重要部分,如果刚开始您看不太懂,请继续阅读后续的内容,我们会更详细地讲解:
Following is a list of important parts of the template system, if this doesn't make sense at first, continue reading, we will look at each part in more detail:
- 模板 Template
功能的载体,绑定在一个特定的articy对象类型上。
Container for features bound to one specific articy object type. - 功能 Feature
属性的载体,可在不同模板中反复利用。
Container for properties reusable in different templates. - 属性 Property
单一的一条信息,带有存储在功能中的某个特定类型。
Single piece of information with a specific type stored inside a feature. - 属性定义 Property definition
允许将属性及其设置预定义为可重用的属性类型。
Allows predefining a property and its settings as a reusable property type.
每个articy:draft的对象类型都可以包含一个对象模板。你可以使用articy:draft中的模板编辑器创建模板。需要注意理解,一个对象模板被固定在一个类型当中,只有一种类型是很重要的。如果你创建了一个名为“Item”的实体模板,只能将此模板附加到实体,而不能进行其他操作。
Every articy:draft object type can have an object template. You create those object templates in articy:draft using the template editor. It is important to understand that an object template is fixed to one type and one type only. When you create an entity template called "Item" you can only attach this template to entities and nothing else.
A template is usually built up of one or many different features. A feature is created via the feature editor in articy:draft. Because features are not bound to an object type they are a good way to share the same kind of properties between different templated articy object types. A feature itself is a container for properties and can have many properties of varying types. Reusing our example above we could create a feature called LootInfo and place it in our entity template NPC. Later on if we create a template for Chests, we could reuse our LootInfo feature.
基于功能,可以开始计划并创建属性。在功能编辑器中,你可以看到一列不同的属性类型,每个类型都可以拖放到功能网格中,创建出新的功能中的属性。每个属性类型都有不同的设置,具体取决于类型,这使我们可以微调属性,指导设计师如何在工作中使用或修改属性。比如当我们使用Number属性类型时,可以设置小数位数,单位,最小和最大值等。回到上述的案例中,在我们的LootInfo功能中,我们会创建一个新的Number属性,称之为Gold,调整它的设定,比如最小值和最大值,并将金币的单位设置为“g”。
On the feature we can now start to plan and create our properties. In the feature editor you are presented with a list of different property types and each type can be placed in the feature grid, creating a new property inside the feature. Every property type has different settings depending on the type and allow us to fine tune and guide how the designers can work or modify the property when used. For example when using the Number property type, we can set the amount of decimal places, a unit, min and max value and so forth. Going back to our example above, in our LootInfo feature we would create a new Number property calling it Gold, adjusting its setting, like min and max and maybe set the Unit to "g" for gold.
又是我们的功能中有大量的属性共享着同样的设定。比如,我们为一个RPG角色创建了一个功能,该功能包含有大量的技能属性,而我们手动为每个属性设置了最小值和最大值。为了简化此过程,您可以创建作为可重复使用的属性预设的属性定义。对当前的unity plugin和本教程的其他内容而言,这部分并不重要。
Sometimes we have a lot of properties in our features that share the same settings. For example we create a feature for an RPG character with many skill attributes and we have to set the min and max value for every property by hand. To simplify this, you can create property definitions that are reusable presets of properties. For the unity plugin and for the remainder of this guide they are not important.
理解对象及其模板
Understanding Objects with Templates
让我们先来瞅瞅有模板的对象和没模板的对象有什么区别,举例来看,我们可以看到下面这个Entity类型:
Lets first have a look of how objects with templates differ from objects without templates, for this example we look at the Entity type:

Entity ent = ArticyDatabase.GetObject<Entity>("Chr_Manfred");
Debug.Log( ent.DisplayName );
Character ent = ArticyDatabase.GetObject<Player_Character>("Chr_Manfred");
// 获取displayname,因为Character是一个Entity
// access the displayname because a Character is still an Entity.
Debug.Log(ent.DisplayName);
// 获取模板
// access the template
Debug.Log( ent.Template.Character.Motivation );
着重注意 Important to remember
- articy:draft的对象模板在untiy中将会成为C#的类。比如Player_Character:Template -> class Player_Character : Entity{}
Object Templates in articy:draft will be C# classes in unity. eg. Player_Character Template -> class Player_Character : Entity {} - 每个模板的类都会有一个属性,叫做Template,以便获取模板和和它的功能。myObj.Template.MyFeature
Each of these template classes will have a property called Template giving access to the template and its features. myObj.Template.MyFeature - 功能包含articy:draft模板编辑器中列出的属性。myObj.Template.MyFeature.MyProperty
The features contain the properties layed out in the articy:draft template editor. myObj.Template.MyFeature.MyProperty - TechnicalName永远是生成的类或属性的名字。
The TechnicalName is always used for the generated classes or property names.
注意 |
|---|
本示例假定您在规则集数据布局(ruleset data layout)中启用了继承,这是默认设置,也是首选的工作方式。 This example assumes that you have inheritance enabled in the ruleset data layout, which is the default and the prefered way to work. |
获取功能和属性
Accessing Features and properties
With a basic understanding of how templates are created by the plugin, lets look how we can work with them
Character ent = ArticyDatabase.GetObject<Player_Character>("Chr_Manfred");
// 获取模板 -> 叫“Character”的功能和叫“Motivation”的模板属性
// access to the template -> the feature called "Character" and the template property "Motivation"
Debug.Log( ent.Template.Character.Motivation );
Accessing a template property is very straight forward if you are used to C# properties in general.
<myObject>.Template.<FeatureTechnicalName>.<PropertyTechnicalName>

使用特定属性类型
Working with specific property types

本节包含以下子节
This section contains the following subsections:
- 布尔值,数字,文本 Boolean, Number, Text
- 插槽 Slots
- 插条和计算插条 Strip and calculated Strip
- 下拉菜单 Drop-down list
- 脚本 Scripts
布尔值,数字,文本 Boolean, Number, Text
The basic types are straight forward mapped to their C# types and thus very easy and intuitive to use.
var manfred = ArticyDatabase.GetObject<Player_Character>("Chr_Manfred");
var locationCell = ArticyDatabase.GetObject<LocationSettings>("Loc_Cell");
Debug.Log( manfred.Template.Character.Age );
// 数字 Number (float)
manfred.Template.Character.Age = 42;
Debug.Log( manfred.Template.Character.Motivation );
// 文本 Text (small, medium, large) (string)
manfred.Template.Character.Motivation = "Converting oxygen to carbon dioxide.";
Debug.Log( locationCell.Template.LocationSettings.IsStartLocation );
// 布尔值 Boolean (bool)
locationCell.Template.LocationSettings.IsStartLocation = false;
插槽 Slots
A reference slot is used to provide a link to another articy object.
var locationCell = ArticyDatabase.GetObject<LocationSettings>("Loc_Cell");
var startDialog = locationCell.Template.LocationSettings.InitialDialog as Dialogue;
It is worth noting that the object is lazy fetched, which means everytime you access the property, the property will internally ask the database to get the object again.
插条和计算插条 Strip and calculated Strip
When you need multiple objects referenced you should use a Strip in your template. In unity a strip property is of type List<ArticyObject>.
var manfred = ArticyDatabase.GetObject<Player_Character>("Chr_Manfred");
foreach(ArticyObject obj in manfred.Template.Character.Likes)
{
var entity = obj as Entity;
if(entity != null)
Debug.Log(entity.DisplayName);
}
注意 |
|---|
该插件不支持articy:draft中用于计算插条的查询语言,因此计算插条会在导出时被实际上降级为常规插条,并且在包含计算出的数据。 Because the plugin has no support for the query language used in articy:draft for calculated strips they are effectively downgraded to regular strips and they contain the calculated data at the time of export. |
下拉菜单 Drop-down list
下拉菜单可以有效地让受限的数据视觉化。Unity当中的下拉菜单实际上是枚举,下拉类型是枚举的名称。以下是在unity中使用下拉菜单
Dropdown lists are a good way to visualize limited data. In unity drop down lists are effectively enums, with the drop-down type being the name of the enum. So using a drop-down in unity
var therapistZone = ArticyDatabase.GetObject<Conditional_Zone>("Zon_4B2E23F9");
therapistZone.Template.ZoneCondition.CursorIfConditionMatches = MouseCursor.Take;
脚本 Scripts
All the scripts inside the flow on pins and in instructions and conditions are called by the ArticyFlowPlayer and we usually don't have to worry about it. But scripts in templates have to be used manually. When exported these properties can be ArticyScriptCondition, ArticyScriptInstruction or a plain string depending on which mode you selected in the template editor in articy

You can do 2 things with both script types in unity.
- 使用RawScript(Condition)/ RawScript(Instructiong)以字符串形式访问脚本
Access the script as a string using RawScript (Condition)/RawScript (Instruction) - 调用基础脚本代码CallScript(Condition)/ CallScript(Instructiong)
Call the underlying script code CallScript (Condition)/CallScript (Instruction)
Using scripts inside your code is therefor just a matter of using the CallScript() methods.
var therapistZone = ArticyDatabase.GetObject<Conditional_Zone>("Zon_4B2E23F9");
// 首先调用Condition属性
// call the Condition property first
bool result = therapistZone.Template.ZoneCondition.ClickCondition.CallScript();
// 检查返回的值,条件始终根据脚本的评估返回true或false
// check the returned value, a condition always returns true or false depending on the evaluation of the script
if(result)
{
// 若允许点击,则执行instruction
// if we were allowed to click it, execute the instruction
therapistZone.Template.ZoneCondition.OnClickInstruction.CallScript();
}

通过功能获取对象
Access object by feature
In articy:draft templates are bound to a specific type, which means you can't assign a FlowFragment template to a DialogueFragment. But because it is often necessary to have the same set of data on multiple types, articy:draft introduced the concept of Features. Features can be reused in templates and are a good way to attach the same set of data to multiple object types. But how can we write code targeting a specific feature, without the need to know the type of the underlying template.
到此为止我们仅仅获取了得知模板类型的功能。但是也可以询问任意对象,其是否为模板对象,并包含特定功能。为此,该插件将为每个功能生成专门的接口,形式为
At this point we have only accessed features where knew the type of the template. But its also possible to ask an arbitrary object if it is a templated object and contains a specific feature. To do that, the plugin will generated specialized interfaces for every feature in the form of
IObjectWithFeature<FeatureTechnicalName>
这一概念与属性接口相同,如IObjectWithDisplayName。现在我们可以输入
for us. This is the same concept as the property interfaces like IObjectWithDisplayName. Now to use it we can type
ArticyObject obj = ArticyDatabase.GetObject("Chr_Manfred"); // 一些对象
var characterFeature = obj as IObjectWithFeatureCharacter;
if(characterFeature != null) {
characterFeature.GetFeatureCharacter().Motivation = "Converting oxygen to carbon dioxide.";
}
<Object>.GetFeature<FeatureTechnicalName>()
模板属性元数据和约束
Template property meta data and constraints

<TemplateType>.Constraints.<FeatureTechnicalName>.<PropertyTechnicalName>.<Constraint data>
var manfred = ArticyDatabase.GetObject<Player_Character>("Chr_Manfred");
// 使用unity的Assert来检查Motivation属性的长度是否小于或等于我们在该属性的约束中定义的长度
// use unitys Assert to check if the Motivation properties length is less or equal than what we defined in the constraints for that property
Assert.IsEqual( manfred.Template.Character.Motivation.Length <= Character.Constraints.Character.Motivation.MaxLength );

注意