撰写了文章 发布于 2020-04-29 01:05:31
Articy Importer Guide - 04 脚本与使用
脚本与使用 Scripting and how to use it
articy:draft自带Expresso脚本语言支持,并已在articy:access中引入。articy:draft中的脚本语言非常有用,主要用于全局变量和模拟模式的结合使用,以便测试流程和对话逻辑。
articy:draft contains support for a script language called "Expresso" and was introduced with articy:access. In articy:draft the script language was most useful when combined with Global Variables and the Simulation mode allowing you to test your flow and your dialogues with logic.
ArticyImporter插件会将脚本导入unity,并确保您可以在合适的情况下使用。不仅如此,ArticyFlowPlayer还会在流程遍历时自动使用流程中找到的脚本。
The ArticyImporter plugin imports your scripts into unity and makes sure that you can use them as you seem fit, not only that, but the ArticyFlowPlayer will automatically use the scripts found inside the flow when it will traverse it.
本篇教程将会教授你如何运用articy:draft的script功能,并使untiy能够使用它。
This guide will teach you how you can take advantage of the script functionality inside articy:draft and how to make use of it in unity
本篇
This topic contains the following sections:
- Expresso脚本入门 Expresso Script Primer
- 条件 Conditions
- 指令 Instructions
- 通过脚本获取对象,属性和模板 Accessing objects, properties and templates via Script
- 相关链接 See Also
Expresso脚本入门
Expresso Script Primer
There is a fair chance that you have never worked with scripts inside articy:draft before, so in this chapter we give you a small overview of what you can and can't do with it and how to use it.
首先第一件事:articy:draft有两种基本的脚本类型,Condition(条件)和Instruction(指令)。顺便说一句,articy中有两种同类型的节点。
The first thing is: In articy:draft are basically 2 types of scripts Conditions and Instructions. Incidentally there are two node types in articy:draft that go by these names.
- Conditions 条件:用于测试某些情况是否被允许,条件脚本是解析为布尔值的单个语句,因此必须返回true或false。
are used to test if something is allowed, a condition script is a single statement that must resolve to a boolean therefore returning true or false. - Instructions 指令:用于多种语句的脚本,用分号分隔,通常用于更改变量或调用方法。
are scripts that can be multiple statements, separated with semicolon and usually used to change variables or call methods.
脚本会出现在3个不同的位置:引脚(Pins),专门的节点(Nodes)和脚本模板(Script template)属性。模板和节点理解起来很轻松,但引脚需要我们仔细说明。
Scripts can be found in 3 different places Pins, specialized Nodes and Script template property. While template and node types are self explanatory, pins need a bit more explanation.
左侧的节点称为输入引脚(Input Pins),每个输入引脚包含一个条件脚本。与之相对,右边的引脚称为输出引脚(Output Pins),每个输出引脚都包含一个指令脚本。
Pins on the left side of a node are called Input Pins and every input pin contains a condition script. In that regard are the pins on the right side called Output Pins and every output pin contains an instruction script.
For more information how to write scripts inside articy:draft check the help about Scripting
条件
Conditions

To write a condition you usually just have to form statements that can be evaluated to a boolean, lets look at some simple examples of what are valid condition scripts.
true
GameState.awake
!Inventory.hasKey || Inventory.lockPicks == 0
Resources.woodSupply > 100 && Resources.ironSupply > 50
如你所见的,条件仅是一行语句而已,该语句负责检查一个或多个变量的值。重要的一点是要理解你无法在单个条件中使用多重语句,这样尝试时,articy:draft通常会返回一个错误。
As you can see conditions are just a single statement that is testing the value of one or more variables. Its important to understand that you cannot use multiple statements in conditions and articy:draft will usually return an error when trying to do that.
指令
Instructions

指令相较而言在撰写上更加容易,因为他们通常只是一个或多个改变变量的语句而已。
Instructions are rather easy to write, as they are usually just one or more statements changing a variable.
GameState.awake = true;
Resources.woodSupply -= 100; Resources.ironSupply -= 50;
playSound("forge_build.wav");
你可以用指令改变游戏中的变量,甚至可以调用自定义方法。
You can use instructions to change the variables inside your game and even call custom methods.
通过脚本获取对象,属性和模板
Accessing objects, properties and templates via Script

