Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The VictoR SDK prefab makes use of the libraries contained in the Plugins folder to communicate with a VictoR device, through the attached VictorController script. The libraries used are determined by the platform the project has been set to. Currently, Universal Windows platform and Android are supported. The VictorController script also serves as an example on how to use the Victor SDK for both platforms. It’s primary function is to use the appropriate device manager (Windows or Android SDK), dependent on the platform the application is running on. Once the appropriate device manager is instantiated, calls to Scan, Connect, Read/Write, and Subscribe/Unsubscribe can be made through the VictorController. The following will walk through how the Windows and Android DeviceManagers are handled through a Unity project.

...

In order to scan for devices using the Android SDK from within a Unity project, users must first create an AndroidJavaObject representing the Java SDK’s VictorBleDeviceManager. In the example script, this is done inside the constructor. Once the device manager object has been created, the actual scan method is able to use the AndroidJavaObject to call the “scanForDevices” method. As this is a CompletableFuture on the Java side, this call can be called from within is made inside of a Task on the C# side. An important item to note is that in order to properly call this function, users must first attach the current thread to a Java VM. Remember that the Unity package contains a VictorAndroidBLEDeviceManager script that has performed this binding already for the user.

...

Callbacks when using the Android SDK requires not only a binding to the underlying Java call, but also defining the Callback abstract class in the Android SDK. Once again, the VictorAndroidBLEDeviceManager provides an example for how both of these are handled. First, the VictorDeviceCallback in the Android SDK is defined on the C# side. In the provided example, the VictorEventHandler and VictorEventHandlerMap in the Windows SDK is leveraged to manage passed in events.

...

With both items defined, users can define create their own Event to pass to the VictorAndroidBLEDeviceManager to be notified of attribute changes (for attributes that have the Notify flag enabled), connection state events, and device found events. It is important to remember that these callbacks will occur in a separate thread and should be especially noted if working on Unity Gameobjects that rely on these callbacks for modifications, as many operations on Unity Gameobjects can only be done on the main thread.

UI Prefabs

The UI prefab consists of a collection of controls that allow for scanning for devices, connecting/disconnecting to/from the device, and reading/writing to the device.

...

Additionally, a Log prefab is used by the VictorUIManager script to print out a number of informational, warning, and error logs in the scroll view of the UI. Any reads made on the device will be printed out in the scroll view, as well as notifications of the state of a scan, connect, or disconnect call.

...

Building The Unity Project

...

Below lists the settings used to build and run a an Android project in Unity when using the Victor SDK package. It is important to note that a device plugged into the development machine has been detected and will be the target device the application runs on once the build succeeds and deploys to the device.

...