2.8 KiB
uid
| uid |
|---|
| openxr-native-api |
OpenXR native API
For users familiar with the OpenXR specification, the class OpenXRNativeApi contains a partial public C# port of OpenXR. You can use the OpenXR native API to write low-level OpenXR code if you prefer a lower-level abstraction.
Refer to the OpenXR specification for more detailed information about each extension.
Supported extensions
The OpenXR native API currently supports the following OpenXR extensions:
- XR_EXT_future
- XR_EXT_spatial_anchor
- XR_EXT_spatial_entity
- XR_EXT_spatial_marker_tracking
- XR_EXT_spatial_persistence
- XR_EXT_spatial_persistence_operations
- XR_EXT_spatial_plane_tracking
Enable extensions
The OpenXR native API is a static class, so C# allows you to call its methods at any time from any C# script. However, methods provided by an extension will return the XrResult.FunctionUnsupported error code unless the required extension is enabled.
The OpenXR Plug-in supports enabling extensions via OpenXR features.
To enable the required extensions for the native API:
- Create a class that inherits
OpenXRFeature. - Fill out the required information for the
OpenXRFeatureAttributeconstructor, including the extensions you wish to enable. - Implement OnInstanceCreate. Return
falseif any requirements to enable your feature are not met, such as if runtime failed to enable the required extensions. - Go to Project Settings > XR Plug-in Management and enable your feature in the OpenXR tab.
- At runtime, use
OpenXRSettings.Instance.GetFeature<T>to get your feature. Iffeature != null && feature.enabled, your app can use the native API methods provided by the enabled extensions.
Example code
The following example code demonstrates how to implement a simple OpenXR feature that enables XR_EXT_spatial_plane_tracking and its required dependencies:
[!code-csSpatialPlaneTrackingFeatureEXT]