This page has been translated automatically.
Видеоуроки
Интерфейс
Основы
Продвинутый уровень
Подсказки и советы
Основы
Программирование на C#
Рендеринг
Профессиональный уровень (SIM)
Принципы работы
Свойства (properties)
Компонентная Система
Рендер
Физика
Редактор UnigineEditor
Обзор интерфейса
Работа с ассетами
Контроль версий
Настройки и предпочтения
Работа с проектами
Настройка параметров ноды
Setting Up Materials
Настройка свойств
Освещение
Sandworm
Использование инструментов редактора для конкретных задач
Расширение функционала редактора
Встроенные объекты
Ноды (Nodes)
Объекты (Objects)
Эффекты
Декали
Источники света
Geodetics
World-ноды
Звуковые объекты
Объекты поиска пути
Player-ноды
Программирование
Основы
Настройка среды разработки
Примеры использования
C++
UnigineScript
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
Учебные материалы

Plugin Class

You can get access to the main loop of the Unigine engine by overriding virtual methods of the Unigine.Plugin class. This article describes the sample located in the <UnigineSDK>/source/csharp/samples/Api/Systems/Ffp/ directory.

Notice
In the C# API you can inherit from the Plugin class only once.

See also#

  • An example can be found in the <UnigineSDK>/source/csharp/samples/Api/Systems/Ffp/ directory.
  • C++ API classes Unigine::Plugin and Unigine::Ffp which have the same methods and behavior as in the C# API.

Plugin Class Usage Example#

C# Side#

To use the Unigine.Plugin class, you should create your own class and inherit it from the Unigine.Plugin class and override necessary methods, which the engine will perform in its main loop.

Source code (C#)
using System;
using Unigine;

class UnigineApp
{
	class FfpPlugin : Plugin
	{
		private float time;

		public override void Gui(EngineWindowViewport window)
		{
			time += Engine.IFps;
			Render(time);
		}

		private void Render(float time)
		{
			// screen size
			int width = 0;
			int height = 0;

			EngineWindow main_window = WindowManager.MainWindow;
			if (main_window != null)
			{
				width = main_window.Size.x;
				height = main_window.Size.y;
			}

			float radius = height / 2.0f;

			Ffp.Enable(Ffp.MODE_SOLID);
			Ffp.SetOrtho(width, height);

			// begin triangles
			Ffp.BeginTriangles();

			// vertex colors
			uint[] colors = { 0xffff0000, 0xff00ff00, 0xff0000ff };

			// create vertices
			int num_vertex = 16;
			for (int i = 0; i < num_vertex; i++)
			{
				float angle = MathLib.PI2 * i / (num_vertex - 1) - time;
				float x = width / 2 + (float)Math.Sin(angle) * radius;
				float y = height / 2 + (float)Math.Cos(angle) * radius;
				Ffp.AddVertex(x, y);
				Ffp.SetColor(colors[i % 3]);
			}

			// create indices
			for (int i = 1; i < num_vertex; i++)
			{
				Ffp.AddIndex(0);
				Ffp.AddIndex(i);
				Ffp.AddIndex(i - 1);
			}

			// end triangles
			Ffp.EndTriangles();

			Ffp.Disable();
		}
	}

	class AppSystemLogic : SystemLogic
	{
		public override bool Init()
		{
			Engine.BackgroundUpdate = Engine.BACKGROUND_UPDATE.BACKGROUND_UPDATE_RENDER_NON_MINIMIZED;
			Unigine.Console.Run("world_load data/ffp");
			return true;
		}

	}

	class AppWorldLogic : WorldLogic
	{
		FfpPlugin plugin;

		public override bool Init()
		{
			// create plugin
			plugin = new FfpPlugin();
			Engine.AddPlugin(plugin);
            Unigine.Console.Active = true;

            return true;
        }

		public override bool Shutdown()
		{
			// remove plugin
			Engine.DestroyPlugin(plugin);

			return true;
		}
	}
}

In this part of the code we create the FfpPlugin class which inherits the Plugin class and override the Gui() method. We specified the Render() method and call it inside the overridden Gui() method. Engine calls this function before Gui each render frame.

In the Main() method, we create an instance of the FfpPlugin class and add it to the engine by using the AddPlugin() method after the engine had been initialized.

Output#

The following result will be shown:

Last update: 17.06.2023
Build: ()