This page has been translated automatically.
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
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
CIGI Client Plugin
Rendering-Related Classes
注意! 这个版本的文档是过时的,因为它描述了一个较老的SDK版本!请切换到最新SDK版本的文档。
注意! 这个版本的文档描述了一个不再受支持的旧SDK版本!请升级到最新的SDK版本。

Call()方法

variable call(string function_name, variable arguments)

调用函数,将提供的函数名作为参数。
注意
上面的表达式等同于function_name(arguments)

参数

  • string function_name - 调用的函数名
  • variable arguments - 函数参数

返回值

函数的执行结果。

例子

源代码 (UnigineScript)
call("log.message","%d %s\n",13,"some text");

// the result is: 13 some text

variable call(int function_id, variable arguments)

通过函数ID调用函数,这种方式与直接调用函数的速度一样快。为获取此ID,使用get_function()

参数

  • int function_id - 调用函数的ID。
  • variable arguments - 函数参数。

返回值

函数执行结果。

例子

源代码 (UnigineScript)
void foo(int a) {
	log.message("%d\n",a);
}

int id = get_function("foo",1);	
call(id,3);

// 结果为: 3
如果打算使用用户类方法的ID对其进行调用而不通过静态方法进行调用,可使用下列方式:
源代码 (UnigineScript)
class MyClass {
    
    void print_me() {
        log.message("MyClass::print_me() called\n");
    }
    
    void id_func(MyClass obj) {
        obj.print_me();
    }
};

MyClass m = new MyClass();
call(get_function("MyClass::id_func",1),m);

// 结果为:调用MyClass::print_me()
也可以下列方式调用id_func()函数:
源代码 (UnigineScript)
int id = get_function("MyClass::id_func",1);
m.call(id,m);

variable call(string function_name, variable array)

调用函数,将提供的函数名作为参数。函数参数的数量可进行更改。

参数

  • string function_name - 调用的函数名。
  • variable array - 函数参数。函数参数的数量可进行更改。

返回值

函数执行结果。

例子

源代码 (UnigineScript)
int args[] = ("%s\n","hello world");
call("log.message",args);

// 输出:hello world

variable call(string method_name, variable arguments)

调用外部或用户自定义类方法。

参数

  • string method_name - 调用的方法名。
  • variable arguments - 函数参数。

返回值

函数执行结果。

例子

调用外部类的方法:

源代码 (UnigineScript)
File file = new File("test.cpp","rb");
log.message("%d %s\n",file.call("isOpened"),file.call("getName"));
file.call("close");	// same as file.close();
delete file;

// 输出为: 1 test.cpp
调用用户自定义类的方法:
源代码 (UnigineScript)
class Foo {
	void print(int a) {
		log.message("Foo::print(): %d\n",a);
	}
};
Foo foo = new Foo();
foo.print(1);
foo.call("print",2);

// Foo::print(): 1
// Foo::print(): 2
最新更新: 2018-06-04
Build: ()