Basic UI Example
This example is a basic “hello-world” example. In playmode, the device will automatically connect to any Skinetic device available, and update the connection status. Additionally, two buttons are displayed in the middle of the screen, pressing one of them triggers a predefined haptic effect on the vest on the front (or back) of the haptic device.
The scene is composed of a canvas with two buttons and a text and an empty gameobject SkineticBasicUIExample containing two gameobjects: one to handle the SkineticDevice
component and one to handle the HapticEffect
components.
Automatic connection
The connection is automatically performed by the SkiEx_AutoConnect script on the SkineticDevice
component. This script has a reference set in the inspector to the SkineticDevice
component and a Text on the canvas.
On the OnEnable event
A connection callback is set:
m_device.SetConnectionCallback(ConnectionCallback);
This callback will be called whenever the connection to the device is made or broken, and update the state string
m_connectString
. When the connection succeed, the serial number is passed as an argument to the callback, it can be converted to a formatted string using the staticSkinetic.SkineticDevice.SerialNumberToString
.A connection to any Skinetic device is requested by passing
Skinetic.SkineticDevice.OutputType.E_AUTODETECT
to allow any kind of connection and 0 to pick the first available device.Start a coroutine to update the connection status in the text field as the callback being called from another thread cannot update the UI itself.
During the OnDisable event
The disconnection routine is initiated and the function returns once the disconnection is completed.
Basic Effects
The HapticEffects gameobject contains 3 components:
two preconfigured
HapticEffect
components whose parameters are predefined in the inspector and hold references to theSkineticDevice
component in the scene and to thePatternAsset
ScriptableObject they have to use.a SkiEx_BasicUIEffects script which simply holds reference to the two
HapticEffect
and exposes 2 public functions registered in the inspector to each button’sOnClick()
event. These functions then callPlayEffect
from theHapticEffect
as the target device was set in the inspector.
Additionally, the two PatternAsset
ScriptableObjects are added to the preload list of the SkineticDevice
so there is no need to register them through scripting as they will be loaded right at the beginning.