UnigineEditor
Interface Overview
Assets Workflow
Settings and Preferences
Adjusting Node Parameters
Setting Up Materials
Setting Up Properties
Landscape Tool
Using Editor Tools for Specific Tasks
FAQ
编程
Fundamentals
Setting Up Development Environment
Usage Examples
C++
C#
UUSL (Unified UNIGINE Shader Language)
File Formats
Rebuilding the Engine and Tools
GUI
Double Precision Coordinates
应用程序接口
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
CIGI Client Plugin
Rendering-Related Classes

Foreach语句

foreach架构用于对矢量贴图进行迭代。

语法#

源代码 (UnigineScript)
foreach(value_variable; container; loop_increment) { 
	// some_code;
}

部分#

  • value_variable为当前容器元素的值。
  • container 是一个矢量或一副贴图。
  • 在每个迭代结束时执行loop_increment

每个迭代中,当前元素的值会被分配给value_variable,容器内部游标会移至下一个容器元素所在处。value_variable的类型无关紧要, loop_increment为可选选项。

foreach模块内部元素的变化会对容器造成影响;在每个迭代的尾期会发生同步现象。

示例#

  • 对于每种矢量元素:
    源代码 (UnigineScript)
    int vector[4] = ( 1, vec3(1,2,3), -7.2e-2, "end" );
    foreach(int i; vector) {
    	log.message("%s\n",typeinfo(i));
    }
    此示例会得出下列结果:
    输出
    int: 1
    vec3: 1 2 3
    float: -0.072
    string: "end"
  • 对于每个贴图元素:
    源代码 (UnigineScript)
    int map[] = ( 1 : "begin", 2 : 2, 3 : "end" );
    foreach(int i; map) {
    	log.message("%s\n",typeinfo(i));
    }
    结果为:
    输出
    string: "begin"
    int: 2
    string: "end"
  • 增量:
    源代码 (UnigineScript)
    foreach(int i, j = 0; vector; j++) {
    	log.message("%d: %s\n",j,typeinfo(i));
    }
    输出为:
    输出
    0: int: 1
    1: vec3: 1 2 3
    2: float: -0.072
    3: string: "end"
最新更新: 2017-07-03