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

创建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#项目非常容易:

  1. Open the UNIGINE SDK Browser.打开UNIGINE SDK浏览器。
  2. Go to the Projects tab and click CREATE NEW.
    转到Projects选项卡,然后单击CREATE NEW
  3. 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.
    注意
    Read more about these parameters in this article.Read more about these parameters in this article.
    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.
    指定以下参数:
    • 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.本文中阅读有关这些参数的更多信息。
  4. 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按钮来运行项目。

注意
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#.默认情况下,在世界脚本文件中创建WorldLight和PlayerSpectator。您可以将世界脚本的功能留空,并使用C#创建自己的灯光和播放器。

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#应用程序项目中添加逻辑,并旋转默认情况下创建的物料球。

  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.在UNIGINE SDK浏览器中,选择使用C# (.NET)选项作为API + IDE选择创建的C#项目,然后单击Open Editor按钮。

    UnigineEditor will open.UnigineEditor将打开。

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

    Let's name it rotator.
    在UnigineEditor中,通过Asset Browser创建一个新的C#组件。

    我们将其命名为rotator
  3. By double-clicking a created asset rotator.cs, it will open in the default IDE. Add the following code to this file.
    源代码 (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.
    双击创建的rotator.cs资源,它将在默认IDE中打开。将以下代码添加到该文件。
    源代码 (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);
    	}
    }
    编辑器窗口获得焦点时,所有已保存的组件源代码更改都将使组件更新,而无需编译。
  4. Add this component to the material ball.将此组件添加到material ball
  5. Run an instance of the application by clicking the Play button on the toolbar.
    通过单击工具栏上的 Play 按钮来运行该应用程序的实例。

The component can be assigned to any node or nodes without changing anything in it.可以将组件分配给任何一个或多个节点,而无需更改其中的任何内容。

最新更新: 2023-12-19
Build: ()