This page has been translated automatically.
Видеоуроки
Interface
Essentials
Advanced
Полезные советы
Программирование на C#
Принципы работы
Свойства (properties)
Компонентная Система
Рендер
Физика
Редактор UnigineEditor
Обзор интерфейса
Работа с ассетами
Настройки и предпочтения
Работа с проектами
Настройка параметров узла
Setting Up Materials
Setting Up Properties
Освещение
Landscape Tool
Sandworm (Experimental)
Использование инструментов редактора для конкретных задач
Extending Editor Functionality
Встроенные объекты
Nodes
Objects
Effects
Decals
Light Sources
Geodetics
World Objects
Sound Objects
Pathfinding Objects
Players
Программирование
Основы
Настройка среды разработки
Примеры использования
UnigineScript
C++
Унифицированный язык шейдеров UUSL
File Formats
Rebuilding the Engine Tools
GUI
Двойная точность координат
API
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
Работа с контентом
Оптимизация контента
Материалы
Art Samples
Tutorials
Внимание! Эта версия документация УСТАРЕЛА, поскольку относится к более ранней версии SDK! Пожалуйста, переключитесь на самую актуальную документацию для последней версии SDK.
Внимание! Эта версия документации описывает устаревшую версию SDK, которая больше не поддерживается! Пожалуйста, обновитесь до последней версии SDK.

Variable Export

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 UnigineScipt (beyond its scope of applications) is not guaranteed, as the current level of support assumes only fixing critical issues.

To use variables from your C# code in UnigineScript, you need to export them. After that, they will be available on the script side.

  • External variables are read-only.

See also#

An example can be found in <UnigineSDK>/source/csharp/samples/Api/Scripts/Variables/ directory.

Variable Export Example#

Let's say, you declared a number of variables on C# side. To export them, you will need to do the following:

  1. Register the variable via Unigine.Interpreter.addExternVariable() (the same as the C++ API Unigine::Interpreter::addExternVariable() function.
Source code (C#)
using System;
using Unigine;

class UnigineApp {
	
	/*
	 */
	[STAThread]
	static void Main(string[] args) {

		// export a variable and specify a name to access it from Unigine scripts
		Interpreter.AddExternVariable("my_variable_int",13);
		Interpreter.AddExternVariable("my_variable_float",13.17f);
		Interpreter.AddExternVariable("my_variable_double",13.17);
		Interpreter.AddExternVariable("my_variable_string","13.17s");
		Interpreter.AddExternVariable("my_variable_vec3",new Variable(new vec3(13.0f,17.0f,137.0f)));
		Interpreter.AddExternVariable("my_variable_vec4",new Variable(new vec4(13.0f,17.0f,137.0f,173.0f)));

		// init engine
		Engine engine = Engine.Init(Engine.VERSION,args);
		
		// enter main loop
		engine.Main();
		
		// shutdown engine
		Engine.Shutdown();
	}
}

Access from Scripts#

After the registration, you can access variables from a script by their registered names:

Source code (UnigineScript)
// variables.cpp

int init() {

	log.message("\n");
	
	log.warning("int:      %s\n",typeinfo(my_variable_int));
	log.warning("float:    %s\n",typeinfo(my_variable_float));
	log.warning("double:   %s\n",typeinfo(my_variable_double));
	log.warning("string:   %s\n",typeinfo(my_variable_string));
	log.warning("variable: %s\n",typeinfo(my_variable_vec3));
	log.warning("variable: %s\n",typeinfo(my_variable_vec4));
	
	// show console
	engine.console.setActivity(1);
	
	return 1;
}

Output#

The following results will be printed into the console after launching the application:

Output
int:		int: 13
float:		float: 13.17
double:		double: 13.17
string:		string: "13.17s"
variable: 	vec3: 13 17 137
variable: 	vec4: 13 17 137 173
Last update: 24.11.2020
Build: ()