Table of Contents

Class CameraDevice

A wrapper for a native Camera2 CameraDevice.

public class CameraDevice : MonoBehaviour
Inheritance
object
CameraDevice

Fields

OnDeviceClosed

Invoked when the CameraDevice is closed.

public UnityEvent OnDeviceClosed

Field Value

UnityEvent

OnDeviceDisconnected

Invoked when the CameraDevice is disconnected.

public UnityEvent OnDeviceDisconnected

Field Value

UnityEvent

OnDeviceErred

Invoked when the CameraDevice encounters an error.

public UnityEvent<CameraDevice.ErrorCode> OnDeviceErred

Field Value

UnityEvent<ErrorCode>

OnDeviceOpened

Invoked when the CameraDevice is opened.

public UnityEvent OnDeviceOpened

Field Value

UnityEvent

Properties

CameraId

The ID of the camera being wrapped.

public string CameraId { get; }

Property Value

string

CurrentState

The current assumed state of the native CameraDevice wrapper.

public NativeWrapperState CurrentState { get; }

Property Value

NativeWrapperState

IsActiveAndUsable

Is the native CameraDevice wrapper active and usable?

public bool IsActiveAndUsable { get; }

Property Value

bool

Methods

CreateContinuousCaptureSession(Resolution, CaptureTemplate)

Creates a new repeating/continuous capture session for use.

public CaptureSessionObject<ContinuousCaptureSession> CreateContinuousCaptureSession(Resolution resolution, CaptureTemplate captureTemplate = CaptureTemplate.Preview)

Parameters

resolution Resolution

The resolution of the capture.

captureTemplate CaptureTemplate

The capture template to use for the capture

Returns

CaptureSessionObject<ContinuousCaptureSession>

A new capture session wrapper. May be null if the current camera device is not usable.

Remarks

Once you have finished using the capture session, call Destroy() to close the session and free up native and compute shader resources.

CreateOnDemandCaptureSession(Resolution)

Creates a new on-demand capture session for use.

public CaptureSessionObject<OnDemandCaptureSession> CreateOnDemandCaptureSession(Resolution resolution)

Parameters

resolution Resolution

The resolution of the capture.

Returns

CaptureSessionObject<OnDemandCaptureSession>

A new capture session wrapper. May be null if the current camera device is not usable.

Remarks

Once you have finished using the capture session, call Destroy() to close the session and free up native and compute shader resources.

CreateOnDemandSurfaceTextureCaptureSession(Resolution, CaptureTemplate)

Creates a new on-demand OpenGL SurfaceTexture based capture session for use. Equivalent to OnDemandCaptureSession.

public OnDemandSurfaceTextureCaptureSession CreateOnDemandSurfaceTextureCaptureSession(Resolution resolution, CaptureTemplate captureTemplate = CaptureTemplate.Preview)

Parameters

resolution Resolution

The resolution of the capture.

captureTemplate CaptureTemplate

The capture template to use for the capture

Returns

OnDemandSurfaceTextureCaptureSession

A new capture session wrapper. May be null if the current camera device is not usable.

Remarks

This is an experimental capture session type that uses a native OpenGL texture to capture images for better performance.

The results of this capture session may be more noisy compared to OnDemandCaptureSession. Requires OpenGL ES 3.0 or higher as the project's Graphics API. Works with single and multi-threaded rendering.

CreateSurfaceTextureCaptureSession(Resolution, CaptureTemplate)

Creates a new OpenGL SurfaceTexture based capture session for use. Equivalent to ContinuousCaptureSession.

public SurfaceTextureCaptureSession CreateSurfaceTextureCaptureSession(Resolution resolution, CaptureTemplate captureTemplate = CaptureTemplate.Preview)

Parameters

resolution Resolution

The resolution of the capture.

captureTemplate CaptureTemplate

The capture template to use for the capture

Returns

SurfaceTextureCaptureSession

A new capture session wrapper. May be null if the current camera device is not usable.

Remarks

This is an experimental capture session type that uses a native OpenGL texture to capture images for better performance.

The results of this capture session may be more noisy compared to ContinuousCaptureSession. Requires OpenGL ES 3.0 or higher as the project's Graphics API. Works with single and multi-threaded rendering.

Destroy()

Releases the CameraDevice's native resources, and destroys its GameObject.

public void Destroy()

OnDestroy()

protected void OnDestroy()

Release()

Releases the CameraDevice's native resources, and makes it unusable.

public void Release()

WaitForInitialization()

Waits until the CameraDevice is open or erred out.

public IEnumerator WaitForInitialization()

Returns

IEnumerator

WaitForInitializationAsync()

Waits until the CameraDevice is open or erred out.

public Awaitable<NativeWrapperState> WaitForInitializationAsync()

Returns

Awaitable<NativeWrapperState>

The current state of the CameraDevice.

Remarks

Requires Unity 6.0 or higher.

_onDeviceClosed(string)

public void _onDeviceClosed(string _)

Parameters

_ string

_onDeviceDisconnected(string)

public void _onDeviceDisconnected(string _)

Parameters

_ string

_onDeviceErred(string)

public void _onDeviceErred(string errorCodeStr)

Parameters

errorCodeStr string

_onDeviceOpened(string)

public void _onDeviceOpened(string _)

Parameters

_ string