This page has been translated automatically.
Video Tutorials
Interface
Essentials
Advanced
How To
Basics
Rendering
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
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
Content Creation
Content Optimization
Materials
Material Nodes Library
Miscellaneous
Input
Math
Matrix
Textures
Art Samples
Tutorials

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 on Windows platform.

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

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 C# (.NET).
    • 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#

To implement C# logic, use the following approaches either separately, or in combination:

  • C# Component System, which is enabled by default and integrated into the Editor: this way it is easier to implement your application logic in components and assign them to any node to be executed. A component can be reused for as many nodes as you need without changing anything in it. If a node is renamed or disabled, the component assigned to it does not require any changes due to that. When you change anything in your component's logic, the changes are applied to all nodes having this component assigned. The Editor also provides for running an instance of the application to check the result immediately.
  • SystemLogic and WorldLogic global classes that are available in the /source folder.

In this section we will add logic to the empty C# application project and rotate the material ball that is created by default.

  1. In UNIGINE SDK Browser, choose your C# project created with the C# (.NET) option selected as API+IDE, and click the Open Editor button.

    UnigineEditor will open.

  2. In UnigineEditor, create a new C# component via Asset Browser.

    Let's name it rotator.
  3. By double-clicking a created asset rotator.cs, it will open in the default IDE. Add the following code to this file.
    Source code (C#)
    public class rotator : Component
    {
    	public float angle = 30.0f;
    	
    	void Update()
    	{
    		// write here code to be called before updating each render frame
    		node.Rotate(0, 0, angle * Game.IFps);
    	}
    }
    All saved changes of the component source code make the component update with no compilation required when the Editor window gets focus.
  4. Add this component to the material ball.
  5. Run an instance of the application by clicking the Play button on the toolbar.

The component can be assigned to any node or nodes without changing anything in it.

Last update: 2023-02-16
Build: ()