Class XRCameraExtensions
Provides extensions to the XRCameraSubsystem
.
Inheritance
Inherited Members
Namespace: UnityEngine.XR.ARExtensions
Syntax
public static class XRCameraExtensions
Methods
ActivateExtensions(XRCameraSubsystem)
For internal use. Sets the active subsystem whose extension methods should be used.
Declaration
public static void ActivateExtensions(this XRCameraSubsystem cameraSubsystem)
Parameters
Type | Name | Description |
---|---|---|
XRCameraSubsystem | cameraSubsystem | The |
Configurations(XRCameraSubsystem)
Enumerate the CameraConfigurations supported by the device.
Declaration
public static CameraConfigurationCollection Configurations(this XRCameraSubsystem cameraSubsystem)
Parameters
Type | Name | Description |
---|---|---|
XRCameraSubsystem | cameraSubsystem | The |
Returns
Type | Description |
---|---|
CameraConfigurationCollection | A CameraConfigurationCollection, which allows you to enumerate the supported configurations. |
Examples
You can use Configurations(XRCameraSubsystem) in a foreach
statement:
foreach (var config in cameraSubsystem.Configurations())
Debug.Log(config);
GetCurrentConfiguration(XRCameraSubsystem)
Get the current CameraConfiguration. If camera configurations
are not supported, or if the session is not active, this method may throw
InvalidOperationException
.
Camera configurations are unsupported if
Declaration
public static CameraConfiguration GetCurrentConfiguration(this XRCameraSubsystem cameraSubsystem)
Parameters
Type | Name | Description |
---|---|---|
XRCameraSubsystem | cameraSubsystem | The |
Returns
Type | Description |
---|---|
CameraConfiguration | The currently active CameraConfiguration. |
GetNativePtr(XRCameraSubsystem)
Retrieve a native IntPtr
associated with the XRCameraSubsystem
.
Declaration
public static IntPtr GetNativePtr(this XRCameraSubsystem cameraSubsystem)
Parameters
Type | Name | Description |
---|---|---|
XRCameraSubsystem | cameraSubsystem | The |
Returns
Type | Description |
---|---|
IntPtr | An |
IsPermissionGranted(XRCameraSubsystem)
Allows you to determine whether camera permission has been granted.
Declaration
public static bool IsPermissionGranted(this XRCameraSubsystem cameraSubsystem)
Parameters
Type | Name | Description |
---|---|---|
XRCameraSubsystem | cameraSubsystem | The |
Returns
Type | Description |
---|---|
System.Boolean | True if camera permission has been granted for this app, false otherwise. |
RegisterCameraConfigApi(String, ICameraConfigApi)
Allows a camera provider to register support for ICameraConfigApi. This is typically only used by platform-specific packages.
Declaration
public static void RegisterCameraConfigApi(string subsystemId, ICameraConfigApi api)
Parameters
Type | Name | Description |
---|---|---|
System.String | subsystemId | The string name associated with the camera provider to extend. |
ICameraConfigApi | api | The API to use to perform provider-specific calls. |
RegisterCameraImageApi(String, ICameraImageApi)
Allows a camera provider to register support for ICameraImageApi. This is typically only used by platform-specific packages.
Declaration
public static void RegisterCameraImageApi(string subsystemId, ICameraImageApi api)
Parameters
Type | Name | Description |
---|---|---|
System.String | subsystemId | The string name associated with the camera provider to extend. |
ICameraImageApi | api | The API to use to perform provider-specific calls. |
RegisterGetNativePtrHandler(String, Func<XRCameraSubsystem, IntPtr>)
For internal use. Allows a camera provider to register for the GetNativePtr extension.
Declaration
public static void RegisterGetNativePtrHandler(string subsystemId, Func<XRCameraSubsystem, IntPtr> handler)
Parameters
Type | Name | Description |
---|---|---|
System.String | subsystemId | The string name associated with the camera provider to extend. |
Func<XRCameraSubsystem, IntPtr> | handler | A method that returns an |
RegisterIsPermissionGrantedHandler(String, Func<XRCameraSubsystem, Boolean>)
For internal use. Allows a camera provider to register for the IsPermissionGranted extension.
Declaration
public static void RegisterIsPermissionGrantedHandler(string subsystemId, Func<XRCameraSubsystem, bool> handler)
Parameters
Type | Name | Description |
---|---|---|
System.String | subsystemId | The string name associated with the camera provider to extend. |
Func<XRCameraSubsystem, System.Boolean> | handler | A method that returns true if permission is granted. |
RegisterTryGetColorCorrectionHandler(String, XRCameraExtensions.TryGetColorCorrectionDelegate)
For internal use. Allows a camera provider to register for the TryGetColorCorrection extension.
Declaration
public static void RegisterTryGetColorCorrectionHandler(string subsystemId, XRCameraExtensions.TryGetColorCorrectionDelegate handler)
Parameters
Type | Name | Description |
---|---|---|
System.String | subsystemId | The string name associated with the camera provider to extend. |
XRCameraExtensions.TryGetColorCorrectionDelegate | handler | A method that returns true if color correction is available. |
RegisterTryGetIntrinsicsHandler(String, XRCameraExtensions.TryGetIntrinsicsDelegate)
Allows a camera provider to register support for TryGetIntrinsics(XRCameraSubsystem, out CameraIntrinsics). This is typically only used by platform-specific packages.
Declaration
public static void RegisterTryGetIntrinsicsHandler(string subsystemId, XRCameraExtensions.TryGetIntrinsicsDelegate handler)
Parameters
Type | Name | Description |
---|---|---|
System.String | subsystemId | The string name associated with the camera provider to extend. |
XRCameraExtensions.TryGetIntrinsicsDelegate | handler | A method to get the camera intriniscs that should return |
RegisterTrySetFocusModeHandler(String, Func<XRCameraSubsystem, CameraFocusMode, Boolean>)
Allows a camera provider to register support for TrySetFocusMode(XRCameraSubsystem, CameraFocusMode). This is typically only used by platform-specific packages.
Declaration
public static void RegisterTrySetFocusModeHandler(string subsystemId, Func<XRCameraSubsystem, CameraFocusMode, bool> handler)
Parameters
Type | Name | Description |
---|---|---|
System.String | subsystemId | The string name associated with the camera provider to extend. |
Func<XRCameraSubsystem, CameraFocusMode, System.Boolean> | handler | A method to set whether auto focus is enabled and returns |
SetCurrentConfiguration(XRCameraSubsystem, CameraConfiguration)
Set a CameraConfiguration to be the active one. Throws if the camera configuration is not supported by the device. You can enumerate the available configurations with Configurations(XRCameraSubsystem).
The camera image configuration affects the resolution of the CameraImage provided by TryGetLatestImage(XRCameraSubsystem, out CameraImage). It may also affect the camera framerate. See framerate.
Setting this value may cause the device to relocalize, similar to stopping and restarting the session.
All CameraImages should be disposed and all asynchronous conversion operations
completed prior to setting the configuration or the this method may throw
InvalidOperationException
, depending on the platform.
Declaration
public static void SetCurrentConfiguration(this XRCameraSubsystem cameraSubsystem, CameraConfiguration configuration)
Parameters
Type | Name | Description |
---|---|---|
XRCameraSubsystem | cameraSubsystem | The |
CameraConfiguration | configuration | A configuration to use. This is typically one of the
configurations returned by |
TryGetColorCorrection(XRCameraSubsystem, out Color)
Attempts to retrieve color correction data for the extended XRCameraSubsystem
.
The color correction data represents the scaling factors used for color correction.
The RGB scale factors are used to match the color of the light
in the scene. The alpha channel value is platform-specific.
Declaration
public static bool TryGetColorCorrection(this XRCameraSubsystem cameraSubsystem, out Color color)
Parameters
Type | Name | Description |
---|---|---|
XRCameraSubsystem | cameraSubsystem | The |
Color | color | The |
Returns
Type | Description |
---|---|
System.Boolean |
|
TryGetIntrinsics(XRCameraSubsystem, out CameraIntrinsics)
Attempt to get the hardware camera's intrinsics. Intrinsics describe physical characteristics of a camera, which may be necessary to perform computer vision algorithms or other processing.
Declaration
public static bool TryGetIntrinsics(this XRCameraSubsystem cameraSubsystem, out CameraIntrinsics cameraIntrinsics)
Parameters
Type | Name | Description |
---|---|---|
XRCameraSubsystem | cameraSubsystem | The |
CameraIntrinsics | cameraIntrinsics | If this method returns |
Returns
Type | Description |
---|---|
System.Boolean |
|
TryGetLatestImage(XRCameraSubsystem, out CameraImage)
Attempt to get the latest camera image. This provides directly access to the raw pixel data, as well as utilities to convert to RGB and Grayscale formats. The CameraImage must be disposed to avoid resource leaks.
Declaration
public static bool TryGetLatestImage(this XRCameraSubsystem cameraSubsystem, out CameraImage cameraImage)
Parameters
Type | Name | Description |
---|---|---|
XRCameraSubsystem | cameraSubsystem | The |
CameraImage | cameraImage | A valid CameraImage if this method returns |
Returns
Type | Description |
---|---|
System.Boolean |
|
TrySetFocusMode(XRCameraSubsystem, CameraFocusMode)
Attempt to set the CameraFocusMode.
Declaration
public static bool TrySetFocusMode(this XRCameraSubsystem cameraSubsystem, CameraFocusMode mode)
Parameters
Type | Name | Description |
---|---|---|
XRCameraSubsystem | cameraSubsystem | The |
CameraFocusMode | mode | The CameraFocusMode to use. |
Returns
Type | Description |
---|---|
System.Boolean |
|