This page has been translated automatically.
Video Tutorials
Interface
Essentials
Advanced
How To
Professional (SIM)
UnigineEditor
Interface Overview
Assets Workflow
Version Control
Settings and Preferences
Working With Projects
Adjusting Node Parameters
Setting Up Materials
Setting Up Properties
Lighting
Sandworm
Using Editor Tools for Specific Tasks
Extending Editor Functionality
Built-in Node Types
Nodes
Objects
Effects
Decals
Light Sources
Geodetics
World Nodes
Sound Objects
Pathfinding Objects
Players
Programming
Fundamentals
Setting Up Development Environment
Usage Examples
C++
UnigineScript
UUSL (Unified UNIGINE Shader Language)
Plugins
File Formats
Materials and Shaders
Rebuilding the Engine Tools
GUI
Double Precision Coordinates
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
Content Creation
Content Optimization
Materials
Material Nodes Library
Miscellaneous
Input
Math
Matrix
Textures
Art Samples
Tutorials
Warning! This version of documentation is OUTDATED, as it describes an older SDK version! Please switch to the documentation for the latest SDK version.
Warning! This version of documentation describes an old SDK version which is no longer supported! Please upgrade to the latest SDK version.

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: 2023-06-23
Build: ()