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

接口类

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

使用接口对行为进行描述,这些行为被所有继承自接口的类所遵循。接口类并不会执行任何函数,这就意味着这种类仅包含对函数的声明。必须使用派生类才能执行接口类函数。

使用接口提供多形态。即数个类可对同一个接口函数通过不同的方法进行操作。

Interface Class接口类#

接口类的声明与UnigineScript中其它类的声明一样。 在此示例中,使用虚拟抽象函数声明

源代码 (UnigineScript)
class Interface {
	// 声明函数
	void update() = 0;
	//...;
}
注意Interface一字未被保留。

所有继承自Interface的类必须包括对函数的实施方法。例如:

源代码 (UnigineScript)
class Bar : Interface {
	// 执行用于Bar的接口函数
	void update() {
		log.message("Bar::update(): called\n");
	}
};
class Baz : Interface {
	// 执行用于Baz的接口函数
	void update() {
		log.message("Baz::update(): called\n");
	}
};

示例

试想存在一个对对象进行描述的接口类:

源代码 (UnigineScript)
class Interface {
	void update() = 0;
}
这就意味着每个对象必须被更新。

BarBaz 类描述了两种不同的对象。这两种类继承自Interface类且 Bar类派生自Foo类。

源代码 (UnigineScript)
class Foo {
	void foo() = 0;
};
class Bar : Foo, Interface {
	void update() {
		log.message("Bar::update(): called\n");
	}
};
class Baz : Interface {
	void update() {
		log.message("Baz::update(): called\n");
	}
};

使用此接口对不同类型的对象进行迭代,这些类型的对象执行对此接口的操作。因此可创建一个对象数组并将对象进行更新。

源代码 (UnigineScript)
Interface interfaces[0];
interfaces.append(new Bar());
interfaces.append(new Baz());
foreach(Interface i; interfaces) {
	i.update();
}
此示例输出以下内容:
输出
Bar::update(): called
Baz::update(): called

Abstract virtual function declaration抽象虚拟函数声明#

虚拟函数也是一种函数,可在派生类中将此函数覆盖。

注意
如果某个用户类继承自其它类,那么两种类都自动支持虚拟方法。

可通过下列方式(C++风格)声明虚拟函数:

源代码 (UnigineScript)
class Foo {
	void foo() = 0;
};
这种情况下,这样的函数并无任何实施方法而派生类必须对其进行实施。
注意
也可使用virtual关键字声明虚拟函数,但此为可选选项。
最新更新: 2017-07-03
Build: ()