This page has been translated automatically.
视频教程
界面
要领
高级
实用建议
专业(SIM)
UnigineEditor
界面概述
资源工作流程
版本控制
设置和首选项
项目开发
调整节点参数
Setting Up Materials
设置属性
照明
Sandworm
使用编辑器工具执行特定任务
如何擴展編輯器功能
嵌入式节点类型
Nodes
Objects
Effects
Decals
光源
Geodetics
World Nodes
Sound Objects
Pathfinding Objects
Players
编程
基本原理
搭建开发环境
使用范例
C++
C#
UUSL (Unified UNIGINE Shader Language)
Plugins
File Formats
材质和着色器
Rebuilding the Engine Tools
GUI
双精度坐标
应用程序接口
Animations-Related Classes
Containers
Common Functionality
Controls-Related Classes
Engine-Related Classes
Filesystem Functionality
GUI-Related Classes
Math Functionality
Node-Related Classes
Objects-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
IG Plugin
CIGIConnector Plugin
Rendering-Related Classes
VR-Related Classes
创建内容
内容优化
材质
Material Nodes Library
Miscellaneous
Input
Math
Matrix
Textures
Art Samples
Tutorials

Wait语句

警告
UnigineScript的应用范围仅限于实现与材质相关的逻辑(材质表达式,可编写脚本的材质,画笔材质)。 不要将UnigineScript用作应用程序逻辑的语言,请改用C#/C++,因为这些API是首选的。 无法保证UnigineScript中新引擎功能的可用性(超出其应用范围),因为当前的支持级别仅假设已解决关键问题。

这种架构会暂时停止当前函数的执行。函数的地址会被放置在等待函数列表中。在调用runWaits函数后,等待函数处于非冻结状态。runWaits函数仅可在应用程序的C++部分执行。Unigine会自动运行等待列表每帧中的函数。因此可以创建线程,这些线程没帧仅运行一次并使用wait 用于实现同步。

注意
wait架构仅能在线程中使用。

语法

源代码 (UnigineScript)
wait value;

部分

  • value 是一种可选的返回型值 (默认情况为0)。

实例

源代码 (UnigineScript)
void thread_func() {
	for(int i = 0; i < 4; i++) {
		log.message("%d\n",i);
		wait;
	}
}

thread("thread_func");

/* Output: 
 * "0" // 第一帧
 * "1" // 第二帧
 * "2" // 第三帧
 * "3" // 第四帧
 */
注意
当调用简单函数(而不是类的成员函数)时,wait 架构才有效:
源代码 (UnigineScript)
void update_redirector(Sprite sprite) {
	while(1) {
		sprite.update();
		wait;
	}
}

如果设置了类的实例,将会生成一个错误因为在保存下一帧中被runWaits调用的函数时,类的实例并不会被保存。然而如果将类函数作为静态函数(但不传递类的实体给此函数)进行调用wait便有可能:

源代码 (UnigineScript)
class Foo {

	void update() { 
		while(true) wait 1; 
	}
};
 
Foo f = new Foo();
Foo::update();		// 这样可用,因为方法被作为静态函数进行调用

// f.update();		// 由于传递了类的实例,因此这样会造成冲突

也可参看: thread().

最新更新: 2017-07-03
Build: ()