This page has been translated automatically.
视频教程
界面
要领
高级
实用建议
专业(SIM)
UnigineEditor
界面概述
资产工作流程
设置和首选项
项目开发
调整节点参数
Setting Up Materials
设置属性
照明
Landscape Tool
Sandworm
使用编辑器工具执行特定任务
如何擴展編輯器功能
嵌入式节点类型
Nodes
Objects
Effects
Decals
光源
Geodetics
World Nodes
Sound Objects
Pathfinding Objects
Players
编程
基本原理
搭建开发环境
使用范例
C++
UnigineScript
UUSL (Unified UNIGINE Shader Language)
Plugins
File Formats
Materials and Shaders
Rebuilding the Engine Tools
GUI
双精度坐标
应用程序接口
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
创建内容
内容优化
Materials
Material Nodes Library
Miscellaneous
Input
Math
Matrix
Textures
Art Samples
Tutorials
注意! 这个版本的文档是过时的,因为它描述了一个较老的SDK版本!请切换到最新SDK版本的文档。
注意! 这个版本的文档描述了一个不再受支持的旧SDK版本!请升级到最新的SDK版本。

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() {
			time += Engine.ifps;
			render(time);
		}
		
		private void render(float time) {
			
			App app = Engine.app;
			Ffp ffp = Engine.ffp;
			
			// screen size
			int width = app.GetWidth();
			int height = app.GetHeight();
			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();
		}
	}
	
	/*
	 */
	[STAThread]
	static void Main(string[] args) {
		
		// initialize engine
		Engine engine = Engine.Init(Engine.VERSION,args);
		
		// create plugin
		FfpPlugin plugin = new FfpPlugin();
		engine.AddPlugin(plugin);
		
		// enter main loop
		engine.Main();
		
		// remove plugin
		engine.RemovePlugin(plugin);
		
		// shutdown engine
		Engine.Shutdown();
	}
}

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.

Unigine Script Side#

All the logic is implemented in the C# Ffp.cs file. There is only one command in the UnigineScript ffp.cpp file to show a console:

Source code (UnigineScript)
int init() {
		
	// show console
	engine.console.setActivity(1);

	return 1;
}

Output#

The following result will be shown:

Last update: 2022-03-10
Build: ()