Skip to main content
Version: 2.2.0

Haply::Inverse::Unity::DeviceBehaviour

Represents the base class for Inverse devices, providing common functionality and state management.

Inherits from MonoBehaviour

Inherited by Haply.Inverse.Unity.Inverse3, Haply.Inverse.Unity.VerseGrip

Public Events

Name
Action< DeviceBehaviour, Ret >ErrorEvent()
ConnectionStateDelegateConnectionStateChanged()
Event triggered when the device connection state changes.
Action< DeviceBehaviour, DeviceConnectionState, DeviceConnectionState >ConnectionStateChangedAsync()
Event triggered shortly after the device connection state changes.

Public Functions

Name
delegate voidConnectionStateDelegate(DeviceBehaviour device, DeviceConnectionState state, DeviceConnectionState prevState)
Delegate for handling connection state changes of the device.
voidSetSetupToPerform()
Indicate to perform setup on next frame.
override stringToString()
Returns a string representation of the object, providing a human-readable description that includes the object's name, class type, and device ID.

Protected Functions

Name
voidInvokeReadyEvent()
Invokes the Ready event.
virtual voidSetup()
This method is automatically called once the _performSetup flag is set to handle consuming calculations too heavy to be called on each frame.
virtual voidAwake()
voidOnEnable()
voidOnDisable()
voidOnDestroy()
virtual voidFixedUpdate()

Public Properties

Name
DeviceTypeDeviceType
Gets the type of the device.
intSelectedDeviceId
uintDeviceId
Gets the device ID.
boolIsReady
Indicates whether the device is ready for use.
CursorBehaviourCursor
Gets or sets the CursorBehaviour associated with the device.
DeviceConnectionStateConnectionState
Gets or sets the current connection state of the device.
boolIsConnected
Gets whether the device is connected.
boolIsOpened
Gets whether the device is opened.

Protected Properties

Name
BaseCoordinateConverterCoordinateConverter
boolIsCursorSet
Indicates whether the Cursor has been set.

Public Attributes

Name
const intANY_ID
UnityEvent< DeviceBehaviour >DeviceOpened
Event triggered when the ConnectionState transitions to the DeviceConnectionState.Opened state.
UnityEvent< DeviceBehaviour >DeviceClosed
Event triggered when the ConnectionState transitions to the DeviceConnectionState.Connected state.

Protected Attributes

Name
string_objectName

Public Events Documentation

event ErrorEvent

Action< DeviceBehaviour, Ret > ErrorEvent()

event ConnectionStateChanged

ConnectionStateDelegate ConnectionStateChanged()

Event triggered when the device connection state changes.

event ConnectionStateChangedAsync

Action< DeviceBehaviour, DeviceConnectionState, DeviceConnectionState > ConnectionStateChangedAsync()

Event triggered shortly after the device connection state changes.

See: ConnectionStateChanged

This event is dispatched on the main thread, allowing for safe interactions with Unity scene objects and UI elements. Note that the device state is updated on a separate high-frequency thread, so the state at the time of the event might differ slightly from the current state when handling the event. Use the ConnectionStateChanged event if you need more precision.

Public Functions Documentation

function ConnectionStateDelegate

delegate void ConnectionStateDelegate(
DeviceBehaviour device,
DeviceConnectionState state,
DeviceConnectionState prevState
)

Delegate for handling connection state changes of the device.

Parameters:

  • state The new state of the device.
  • prevState The previous state of the device.
  • device The device instance raising the event.

function SetSetupToPerform

void SetSetupToPerform()

Indicate to perform setup on next frame.

See: Setup

function ToString

override string ToString()

Returns a string representation of the object, providing a human-readable description that includes the object's name, class type, and device ID.

Return: A string that represents the current object, including its name, class type, and device ID.

The returned string follows the format: "name <Class>(#id)", where:

  • "name" is the value of the object's _objectName field.
  • "Class" is the name of the object's class type.
  • "id" is the device ID, formatted as a 4-character hexadecimal string, or "*" if the device ID is ANY_ID. If DeviceId is ANY_ID, the value of SelectedDeviceId is used.

