World Expression
World Expression is a point object, which executes arbitrary expressions (scripts) within the specified distance and at a set frame rate. By default, expressions are executed at the same frame rate as the main application.World Expression是一个点对象,它在指定范围内执行任意表达式(脚本)距离并在一组帧率。默认情况下,表达式以与主应用程序相同的帧速率执行。
By using World Expression, you can attach a script to an object in the scene. To do that, such object must be added as a child node to World Expression. Child nodes inherit transformations (if any) of the World Expression node.通过使用World Expression,可以将脚本附加到场景中的对象。为此,必须将此类对象作为子节点添加到World Expression。子节点继承World Expression节点的转换(如果有)。
If there are nested World Expression nodes, the child node of the last World Expression in the hierarchy inherits transformations of all parent World Expression nodes.如果存在嵌套的World Expression节点,则层次结构中最后一个World Expression的子节点将继承所有父World Expression节点的转换。
For example, by using World Expression, you can transform objects in the scene, turn on and off sounds with the distance, turn on and off NPC behavior, attach objects to the camera (e.g. drops of the rain on the camera), and so on.例如,通过使用World Expression,您可以变换场景中的对象,按一定距离打开和关闭声音,打开和关闭NPC行为,将对象附加到相机(例如,相机上的雨滴)等等。 。
See also也可以看看#
- The WorldExpression class to manage World Expression via API通过API管理World Expression的WorldExpression类
- Tutorial on Adding Scripts to the Project教程开将脚本添加到项目
-
Set of samples located in the <UnigineSDK>/data/samples/worlds/ folder:位于<UnigineSDK>/data/samples/worlds/文件夹中的样本集:
- expression_00 — expression_05
Creating World Expression创造世界表达#
To create World Expression via UnigineEditor:要通过UnigineEditor创建World Expression,请执行以下操作:
Attaching World Expression Script附加世界表达脚本#
There are two ways of attaching a World Expression script via UnigineEditor:有两种方法可以通过UnigineEditor附加World Expression脚本:
-
Directly in UnigineEditor in the Source field of the World Expression section in the Parameters window. Source code must be inside the curly braces {}, as they define the World Expression scope.直接在UnigineEditor中Parameters窗口中World Expression部分的Source字段中。源代码必须在花括号{}内,因为它们定义了World Expression范围。
-
Attached as a script file in the File field of the World Expression section. The script file should be included in the World Expression scope in the Source field using the curly braces {}:作为脚本文件附加在World Expression部分的File字段中。脚本文件应使用花括号{}包含在Source字段的World Expression范围内:
In this case, the my_expression.h file should contain the following code:在这种情况下,my_expression.h文件应包含以下代码:
log.message("WorldExpression is updated\n");
In the script file, the source code must not be wrapped in the curly braces {}.在脚本文件中,不得将源代码包装在花括号{}中。
Implementing Script实施脚本#
The script itself can be implemented as a simple sequence of functions' calls or as a set of functions and classes. See examples here.脚本本身可以实现为简单的函数调用序列,也可以实现为一组函数和类。查看范例这里。
Inter-Script Communication脚本间通信#
Such script can communicate with the world script via the corresponding engine.world class functions or with World Trigger via callbacks (see the samples listed above).这样的脚本可以与世界脚本交流通过相应的engine.world类函数或通过回调使用World Trigger(请参见列出的示例)以上)。
Script Functions脚本功能#
Setting World Expression Parameters设置世界表情参数#
You can adjust the following parameters of World Expression in the Node tab: 您可以在Node选项卡中调整以下World Expression参数:
Update Distance Limit | Distance from the camera, within which the expression is executed.距相机的距离,在该距离内执行表达式。 |
---|---|
IFps | A constant frame duration (inverse FPS, 1/FPS) used to execute the expression. If 0 is set, the expression is executed at the same frame rate as the main application.用于执行表达式的恒定帧持续时间(反向FPS,1 / FPS)。如果设置为0,则以与主应用程序相同的帧速率执行表达式。 |
File |
A path to a file with a World Expression script to be executed. The path is relative to the data directory. This file should be included in the World Expression scope in the Source field. This field is optional as the World Expression script can be implemented directly via the UnigineEditor interface.要执行的带有World Expression脚本的文件的路径。该路径是相对于data目录的。该文件应包含在Source字段的World Expression范围内。该字段是可选的,因为可以通过UnigineEditor接口直接实现World Expression脚本。 If the script file is changed, it should be refreshed via UnigineEditor: click to the right of the File field.如果脚本文件已更改,则应通过UnigineEditor对其进行刷新:单击File字段右侧的。 |
Source |
Source code of a World Expression script. This field can contain:World Expression脚本的源代码。该字段可以包含:
In both cases, the curly braces {} must wrap the code in the field.在这两种情况下,花括号{}必须将代码包装在字段中。 |