This page has been translated automatically.
视频教程
界面
要领
高级
实用建议
基础
专业(SIM)
UnigineEditor
界面概述
资源工作流程
Version Control
设置和首选项
项目开发
调整节点参数
Setting Up Materials
设置属性
照明
Sandworm
使用编辑器工具执行特定任务
如何擴展編輯器功能
嵌入式节点类型
Nodes
Objects
Effects
Decals
光源
Geodetics
World Nodes
Sound Objects
Pathfinding Objects
Players
编程
基本原理
搭建开发环境
使用范例
C++
UnigineScript
统一的Unigine着色器语言 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

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: 2024-08-16
Build: ()