This page has been translated automatically.
UNIGINE 基础课程
1. 简介
2. 虚拟世界管理
3. 3D模型准备
4. 材质
5. 摄像机和光照系统
6. 实现应用程序逻辑
7. 制作过场动画与动画序列
8. 准备发布项目
9. 物理系统
10. 优化基础
11. 项目2:第一人称射击游戏
12. 项目3:第三人称越野街机赛车游戏。简介

使用模板创建应用

Getting Started
开始使用#

UNIGINE has a ready-to-use template for making VR projects in C++. It supports Oculus Rift and HTC Vive / Vive Pro (OpenXR) out of the box. It also provides a sample project (VR Sample). Here, you will find a set of 3D models of all popular VR controllers and the implementation of basic mechanics such as grabbing and throwing objects, pressing buttons, opening/closing drawers, and a lot more.UNIGINE 提供了用于创建 VR 项目的现成模板(支持 C++。该模板开箱即用地支持 Oculus Rift 和 HTC Vive / Vive Pro(基于 OpenXR)。它还附带一个示例项目(VR Sample),其中包含各种流行 VR 控制器的 3D 模型,以及抓取和投掷物体、按按钮、打开/关闭抽屉等基本交互机制的实现。

The world in this sample project has its settings optimized for best performance in VR.该示例项目中的世界经过专门设置,优化了 VR 中的性能表现。

Both the template and the sample project are created using the Component System — components attached to objects determine their functionality.模板和示例项目均基于 Component System(组件系统)创建 —— 功能由附加在对象上的组件决定。

You can extend an object's functionality simply by assigning it more components. For example, the laser pointer object in the VR Sample has the following components attached:你可以通过为对象分配更多组件轻松扩展其功能。例如,在 VR Sample 中的激光指针对象上附加了以下组件:

  • ObjMovable — enables grabbing and throwing an objectObjMovable 使对象能够被抓取和投掷
  • ObjLaserPointer — enables casting a ray of light by the objectObjLaserPointer 使对象能够发射激光

You can also implement custom components to extend functionality.你还可以实现自定义组件来扩展功能。

The main features of the VR Sample:VR Sample 的主要功能包括:

  • VR support (OpenXR-compatible devices including Oculus Rift, HTC Vive, and others)VR 支持(兼容 OpenXR 的设备,如 Oculus Rift、HTC Vive 等)
  • A set of physical objects that can be manipulated via controllers (physical objects, buttons, drawers)可通过控制器交互的物理对象集合(物理对象、按钮、抽屉)
  • An interactive laser pointer object交互式激光指针对象
  • Teleportation around the scene场景中进行传送
  • GUI图形界面(GUI)
  • Interaction with GUI objects via controllers通过控制器与 GUI 对象交互

Open SDK Browser, go to the Samples tab, and select Demos.打开 SDK Browser,进入 Samples(示例) 选项卡,选择 Demos(演示)

Find the VR Sample in the Available section and click Install. After installation, the demo will appear in the Installed section, and you can click Copy as Project to create a project based on this sample.Available(可用) 部分中找到 VR Sample(VR 示例),点击 Install(安装)。安装完成后,演示将出现在 Installed(已安装) 部分,此时可以点击 Copy as Project(复制为项目),以该示例创建一个新项目。

In the Create New Project window that opens, enter the name for your new VR project in the corresponding field and click Create New Project.在弹出的 Create New Project(创建新项目) 窗口中,在相应字段中输入你新的 VR 项目名称,然后点击 Create New Project

To open our new VR project in an IDE, select it on the Projects tab of the UNIGINE SDK Browser and click Open Code IDE.要在 IDE 中打开新的 VR 项目,在 UNIGINE SDK Browser 的 Projects(项目) 选项卡中选择它,然后点击 Open Code IDE(打开代码 IDE)

Structure Overview
结构概览#

As the IDE opens, you can see, that the project contains a lot of different classes. The brief overview below will give you a hint on what are they all about.打开 IDE 后,你会发现项目包含许多不同的类。下面的简要概览将帮助你了解它们的作用。

VRInteractable Class
VRInteractable 类#

This is a base class for all objects that you can interact with. It defines a basic set of interactions, in other words: here you define what can a user do with your object. You can add your own type of interaction here.这是所有可交互对象的基类。它定义了一组基本交互方式,换句话说:在这里你可以定义用户可以对你的对象执行哪些操作。你也可以在此添加自己的交互类型。

The following component classes are inherited from the VRInteractable:以下组件类继承自 VRInteractable

ObjMovable This component type can be used for all objects, that can be grabbed, held and thrown (it can be a ball, a pistol, whatever you can take, carry and drop).此组件类型适用于所有可以被抓取、持有和投掷的对象(如球、手枪等,只要是可以拿起、携带并释放的物体)。
ObjHandle This component type can be used for all objects, that can be turned or moved while being held (various handles, levers, valves, etc.).此组件类型适用于所有可以在持有时旋转或移动的对象(各种把手、杠杆、阀门等)。
ObjSwitch This component type can be used for all objects, that can be switched by grabbing (all sorts of buttons and on-off switches, including rotary ones).此组件类型适用于所有可以通过抓取来切换的对象(各种按钮和开关,包括旋转开关)。
ObjLaserPointer This component enables casting a laser ray by the object.
注意
The laser pointer object in the VR Sample world has ObjMovable and ObjLaserPointer components attached.The laser pointer object in the VR Sample world has ObjMovable and ObjLaserPointer components attached.
The laser pointer object in the VR Sample world has ObjMovable and ObjLaserPointer components attached.
该组件使对象能够发射激光光束。
注意
The laser pointer object in the VR Sample world has ObjMovable and ObjLaserPointer components attached.VR Sample 世界中的激光指针对象附加了 ObjMovableObjLaserPointer 两个组件。

VRPlayer Class
VRPlayer 类#

This is a base class for all players. It contains declaration of baseline controls, common basic player operations, event management etc.这是所有玩家类的基类。它声明了基础控制、常用的基本玩家操作、事件管理等。

The following component classes are inherited from the VRPlayer:以下组件类继承自 VRPlayer

VRPlayerPC This component implements a player with standard PC input devices (keyboard + mouse or Xbox360 controller) for VR emulation and contains all related settings and methods.该组件实现了使用标准 PC 输入设备(键盘 + 鼠标或 Xbox360 控制器)的玩家,用于 VR 模拟,并包含所有相关设置和方法。
VRPlayerVR This is a base class implementing common functionality for supported VR devices and contains their common parameters.这是一个基础类,实现了对支持的 VR 设备的通用功能,并包含它们的公共参数。

VRPlayerSpawner Class
VRPlayerSpawner 类#

This class registers all VRPlayer components in the Component System. It checks that VR is initialized and spawns the VRPlayerVR. In case if VR was not initialized, a VRPlayerPC is spawned.该类负责在组件系统中注册所有 VRPlayer 组件。它会检测是否初始化了 VR,并在成功初始化的情况下生成 VRPlayerVR。如果 VR 未初始化,则生成 VRPlayerPC

MenuBaseGUI Class
MenuBaseGUI 类#

This is a base class for all graphic user interfaces (GUI).这是所有图形用户界面(GUI)的基类。

The following component classes are inherited from the MenuBaseGUI:以下组件类继承自 MenuBaseGUI

注意
These components can be attached to GUI objects only.这些组件只能附加到 GUI 对象 上。
HandSampleMenuGui This component implements initialization of widgets for the menu that is attached to a controller.该组件实现附加在控制器上的菜单部件的初始化。
WorldMenuSampleGui This component implements initialization of widgets for the world menu.该组件实现用于世界菜单的部件初始化。

Framework
框架#

Framework includes the Component System which implements the core functionality of components and a set of utility classes and functions used for playing sounds, auxiliary math functions, event system implementation.框架包括 组件系统(Component System),用于实现组件的核心功能,以及一组用于播放声音、辅助数学函数、事件系统等的实用类和函数。

Triggers Class
Triggers 类#

Triggers is a framework class used to mark room obstacles for the VR Player (e.g. room walls, objects, etc.) and give a warning if there is an obstacle on the way (as the player gets closer to an obstacle, controllers' vibration becomes more intense).Triggers 是一个框架类,用于标记 VR 玩家房间中的障碍物(例如墙体、物体等),并在玩家接近障碍物时发出警告(例如控制器的震动强度会随距离障碍物的接近而增强)。

注意
Obstacles are not available for VRPlayerPC.障碍物功能不适用于 VRPlayerPC

You can simply create primitives for walls and objects in your room and add them as children to the node dummy named Obstacles, which is a child of the VR dummy node (see the hierarchy in the Editor below).你可以在房间中简单地创建墙体和物体的基本体,并将它们添加为名为 Obstacles 的 NodeDummy 的子节点,该节点本身是 VR dummy node 的子节点(如下图所示)。

All children of the Obstacles node will be automatically switched to invisible mode and will be used only to inform the player and prevent collisions with objects in the real room.Obstacles 节点的所有子节点将自动切换为不可见状态,仅用于提示玩家并防止与现实世界的物体发生碰撞。

注意
Primitives used to mark obstacles must have their first surface (the one with the 0 index) named as "box", "sphere", "capsule" or "cylinder" in order to be properly converted into corresponding trigger volumes.用于标记障碍物的基本体的第一个表面(索引为 0)名称必须为 "box"、"sphere"、"capsule""cylinder",以便正确地转换为对应的触发体积。

Setting Up a Device and Running
设备设置与运行#

Suppose you have successfully installed your Head-Mounted Display (HMD) of choice (please visit Oculus Rift Setup or HTC Vive Setup if you did not). If you are having difficulties getting your HTC Vive to work, this Troubleshooting guide might be helpful.假设你已经成功安装了你所选择的头戴式显示器(HMD)(如果尚未完成安装,请访问 Oculus Rift 安装页面HTC Vive 安装页面。如果你在使用 HTC Vive 时遇到困难,可以参考这份 故障排除指南)。

Major VR devices (OpenXR-compatible) are supported out of the box.大多数主流 VR 设备(兼容 OpenXR)均可直接使用,无需额外配置。

So, we're ready to see the template in action, let's build our application for the first time.现在我们准备好实际体验模板效果了,让我们首次构建应用程序。

Don't forget to set the appropriate platform and configuration settings for the project before compiling your code in Visual Studio.在使用 Visual Studio 编译代码前,别忘了设置正确的平台和配置。

Build your application in Visual Studio (Build -> Build Solution) or otherwise, and launch it by selecting the project on the Projects tab of the UNIGINE SDK Browser and clicking Run.Visual Studio 中构建应用程序(通过 Build → Build Solution 菜单),或者通过其他方式构建,然后在 UNIGINE SDK 浏览器的 Projects 选项卡中选择项目并点击 Run 运行。

Before running your application via the UNIGINE SDK Browser make sure, that appropriate Customize Run Options (Debug version in our case) are selected, by clicking an ellipsis under the Run button.在通过 UNIGINE SDK 浏览器运行应用程序前,请确保选择了正确的 运行配置(本示例中为 Debug 版本),你可以通过点击 Run 按钮下的省略号来进行设置。

As the application starts, learn about basic mechanics, grab and throw objects, try to teleport and interact with objects in the scene.启动应用程序后,了解基本操作机制,尝试抓取并投掷物体、传送,以及与场景中的对象进行交互。

本页面上的信息适用于 UNIGINE 2.20 SDK.

最新更新: 2025-06-20
Build: ()