This method helps in debugging and logging by providing a concise and informative description of the object.

Protected Functions Documentation

function InvokeReadyEvent

void InvokeReadyEvent()

Invokes the Ready event.

This method is automatically called by the IsReady property when the value changes to true. It must be implemented by derived classes to trigger the corresponding event.

The IsReady property must be set to true in derived classes when the device is fully initialized and ready for use.

function Setup

virtual void Setup()

This method is automatically called once the _performSetup flag is set to handle consuming calculations too heavy to be called on each frame.

Reimplemented by: Haply::Inverse::Unity::Inverse3::Setup

This method can be override with taking care to keep base call. Use SetSetupToPerform to trigger Setup call.

function Awake

virtual void Awake()

function OnEnable

void OnEnable()

function OnDisable

void OnDisable()

function OnDestroy

void OnDestroy()

function FixedUpdate

virtual void FixedUpdate()

Reimplemented by: Haply::Inverse::Unity::Inverse3::FixedUpdate

Public Property Documentation

property DeviceType

DeviceType DeviceType;

Gets the type of the device.

Can be Inverse.DeviceType.Inverse3, Inverse.DeviceType.VerseGrip or Inverse.DeviceType.Nil if not already set by the DeviceMapper.

property SelectedDeviceId

int SelectedDeviceId;

property DeviceId

uint DeviceId;

Gets the device ID.

property IsReady

bool IsReady;

Indicates whether the device is ready for use.

property Cursor

CursorBehaviour Cursor;

Gets or sets the CursorBehaviour associated with the device.

property ConnectionState

DeviceConnectionState ConnectionState;

Gets or sets the current connection state of the device.

The device can be in either DeviceConnectionState.Disconnected, DeviceConnectionState.Connected or DeviceConnectionState.Opened state. Changing the state triggers the corresponding events and state change notifications.

property IsConnected

bool IsConnected;

Gets whether the device is connected.

property IsOpened

bool IsOpened;

Gets whether the device is opened.

Protected Property Documentation

property CoordinateConverter

BaseCoordinateConverter CoordinateConverter;

property IsCursorSet

bool IsCursorSet;

Indicates whether the Cursor has been set.

This property helps in optimizing checks for the Cursor's existence, as direct comparisons with null can be expensive in Unity.

Public Attributes Documentation

variable ANY_ID

static const int ANY_ID = 0;

variable DeviceOpened

UnityEvent< DeviceBehaviour > DeviceOpened;

Event triggered when the ConnectionState transitions to the DeviceConnectionState.Opened state.

See: ConnectionStateChanged

This indicates that the device is ready for use, with all necessary data, such as DeviceId and Inverse3.Handedness, correctly initialized. Depending on the DeviceType, the DeviceBehaviour instance passed as the first argument can be cast to the corresponding type, either Inverse3 or VerseGrip.

This event is dispatched on the main thread, allowing for safe interactions with Unity scene objects and UI elements. Note that the device state is updated on a separate high-frequency thread, so the state at the time of the event might differ slightly from the current state when handling the event. Use the ConnectionStateChanged event if you need more precision.

variable DeviceClosed

UnityEvent< DeviceBehaviour > DeviceClosed;

Event triggered when the ConnectionState transitions to the DeviceConnectionState.Connected state.

See: ConnectionStateChanged

This indicates that the device is not ready to use anymore. Depending on the DeviceType, the DeviceBehaviour instance passed as the first argument can be cast to the corresponding type, either Inverse3 or VerseGrip.

This event is dispatched on the main thread, allowing for safe interactions with Unity scene objects and UI elements. Note that the device state is updated on a separate high-frequency thread, so the state at the time of the event might differ slightly from the current state when handling the event. Use the ConnectionStateChanged event if you need more precision.

Protected Attributes Documentation

variable _objectName

string _objectName;