# Unity

Hapticlabs Studio directly interfaces with Unity through its TCP port, and you can also connect Unity directly to the satellite after uploading tracks. To ease the setup and usage of these connections, we created a Unity package, available

Download package
https://github.com/HapticlabsIO/UnityHapticlabsController

Learn about protocols:

TCP port
../../api/tcp-port/
Upload tracks
../../settingspanel/externaltrigger/


# Setup

# Installation

  1. Download the Hapticlabs Unity package
    Download package
    https://github.com/HapticlabsIO/UnityHapticlabsController
  2. Within your Unity scene, import the downloaded folder, for example into your "Assets" folder.
  3. Within your Unity scene, drag the "Hapticlabs Manager.prefab" into your scene.
  4. Done! Now you can start configuring your connection.

# Configuration

It is not recommended to change any settings of the Hapticlabs Manager except the Hapticlabs (Script) configuration.

There, you have a few options:

Use TCP
By ticking this box, Unity will connect to Hapticlabs Studio when the scene is running. This allows you to access all the tracks in your currently opened projects.
Use Serial
By ticking this box, Unity will connect to a Hapticlabs Satellite connected to your computer. This way, you can access all tracks that have been uploaded to the satellite..
If you choose to communicate this way, you need to ensure the satellite is not connected to Hapticlabs Studio because it can not connect to multiple programs at the same time.
Log Debug Infos
By ticking this box, you can enable the logs of the Hapticlabs Manager. These are primarily for debugging purposes.

# Usage

Once you have the connection properly set up, you can start including haptics in your Unity project!

For that, anywhere in your project you can call the following functions:

Hapticlabs.StartTrack(string trackName, bool queue=false, float amplitudeScale=1.0f);

With this command, you can start the track with the specified track name.

trackName
A string containing the name of a track in the currently opened project in Hapticlabs Studio or the name of a track that has been uploaded to the satellite.
queue
Whether to immediately play back the specified track (queue: false) or to wait for other tracks currently playing back to complete first (queue: true).
amplitudeScale
Adjust the intensity level of a track by scaling the amplitude

# Adjust intensity

Hapticlabs.SetAmplitudeScale(float amplitudeScale);

This command allows you to vary the intensity (amplitude) of the satellite output during the playback. The default value is 1.0, so you can reduce the intensity from its standard value by passing a scale value

Scaling Intensity
// Decrease the intensity value
Hapticlabs.SetAmplitudeScale(0.7);

// Incerasing the intensity value
Hapticlabs.SetAmplitudeScale(1.3);

// Reset the intensity value
Hapticlabs.SetAmplitudeScale(1.0);

# Stop playback

Hapticlabs.Stop();

With this command, you can terminate any haptic playback.