This page has been translated automatically.
UnigineEditor
Interface Overview
Assets Workflow
Settings and Preferences
Adjusting Node Parameters
Setting Up Materials
Setting Up Properties
Landscape Tool
Using Editor Tools for Specific Tasks
FAQ
Программирование
Fundamentals
Setting Up Development Environment
Usage Examples
UnigineScript
C++
UUSL (Unified UNIGINE Shader Language)
File Formats
Rebuilding the Engine and 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
CIGI Client Plugin
Rendering-Related Classes
Внимание! Эта версия документация УСТАРЕЛА, поскольку относится к более ранней версии SDK! Пожалуйста, переключитесь на самую актуальную документацию для последней версии SDK.
Внимание! Эта версия документации описывает устаревшую версию SDK, которая больше не поддерживается! Пожалуйста, обновитесь до последней версии SDK.

Creating C# Application

A Unigine-based application can be implemented by means of C# only, without using UnigineScript. This article describes how to create a new Unigine-based C# application in Visual Studio on Windows platform.

Implementation by using the C# language is very similar to C++. Read the Creating C++ Application article to get basic principles.

Notice
  • C# (.NET Core) API is cross-platform.
  • C# (.NET Framework) API is supported on Windows only.

See Also#

  • Examples located in the <UnigineSDK>/source/csharp/samples/Api and <UnigineSDK>/source/csharp/samples/App folders.
  • The article on Setting Up Development Environment to learn more on how to prepare the development environment.

Creating Empty C# Application#

It is very easy to start your own C# project by using UNIGINE SDK Browser:

  1. Open the UNIGINE SDK Browser.
  2. Go to the Projects tab and click CREATE NEW.

  3. Specify the following parameters:

    • Project name — specify the name of your project.
    • Location — specify the path to your project folder.
    • SDK — choose the Unigine SDK.
    • API+IDE — choose either of two C# options. Choose C# (.NET Core) to start working with the C# API with the Component System available.
    • Architecture — specify the architecture of your target platform.
    • Precision — specify the precision. In this example we will use double precision.
    Notice
    Read more about these parameters in this article.
  4. Click the Create New Project button. The project will appear in the projects list.

You can run your project by clicking the Run button.

Notice
By default, in the world script file a WorldLight and a PlayerSpectator are created. You can leave functions of the world script empty, and create your own lights and players by using C#.

Implementing C# Logic#

Notice
To engage the C# Component System supported by C# (.NET Core) API follow the instructions in the C# Component System Usage Example.

In this section we will add logic to the empty C# application project.

The following example shows how to rotate the material ball that was created by default in your project.

  1. In the UNIGINE SDK Browser, choose your C# project and click the Edit Code button.

    Visual Studio will be opened.
  2. In Visual Studio, write the following code in your project's AppWorldLogic.cs file.
    Source code (C#)
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    using Unigine;
    
    namespace UnigineApp
    {
    
    	class AppWorldLogic : WorldLogic
    	{
    		// define pointer to node
    		Node node;
    
    		public AppWorldLogic()
    		{
    		}
    
    		public override bool Init()
    		{
    			// find the material ball node by its name
    			node = Engine.editor.GetNodeByName("material_ball");
    			return true;
    		}
    
    		public override bool Shutdown()
    		{
    			return true;
    		}
    
    		public override bool Destroy()
    		{
    			node.clearPtr();
    			return true;
    		}
    
    		public override bool Update()
    		{
    			// set the transformation to the node
    			double angle = Engine.ifps * 90.0f;
    			node.Transform = node.Transform * MathLib.RotateZ(angle);
    			return true;
    		}
    
    		public override bool Render()
    		{
    			return true;
    		}
    
    		public override bool Flush()
    		{
    			return true;
    		}
    
    		public override bool Save(Stream stream)
    		{
    			return true;
    		}
    
    		public override bool Restore(Stream stream)
    		{
    			return true;
    		}
    	}
    }
  3. Build your project by clicking Build -> Build Solution in Visual Studio.

  4. Start your project by clicking Debug -> Start in a proper mode in Visual Studio.

Notice
To run your project from SDK Browser, specify the path to the .exe file of your C# project in SDK Browser by customizing Run Project
Last update: 16.08.2019
Build: ()