Unity's OpenXR+XR Interaction Toolkit realizes UI interaction

I. Introduction

In VR, we often interact with some 3D UI. Today we will talk about how to realize the interaction between OpenXR+XRInteraction Toolkit and UI.

2. Preparations

We need to prepare the Unity project and environment configuration
. With the previous article: Introduction to the basic configuration of OpenXR+XR Interaction Toolkit for Unity , we will not elaborate on these, and you can review them yourself.

Brief description of the process:
We create a new 3D (URP) project
and then install the XR Interaction ToolKit plug-in through PackageManager.
Configure the Preset of XR Interaction Toolkit
to create a new 3D scene

ready to work

3. Create a canvas

insert image description here
Then perform the following settings:
1. Modify RenderMode to World Space mode
2. Modify the Scale of Transform to (0.002,0.002,0.002)
3. Modify the coordinate position of when, such as near the dot (0.0.0)
4. Add XR components Tracked Device Graphic Raycaster (can interact with VR handle)

insert image description here

4. Add XR Origin

Create a VR operation object through the menu GameObject->XR->XR Origin (VR).
Check whether the LeftHand Controller and RightHand Controller are configured correctly.
insert image description here
Set
insert image description here
the resource of the handle model model in the Prefabs directory of XR Interaction Toolkit
insert image description here

The above settings are completed, if there is no problem.
Check the XR Ray Interactor, another component of the Hand Controller, to confirm whether the Enable Interaction With UI GameObjects option is checked. It must be checked here to interact with the UI through the ray.
insert image description here

5. Upgrade EventSystem

Select the EventSystem game object, and we will find it as shown in the figure below:
the reason is self-evident, that is, our original StandaloneInputModule is suitable for the old UI, and cannot be used in the VR environment, and needs to be upgraded to use the InputSystemUIInputModule of XR.
After the upgrade, you can click the UI of VR with the mouse in the editor environment, without using the handle ray. If you don't need this feature, just remove it directly.
insert image description here
We just click the Replace With xxxx button. After the replacement, as shown in the figure below;
insert image description here

Additive XR UI Input Module

Next, add the InputModule module for VR handle ray interaction. If not added, the ray emitted by our handle cannot control the UI.
Note that the configuration on its property Input System UIActions is automatically configured. If it is empty, it may be Our PresetManager was not configured successfully.
insert image description here

Well, at this point, we can run the Demo to try it out.

Guess you like

Origin blog.csdn.net/qq563129582/article/details/130355661