Class XRCameraSubsystem
Provides access to a device's camera.
Namespace: UnityEngine.XR.ARSubsystems
Syntax
public abstract class XRCameraSubsystem : Subsystem<XRCameraSubsystemDescriptor>
Remarks
The XRCameraSubsystem
links a Unity Camera
to a device camera for video overlay (pass-thru
rendering). It also allows developers to query for environmental light estimation, when available.
Constructors
XRCameraSubsystem()
Construct the XRCameraSubsystem
.
Declaration
public XRCameraSubsystem()
Properties
currentConfiguration
The current camera configuration.
Declaration
public virtual XRCameraConfiguration? currentConfiguration { get; set; }
Property Value
Type | Description |
---|---|
Nullable<XRCameraConfiguration> | The current camera configuration if it exists. Otherise, |
focusMode
Specifies the focus mode for the camera.
Declaration
public CameraFocusMode focusMode { get; set; }
Property Value
Type | Description |
---|---|
CameraFocusMode | The focus mode for the camera. |
invertCulling
Whether to invert the culling mode during rendering. Some front-facing camera modes may require this.
Declaration
public bool invertCulling { get; }
Property Value
Type | Description |
---|---|
Boolean |
lightEstimationMode
Specifies the light estimation mode.
Declaration
public LightEstimationMode lightEstimationMode { get; set; }
Property Value
Type | Description |
---|---|
LightEstimationMode | The light estimation mode. |
permissionGranted
Determines whether camera permission has been granted.
Declaration
public bool permissionGranted { get; }
Property Value
Type | Description |
---|---|
Boolean |
|
running
Indicates whether this subsystem is running (i.e., Start() has been called).
Declaration
public bool running { get; }
Property Value
Type | Description |
---|---|
Boolean |
|
shaderName
The shader name used to render the camera texture.
Declaration
public string shaderName { get; }
Property Value
Type | Description |
---|---|
String | The shader name used to render the camera texture. |
Methods
CreateProvider()
Method for the implementation to create the camera functionality provider.
Declaration
protected abstract XRCameraSubsystem.IProvider CreateProvider()
Returns
Type | Description |
---|---|
XRCameraSubsystem.IProvider | The camera functionality provider. |
Destroy()
Destroy the camera subsystem.
Declaration
public sealed override void Destroy()
GetConfigurations(Allocator)
Queries for the supported camera configurations.
Declaration
public NativeArray<XRCameraConfiguration> GetConfigurations(Allocator allocator)
Parameters
Type | Name | Description |
---|---|---|
Allocator | allocator | The allocation strategy to use for the returned data. |
Returns
Type | Description |
---|---|
NativeArray<XRCameraConfiguration> | The supported camera configurations. |
GetTextureDescriptors(Allocator)
Gets the XRTextureDescriptors associated with the
current frame. The caller owns the returned NativeArray
and is responsible for calling Dispose
on it.
Declaration
public NativeArray<XRTextureDescriptor> GetTextureDescriptors(Allocator allocator)
Parameters
Type | Name | Description |
---|---|---|
Allocator | allocator | The allocator to use when creating
the returned |
Returns
Type | Description |
---|---|
NativeArray<XRTextureDescriptor> | An array of texture descriptors. |
Register(XRCameraSubsystemCinfo)
Registers a camera subsystem implementation based on the given subsystem parameters.
Declaration
public static bool Register(XRCameraSubsystemCinfo cameraSubsystemParams)
Parameters
Type | Name | Description |
---|---|---|
XRCameraSubsystemCinfo | cameraSubsystemParams | The parameters defining the camera subsystem functionality implemented by the subsystem provider. |
Returns
Type | Description |
---|---|
Boolean |
|
Start()
Start the camera subsystem.
Declaration
public sealed override void Start()
Stop()
Stop the camera subsystem.
Declaration
public sealed override void Stop()
TryGetIntrinsics(out XRCameraIntrinsics)
Returns the camera intrinsics information.
Declaration
public bool TryGetIntrinsics(out XRCameraIntrinsics cameraIntrinsics)
Parameters
Type | Name | Description |
---|---|---|
XRCameraIntrinsics | cameraIntrinsics | The camera intrinsics information returned from the method. |
Returns
Type | Description |
---|---|
Boolean |
|
Remarks
Note
The intrinsics may change each frame. You should call this each frame that you need intrinsics in order to ensure you are using the intrinsics for the current frame.
TryGetLatestFrame(XRCameraParams, out XRCameraFrame)
Get the latest frame from the provider.
Declaration
public bool TryGetLatestFrame(XRCameraParams cameraParams, out XRCameraFrame frame)
Parameters
Type | Name | Description |
---|---|---|
XRCameraParams | cameraParams | The Unity |
XRCameraFrame | frame | The camera frame to be populated if the subsystem is running and successfully provides the latest camera frame. |
Returns
Type | Description |
---|---|
Boolean |
|
TryGetLatestImage(out XRCameraImage)
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.
Note
Starting November 2022, this method will always return false
and not acquire a camera image on
Android platforms due to API deprecation in ARCore SDK. Update to package version 4.x or higher to use
supported version of the API. See https://developers.google.com/ar/develop/unity-arf/ndk-camera-deprecation.
This methods will not be affected on iOS platforms and will continue to work same as before.
Declaration
public bool TryGetLatestImage(out XRCameraImage cameraImage)
Parameters
Type | Name | Description |
---|---|---|
XRCameraImage | cameraImage | A valid XRCameraImage if this method returns |
Returns
Type | Description |
---|---|
Boolean |
|
Remarks
The returned XRCameraImage must be disposed to avoid resource leaks.