This page has been translated automatically.
Видеоуроки
Интерфейс
Основы
Продвинутый уровень
Подсказки и советы
Основы
Программирование на C#
Рендеринг
Профессиональный уровень (SIM)
Принципы работы
Свойства (properties)
Компонентная Система
Рендер
Режимы вывода изображения
Физика
Браузер SDK 2
Лицензирование и типы лицензий
Дополнения (Add-Ons)
Демонстрационные проекты
API Samples
Редактор UnigineEditor
Обзор интерфейса
Работа с ассетами
Контроль версий
Настройки и предпочтения
Работа с проектами
Настройка параметров ноды
Setting Up Materials
Настройка свойств
Освещение
Sandworm
Использование инструментов редактора для конкретных задач
Расширение функционала редактора
Встроенные объекты
Ноды (Nodes)
Объекты (Objects)
Эффекты
Декали
Источники света
Geodetics
World-ноды
Звуковые объекты
Объекты поиска пути
Player-ноды
Программирование
Основы
Настройка среды разработки
Примеры использования
C++
C#
Унифицированный язык шейдеров UUSL (Unified UNIGINE Shader Language)
Плагины
Форматы файлов
Материалы и шейдеры
Rebuilding the Engine Tools
Интерфейс пользователя (GUI)
Двойная точность координат
API
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
Учебные материалы

Interface Class

Warning
The scope of applications for UnigineScript is limited to implementing materials-related logic (material expressions, scriptable materials, brush materials). Do not use UnigineScript as a language for application logic, please consider C#/C++ instead, as these APIs are the preferred ones. Availability of new Engine features in UnigineScript (beyond its scope of applications) is not guaranteed, as the current level of support assumes only fixing critical issues.

An interface is used to describe a behaviour, which is followed by all of the classes deriving from the interface. An interface class does not implement any functionality. It means that such a class contains only functions declaration. Interface class functions must be implemented by derived classes.

The interface is used to provide a polymorphism. It means that several classes can implement the same interface functions in different ways.

Interface Class#

The interface class is declared as any other class in UnigineScript. In the example, the abstract virtual function declaration is used.

Source code (UnigineScript)
class Interface {
	// functions declaration
	void update() = 0;
	//...;
}
Note that the word Interface is not reserved.

Any class that is inherited from the Interface class must contain an implementation for its functions. For example:

Source code (UnigineScript)
class Bar : Interface {
	// implementation of the interface function for Bar
	void update() {
		log.message("Bar::update(): called\n");
	}
};
class Baz : Interface {
	// implementation of the interface function for Baz
	void update() {
		log.message("Baz::update(): called\n");
	}
};

Example

Let's suppose that there is an interface class, which describes an object:

Source code (UnigineScript)
class Interface {
	void update() = 0;
}
It means that each object must be updated.

Bar and Baz classes decribe two different objects. This classes are inherited from the Interface class, and also the Bar class is derived from the Foo class.

Source code (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");
	}
};

The interface is used to iterate objects of different types that implement that interface. So, you can create an array of the objects and update them all.

Source code (UnigineScript)
Interface interfaces[0];
interfaces.append(new Bar());
interfaces.append(new Baz());
foreach(Interface i; interfaces) {
	i.update();
}
The example displays the following:
Output
Bar::update(): called
Baz::update(): called

Abstract virtual function declaration#

A virtual function is a function, which can be overridden in a derived class.

Notice
When a user class is inherited from another class, both automatically support virtual methods.

You can declare the virtual function the following way (C++ style):

Source code (UnigineScript)
class Foo {
	void foo() = 0;
};
In this case, the function has no any implementation, but the derived class must implement it.
Notice
Also you can declare the virtual function by using the virtual keyword, but it's optional.
Last update: 13.12.2024
Build: ()