This page has been translated automatically.
视频教程
界面
要领
高级
实用建议
专业(SIM)
UnigineEditor
界面概述
资产工作流程
设置和首选项
项目开发
调整节点参数
Setting Up Materials
设置属性
照明
Landscape Tool
Sandworm
使用编辑器工具执行特定任务
如何擴展編輯器功能
嵌入式节点类型
Nodes
Objects
Effects
Decals
光源
Geodetics
World Nodes
Sound Objects
Pathfinding Objects
Players
编程
基本原理
搭建开发环境
使用范例
C++
C#
UUSL (Unified UNIGINE Shader Language)
Plugins
File Formats
Materials and Shaders
Rebuilding the Engine Tools
GUI
双精度坐标
应用程序接口
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
创建内容
内容优化
Materials
Material Nodes Library
Miscellaneous
Input
Math
Matrix
Textures
Art Samples
Tutorials
注意! 这个版本的文档是过时的,因为它描述了一个较老的SDK版本!请切换到最新SDK版本的文档。
注意! 这个版本的文档描述了一个不再受支持的旧SDK版本!请升级到最新的SDK版本。

Call()方法

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

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
最新更新: 2022-03-10
Build: ()