历史版本的articy:draft脚本需要与全局变量一同使用。尽管这一用法能够满足大多数的情况,但直接将数据与对象一起储存可能会更有用。特别是考虑到模板系统的灵活性,我们向脚本系统引入了专门的方法,使你可以访问对象的属性和模板数据。
Historically the articy:draft scripting was used together with Global variables. While this was sufficient for a lot of use cases, it can be more useful to store the data alongside the objects directly. Especially given the flexibility our template system, we introduced specialized methods to the scripting system to allow you to access the properties and the template data of objects.
有四种内置的方法用于对象属性:
There a 4 built in methods that you can use to work with object properties:
- getProp(object, property):
返回一个对象的给定属性的值
returns a value for an object with the given property - setProp(object, property, value):
为一个对象设置属性的值
sets the value of a property for an object - getObject(string):
通过技术名称或ID返回一个对象引用
returns an object reference via technical name or id. - print(string):
打印一串文本,你可以向String.Format()一样使用参数
prints a text, you can use parameters similar to String.Format(). - random(int, int):
在第一个数字(包含该数字)和第二个数字(包含该数字)之间返回一个随机数。
returns a random number between the first number (inclusive) and the second number (inclusive).
- speaker
在一个DialogueFragment当中,speaker是一个队当前说话者对象的自动引用。
inside a DialogueFragment this is an automatic reference to the current speaker object. - self
引用了调用此脚本的当前对象。
this references the current object that this script is called on.
![]() |
---|
请记住,条件只是布尔语句,因此您不能在指令内使用print()或setProp(),因为这两种方法都没有返回值。 Remember that Conditions are only boolean statements, therefore you can't use print() or setProp() inside an instruction as both methods don't have a return value. |
getProp()
为了获取到属性,需要调用getProp()并获取到对象(可以通过getObject()查询)。获取对象后,你需要提供PropertyName作为字符串。
To access a property you just have to call getProp() and get the object, which you can query via getObject() for example. After getting the object you need to supply the PropertyName as a string.
getProp( getObj("Chr_Manfred"), "DisplayName")
属性名称只是C#的属性的名称。比如DisplayName,Speaker,BackgroundColor等。
The property name is just the C# property name. For example DisplayName, Speaker, BackgroundColor etc.
你可以通过写出feature名称和property名称(通过点号分隔符分隔)来获取模板数据,
You can access the template data of the object by writing the feature name and the property name separated via a dot
getProp( getObj("Chr_Manfred"), "Morale.MoraleValue" ) > 10
记住你可以使用更方便的识别符来获取对象:
Remember that you can use the convenient identifier to ease accessing objects:
getProp( speaker, "Player_Character.Morale" ) > 10
setProp()
为了更改一个对象的值,你需要像getProp()一样获取到对象,提供属性名称,还需要提供新的属性值。
To change the value of an object, similar to getProp() you have to access the object and supply the property name you also need to supply the new value for the property.
setProp( getObj("Chr_Manfred"), "DisplayName", "Player1" )
改变模板的属性也同样简单。
Changing a template property is equally easy
setProp( getObj("Chr_Manfred"), "Player_Character.Morale", 100 )
而且你当然也可以使用便捷识别符。
And you can of course use the convenient identifier here aswell.
setProp( speaker, "Morale.MoraleValue", 100 )
getObj()
你可以通过技术名称和id获取对象
You can access an object via its technical or its id
getObj("Chr_Manfred")
getObj("0x01000001000010C6")
And you can specify the instance id to access another clone of the object.
getObj("NPC_Guard", 1)
print()
使用printf()可以向debug工具一样有用地在控制台写入日志,就像Debug.Log()。
Useful as a debug tool you can use print() to write into the Unity console log, like Debug.Log().
print( "Hello" )
print( "Number {0}", 42 ) print( getProp( speaker, "Morale.MoraleValue" ) )
相关链接
See Also
目录