To set up an XR scene, add an XR Origin.
These objects are collections of GameObjects and components that provide a frame of reference for transforming spatial tracking data into the scene, including controlling the scene camera. When you add an XR Origin to a scene, it controls the attached camera to track the user’s head-mounted (VR) or hand-held (AR) device. In addition, the versions of the XR Origin that contain GameObjects for controllers will move them to track the user’s controllers.
ノート:
Refer to XR Origin for a description of the XR Origin options available to use in a scene.
Before you can set up a scene for XR, you must first:
The basic steps to set up a scene for XR include:
For AR projects, refer to Scene setup in the AR Foundation manual for additional set up steps and more detailed instructions.
For VR projects using the XR Interaction Toolkit, see General Setup in the Interaction Toolkit manual for additional information.
If you have a scene that can be used in both XR and non-XR contexts, you can use the XRSettings.enabled property to detect whether the XR subsystems are currently loaded and active. With that information you can activate or deactivate the appropriate sets of GameObjects and components.
public void CheckXRStatus()
{
if (UnityEngine.XR.XRSettings.enabled)
{
Debug.Log("XR is active.");
}
else
{
Debug.Log("XR is not available.");
}
}
Note: you can read the value of the XRSettings.enabled property to determine the XR status. However, setting the value is no longer supported and does nothing. For information about how to dynamically turn XR on and off at runtime, refer to Managing XR Loader Lifecycles Manually.