创建C#应用程序
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.基于Unigine的应用程序只能通过C#来实现,而无需使用UnigineScript。本文介绍如何在Windows平台上创建一个新的基于Unigine的C#应用程序。
Implementation by using the C# language is very similar to C++. Read the Creating C++ Application article to get basic principles.使用C#语言的实现与C ++非常相似。阅读创建C ++应用程序文章以获取基本原理。
See Also也可以看看#
- Examples located in the <UnigineSDK>/source/csharp/samples/Api and <UnigineSDK>/source/csharp/samples/App folders.示例位于<UnigineSDK>/source/csharp/samples/Api和<UnigineSDK>/source/csharp/samples/App文件夹中。
- The article on Setting Up Development Environment to learn more on how to prepare the development environment.设置开发环境上的文章,以了解有关如何准备开发环境的更多信息。
Creating Empty C# Application创建空的C#应用程序#
It is very easy to start your own C# project by using UNIGINE SDK Browser:使用UNIGINE SDK浏览器来启动自己的C#项目非常容易:
- Open the UNIGINE SDK Browser.打开UNIGINE SDK浏览器。
- Go to the Projects tab and click CREATE NEW.
转到Projects选项卡,然后单击CREATE NEW。
- Specify the following parameters:
- Project name — specify the name of your project.Project name — specify the name of your project.
- Location — specify the path to your project folder.Location — specify the path to your project folder.
- SDK — choose the Unigine SDK.SDK — choose the Unigine SDK.
- API+IDE — choose C# (.NET).API+IDE — choose C# (.NET).
- Precision — specify the precision. In this example we will use double precision.Precision — specify the precision. In this example we will use double precision.
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.Read more about these parameters in this article.指定以下参数:Read more about these parameters in this article.Read more about these parameters in this article.
- Project name — specify the name of your project.Project name-指定项目的名称。
- Location — specify the path to your project folder.Location-指定项目文件夹的路径。
- SDK — choose the Unigine SDK.SDK —选择Unigine SDK。
- API+IDE — choose C# (.NET).API+IDE — 选择 C# (.NET)。
- Precision — specify the precision. In this example we will use double precision.Precision-指定精度。在此示例中,我们将使用双精度。
Read more about these parameters in this article.在本文中阅读有关这些参数的更多信息。 - Click the Create New Project button. The project will appear in the projects list.
单击Create New Project按钮。该项目将出现在项目列表中。
You can run your project by clicking the Run button.您可以通过单击Run按钮来运行项目。
Implementing C# Logic实施C#逻辑#
可以使用以下任一API来实现C#逻辑:
In this section we will add logic to the empty C# application project and rotate the material ball that is created by default.在本节中,我们将向空的C#应用程序项目中添加逻辑,并旋转默认情况下创建的物料球。
- In UNIGINE SDK Browser, choose your C# project created with the C# (.NET) option selected as API+IDE, and click the Open Editor button.
- In UnigineEditor, create a new C# component via Asset Browser.
Let's name it rotator. 在UnigineEditor中,通过Asset Browser创建一个新的C#组件。
我们将其命名为rotator。 - By double-clicking a created asset rotator.cs, it will open in the default IDE. Add the following code to this file.
All saved changes of the component source code make the component update with no compilation required when the Editor window gets focus. 双击创建的资产rotator.cs,它将在默认IDE中打开。将以下代码添加到该文件。
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); } }
编辑器窗口获得焦点时,所有已保存的组件源代码更改都将使组件更新,而无需编译。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); } }
- Add this component to the material ball.将此组件添加到material ball。
- 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.可以将组件分配给任何一个或多个节点,而无需更改其中的任何内容。