Skip to content

SingularityManager Component

ls0955 edited this page Jan 10, 2023 · 5 revisions

Reference: SingularityManager

The SingularityManager is the most important component exposed to you in the singularity. It acts as the interface between C# code in Unity, and Java/Kotlin code in the base android layer that actually runs the Bluetooth communication.

It's a monobehavior script, which means you can add it to a Unity GameObject as you would any other Unity script.

UnityEvents

It exposes three UnityEvents:

  • onConnected(), called when the SingularityManager successfully connects to a device.
  • onMessageRecieved(string message), called when the headset receives a message from a connected Bluetooth device
  • onError(string errorMessage), called when an error occurs

You can connect these UnityEvents to call methods in your own scripts through the inspector.

Public Methods

The SingularityManager has these public methods:

  • public List<DeviceSignature> GetPairedDevices()
  • public void ConnectToDevice(DeviceSignature sig)
  • public void sendMessage(string message, DeviceSignature sig)
  • public void DisconnectDevice(DeviceSignature sig)
  • public void DisconnectAll()

Method: List<DeviceSignature> GetPairedDevices()

Returns a List of all the DeviceSignatures that are paired (but not necessarily connected) to the VR headset. Useful if you are trying to make a GUI to choose a device to connect to.

Arguments: None.


Method void ConnectToDevice(DeviceSignature sig)

Attempts a connection with the device specified. If succeeds, will invoke onConnected() and start listening for messages. If fails, will invoke onError(string errorMessage).

Arguments:

  • DeviceSignature sig: the signature of the paired device you want to connect to.

Method: void sendMessage(string message, DeviceSignature sig)

Attempts to send a message over Bluetooth to the specified connected device.

Arguments:

  • DeviceSignature sig: the signature of the connected device you want to send a message to.
  • string message: The message to send to the device.

Method: void DisconnectDevice(DeviceSignature sig)

Disconnects from the specified connected device.

Arguments

  • DeviceSignature sig: the signature of the connected device you want to disconnect from.

Method: void DisconnectAll()

Disconnects from all connected devices.

Arguments: None