Class OpenXRFeature
A Unity OpenXR Feature. This class can be inherited from to add feature specific data and logic. Feature-specific settings are serialized for access at runtime.
Inherited Members
Namespace: UnityEngine.XR.OpenXR.Features
Assembly: Unity.XR.OpenXR.dll
Syntax
[Serializable]
public abstract class OpenXRFeature : ScriptableObject
Properties
enabled
Feature is enabled and will be started when the OpenXR loader is initialized.
Note that the enabled state of a feature cannot be modified once OpenXR is initialized and can be used at runtime to determine if a feature successfully initialized.
Declaration
public bool enabled { get; set; }
Property Value
Type | Description |
---|---|
bool |
xrGetInstanceProcAddr
Accessor for xrGetInstanceProcAddr function pointer.
Declaration
protected static IntPtr xrGetInstanceProcAddr { get; }
Property Value
Type | Description |
---|---|
IntPtr |
Methods
Awake()
Called when the object is loaded.
Declaration
protected virtual void Awake()
Remarks
Additional information: ScriptableObject.Awake
CreateSubsystem<TDescriptor, TSubsystem>(List<TDescriptor>, string)
Creates a subsystem based on a given a list of descriptors and a specific subsystem id. Promoted to public for extensions.
Declaration
protected void CreateSubsystem<TDescriptor, TSubsystem>(List<TDescriptor> descriptors, string id) where TDescriptor : ISubsystemDescriptor where TSubsystem : ISubsystem
Parameters
Type | Name | Description |
---|---|---|
List<TDescriptor> | descriptors | List of TDescriptor instances to use for subsystem matching |
string | id | The identifier key of the particular subsystem implementation being requested |
Type Parameters
Name | Description |
---|---|
TDescriptor | The descriptor type being passed in |
TSubsystem | The subsystem type being requested |
DestroySubsystem<T>()
Destroys a subsystem instance of a given type. Subsystem is assumed to already be loaded from a previous call to CreateSubsystem. Promoted to public for extensions.
Declaration
protected void DestroySubsystem<T>() where T : class, ISubsystem
Type Parameters
Name | Description |
---|---|
T | A subclass of ISubsystem |
GetAction(InputAction)
Returns XrAction handle bound to the given UnityEngine.InputSystem.InputAction.
Declaration
protected ulong GetAction(InputAction inputAction)
Parameters
Type | Name | Description |
---|---|---|
InputAction | inputAction | Action to retrieve XrAction handles for |
Returns
Type | Description |
---|---|
ulong | XrAction handle bound to the given UnityEngine.InputSystem.InputAction or 0 if there is no bound XrAction |
GetAction(InputDevice, string)
Returns XrAction handle bound to the given device and usage.
Declaration
protected ulong GetAction(InputDevice device, string usageName)
Parameters
Type | Name | Description |
---|---|---|
InputDevice | device | Device to retrieve XrAction handles for |
string | usageName | Usage name to retrieve XrAction handles for |
Returns
Type | Description |
---|---|
ulong | XrAction handle bound to the given device and usage, or 0 if there is no bound XrAction |
GetAction(InputDevice, InputFeatureUsage)
Returns XrAction handle bound to the given device and usage.
Declaration
protected ulong GetAction(InputDevice device, InputFeatureUsage usage)
Parameters
Type | Name | Description |
---|---|---|
InputDevice | device | Device to retrieve XrAction handles for |
InputFeatureUsage | usage | Usage to retrieve XrAction handles for |
Returns
Type | Description |
---|---|
ulong | XrAction handle bound to the given device and usage, or 0 if there is no bound XrAction |
GetCurrentAppSpace()
Returns the current app space.
Declaration
protected static ulong GetCurrentAppSpace()
Returns
Type | Description |
---|---|
ulong | Current app space |
GetCurrentInteractionProfile(string)
Returns the path of the current interaction profile for the given user path.
Declaration
protected static ulong GetCurrentInteractionProfile(string userPath)
Parameters
Type | Name | Description |
---|---|---|
string | userPath | User path |
Returns
Type | Description |
---|---|
ulong | A path to the interaction profile, or XrPath.none if the path could not be retrieved. |
GetCurrentInteractionProfile(ulong)
Returns the path of the current interaction profile for the given user path.
Declaration
protected static ulong GetCurrentInteractionProfile(ulong userPath)
Parameters
Type | Name | Description |
---|---|---|
ulong | userPath | OpenXR User Path (eg: /user/hand/left) |
Returns
Type | Description |
---|---|
ulong | A path to the interaction profile, or XrPath.none if the path could not be retrieved. |
GetEnvironmentBlendMode()
Returns the current XR Environment Blend Mode.
Declaration
protected static XrEnvironmentBlendMode GetEnvironmentBlendMode()
Returns
Type | Description |
---|---|
XrEnvironmentBlendMode | Current XR Environment Blend Mode |
GetValidationChecks(List<ValidationRule>, BuildTargetGroup)
Allows a feature to add to a list of validation rules which your feature will evaluate at build time. Details of the validation results can be found in OpenXRProjectValidation.
Declaration
protected virtual void GetValidationChecks(List<OpenXRFeature.ValidationRule> rules, BuildTargetGroup targetGroup)
Parameters
Type | Name | Description |
---|---|---|
List<OpenXRFeature.ValidationRule> | rules | Your feature will check the rules in this list at build time. Add rules that you want your feature to check, and remove rules that you want your feature to ignore. |
BuildTargetGroup | targetGroup | Build target group these validation rules will be evaluated for. |
GetViewConfigurationTypeForRenderPass(int)
Returns viewConfigurationType for the given renderPass index.
Declaration
protected static int GetViewConfigurationTypeForRenderPass(int renderPassIndex)
Parameters
Type | Name | Description |
---|---|---|
int | renderPassIndex | RenderPass index |
Returns
Type | Description |
---|---|
int | viewConfigurationType for certain renderPass. Return 0 if invalid renderPass. |
HookGetInstanceProcAddr(IntPtr)
Called to hook xrGetInstanceProcAddr. Returning a different function pointer allows intercepting any OpenXR method.
Declaration
protected virtual IntPtr HookGetInstanceProcAddr(IntPtr func)
Parameters
Type | Name | Description |
---|---|---|
IntPtr | func | xrGetInstanceProcAddr native function pointer |
Returns
Type | Description |
---|---|
IntPtr | Function pointer that Unity will use to look up OpenXR native functions. |
OnAppSpaceChange(ulong)
Called when the reference xrSpace for the app changes.
Declaration
protected virtual void OnAppSpaceChange(ulong xrSpace)
Parameters
Type | Name | Description |
---|---|---|
ulong | xrSpace | Handle of the xrSpace |
OnDisable()
Called when the object is loaded.
Declaration
protected virtual void OnDisable()
Remarks
Additional information: ScriptableObject.OnDisable
OnEnable()
Called when the object is loaded.
Declaration
protected virtual void OnEnable()
Remarks
Additional information: ScriptableObject.OnEnable
OnEnabledChange()
Called when the enabled state of a feature changes
Declaration
protected virtual void OnEnabledChange()
OnEnvironmentBlendModeChange(XrEnvironmentBlendMode)
Notification to the feature implementer that the environment blend mode has changed.
Declaration
protected virtual void OnEnvironmentBlendModeChange(XrEnvironmentBlendMode xrEnvironmentBlendMode)
Parameters
Type | Name | Description |
---|---|---|
XrEnvironmentBlendMode | xrEnvironmentBlendMode | New environment blend mode value |
OnFormFactorChange(int)
Notification to the feature implementer that the form factor has changed.
Declaration
protected virtual void OnFormFactorChange(int xrFormFactor)
Parameters
Type | Name | Description |
---|---|---|
int | xrFormFactor | New form factor value |
OnInstanceCreate(ulong)
Called after xrCreateInstance.
Declaration
protected virtual bool OnInstanceCreate(ulong xrInstance)
Parameters
Type | Name | Description |
---|---|---|
ulong | xrInstance | Handle of the xrInstance |
Returns
Type | Description |
---|---|
bool | Always returns true, as this is intended to be overridden. |
OnInstanceDestroy(ulong)
Called before xrDestroyInstance
Declaration
protected virtual void OnInstanceDestroy(ulong xrInstance)
Parameters
Type | Name | Description |
---|---|---|
ulong | xrInstance | Handle of the xrInstance |
OnInstanceLossPending(ulong)
Called when the OpenXR loader receives the XR_TYPE_EVENT_DATA_INSTANCE_LOSS_PENDING event from the runtime. This is a notification to the feature implementer that the instance is about to be lost. This feature should do what it needs to do to clean up in preparation for termination.
Declaration
protected virtual void OnInstanceLossPending(ulong xrInstance)
Parameters
Type | Name | Description |
---|---|---|
ulong | xrInstance | The instance that is going to be lost |
OnSessionBegin(ulong)
Called after xrSessionBegin.
Declaration
protected virtual void OnSessionBegin(ulong xrSession)
Parameters
Type | Name | Description |
---|---|---|
ulong | xrSession | Handle of the xrSession |
OnSessionCreate(ulong)
Called after xrCreateSession.
Declaration
protected virtual void OnSessionCreate(ulong xrSession)
Parameters
Type | Name | Description |
---|---|---|
ulong | xrSession | Handle of the xrSession |
OnSessionDestroy(ulong)
Called before xrDestroySession.
Declaration
protected virtual void OnSessionDestroy(ulong xrSession)
Parameters
Type | Name | Description |
---|---|---|
ulong | xrSession | Handle of the xrSession |
OnSessionEnd(ulong)
Called before xrEndSession.
Declaration
protected virtual void OnSessionEnd(ulong xrSession)
Parameters
Type | Name | Description |
---|---|---|
ulong | xrSession | Handle of the xrSession |
OnSessionExiting(ulong)
Called when the runtime transitions to the XR_SESSION_STATE_EXITING state.
Declaration
protected virtual void OnSessionExiting(ulong xrSession)
Parameters
Type | Name | Description |
---|---|---|
ulong | xrSession | Handle of the xrSession |
OnSessionLossPending(ulong)
Called when the runtime transitions to the XR_SESSION_STATE_LOSS_PENDING state. This is a notification to the feature implementer that the session is about to be lost. This feature should do what it needs to do to prepare for potential session recreation.
Declaration
protected virtual void OnSessionLossPending(ulong xrSession)
Parameters
Type | Name | Description |
---|---|---|
ulong | xrSession | The session that is going to be lost |
OnSessionStateChange(int, int)
Called when the OpenXR loader receives the XR_TYPE_EVENT_DATA_SESSION_STATE_CHANGED event from the runtime signaling that the XrSessionState has changed.
Declaration
protected virtual void OnSessionStateChange(int oldState, int newState)
Parameters
Type | Name | Description |
---|---|---|
int | oldState | Previous state |
int | newState | New state |
OnSubsystemCreate()
Called after the OpenXR Loader is initialized and has created its subsystems.
Declaration
protected virtual void OnSubsystemCreate()
OnSubsystemDestroy()
Called before the OpenXR loader destroys its subsystems.
Declaration
protected virtual void OnSubsystemDestroy()
OnSubsystemStart()
Called after the OpenXR loader has started its subsystems.
Declaration
protected virtual void OnSubsystemStart()
OnSubsystemStop()
Called before the OpenXR loader stops its subsystems.
Declaration
protected virtual void OnSubsystemStop()
OnSystemChange(ulong)
Called after xrGetSystem.
Declaration
protected virtual void OnSystemChange(ulong xrSystem)
Parameters
Type | Name | Description |
---|---|---|
ulong | xrSystem | Handle of the xrSystemId |
OnViewConfigurationTypeChange(int)
Notification to the feature implementer that the view configuration type has changed.
Declaration
protected virtual void OnViewConfigurationTypeChange(int xrViewConfigurationType)
Parameters
Type | Name | Description |
---|---|---|
int | xrViewConfigurationType | New view configuration type |
PathToString(ulong)
Converts an XrPath to a string.
Declaration
protected static string PathToString(ulong path)
Parameters
Type | Name | Description |
---|---|---|
ulong | path | Path to convert |
Returns
Type | Description |
---|---|
string | String that represents the path, or null if the path is invalid. |
RegisterStatsDescriptor(string, StatFlags)
Registers an OpenXR statistic with the given name and flags. This method is not thread safe, so it should only be called at OnInstanceCreate.
Declaration
protected static ulong RegisterStatsDescriptor(string statName, OpenXRFeature.StatFlags statFlags)
Parameters
Type | Name | Description |
---|---|---|
string | statName | String identifier for the statistic. |
OpenXRFeature.StatFlags | statFlags | Properties to be applied to the statistic. |
Returns
Type | Description |
---|---|
ulong | Stat Id |
SetEnvironmentBlendMode(XrEnvironmentBlendMode)
Set the current XR Environment Blend Mode if it is supported by the active runtime. If not supported, fall back to the runtime preference.
Declaration
protected static void SetEnvironmentBlendMode(XrEnvironmentBlendMode xrEnvironmentBlendMode)
Parameters
Type | Name | Description |
---|---|---|
XrEnvironmentBlendMode | xrEnvironmentBlendMode | Environment Blend Mode (e.g.: Opaque = 1, Additive = 2, AlphaBlend = 3) |
SetStatAsFloat(ulong, float)
Assigns a float value to a registered statistic. Its thread safe.
Declaration
protected static void SetStatAsFloat(ulong statId, float value)
Parameters
Type | Name | Description |
---|---|---|
ulong | statId | Identifier of the previously registered statistic. |
float | value | Float value to be assigned to the stat. |
SetStatAsUInt(ulong, uint)
Assigns an unsigned integer value to a registered statistic. It is thread safe.
Declaration
protected static void SetStatAsUInt(ulong statId, uint value)
Parameters
Type | Name | Description |
---|---|---|
ulong | statId | Identifier of the previously registered statistic. |
uint | value | Unsigned integer value to be assigned to the stat. |
Remarks
IMPORTANT: Due to limitations in native code, values over 16777216 (1<<24) might not be reflected accurately.
StartSubsystem<T>()
Start a subsystem instance of a given type. Subsystem is assumed to already be loaded from a previous call to CreateSubsystem. Promoted to public for extensions.
Declaration
protected void StartSubsystem<T>() where T : class, ISubsystem
Type Parameters
Name | Description |
---|---|
T | A subclass of ISubsystem |
StopSubsystem<T>()
Stops a subsystem instance of a given type. Subsystem is assumed to already be loaded from a previous call to CreateSubsystem. Promoted to public for extensions.
Declaration
protected void StopSubsystem<T>() where T : class, ISubsystem
Type Parameters
Name | Description |
---|---|
T | A subclass of ISubsystem |
StringToPath(string)
Converts a string to an XrPath.
Declaration
protected static ulong StringToPath(string str)
Parameters
Type | Name | Description |
---|---|---|
string | str | String to convert |
Returns
Type | Description |
---|---|
ulong | Path of converted string, or XrPath.none if string could not be converted. |