Microtube Docs
Developers / API reference / Unity (C#)

Unity (C#)

The C# API for driving HEXR from Unity, as shipped in the com.microtube.hexr package.

Namespaces

Two namespaces matter. HexR holds the Unity components you add to scene objects; HaptGlove holds the low-level glove runtime, including the Haptics.Finger enum every actuation call takes.

PressureTrackerMain

The per-hand haptics controller. One lives on each Pressure Controller that HexR → Create HexR Rig drops into the scene — a left and a right. This is the class to call when you want direct control rather than physics-driven feedback.

CustomSingleHaptics(finger, states, targetPressure, speed, byPassHandCheck)

Steady pressure on one finger.

ArgumentTypeDescription
fingerHaptics.FingerThumb, Index, Middle, Ring, Pinky, Palm
statesbooltrue applies pressure, false releases it
targetPressurefloat 0.1–1How hard — 0.1 is barely there, 1 is maximum
speedfloat 0.1–1How fast it ramps to that pressure
byPassHandCheckbooltrue fires without checking whether a hand is near

CustomSingleVibrations(finger, states, targetPressure, frequency, byPassHandCheck)

Vibration on one finger. Same arguments, except frequency (0.1–40) replaces speed.

Whole-hand calls

MethodWhat it does
TriggerAllHapticsIncrease(float)Pressure on every channel at once
TriggerCustomHapticsIncrease(bool[], float, float)Pressure on a chosen subset of channels
TriggerAllVibrations(float)Vibration on every channel
TriggerCustomlVibrations(bool[], float, float)Vibration on a chosen subset
TriggerPinchPressure(float) / RemovePinchPressure()Thumb-and-index pinch pressure
RemoveAllHaptics() / RemoveAllVibrations()Clear everything

Per-finger shorthands

SingleThumbHaptic(float), SingleIndexHaptic, SingleMiddleHaptic, SingleRingHaptic, SinglePinkyHaptic, SinglePalmHaptic, each with a matching Remove…Haptics(). Convenient for wiring straight into a UnityEvent in the inspector, since they take a single float.

IsHandNear()

Whether HEXR currently believes this hand is near something touchable. Every actuation call is gated on it unless you pass byPassHandCheck: true. It ORs three flags — grab-interactor hover, poke-interactor hover, and a ProximityCheck trigger volume — and on OpenXR only the last one is ever set.

Hand-near gating

Every actuation is gated on IsHandNear() unless you pass byPassHandCheck: true. If your calls appear to do nothing on OpenXR, the usual cause is a missing ProximityCheck on the object, not the hardware — see Make objects feel touchable.

HexRManager

Scene-level wiring and the Bluetooth connection flow. Reachable anywhere through the static HexRManager.Instance.

MemberDescription
ConnectLeftBT() / ConnectRightBT()Start the BLE connection for that hand. Safe to wire to a UI button
leftHand / rightHandThe underlying HaptGloveHandler for each hand
XRFrameworkWhich backend this scene targets — OpenXR or MetaOVR
FingertipColliderRadius, PalmColliderSizeSize of the generated touch colliders
RebindHandsToCurrentScene()Re-resolve hand references after a scene load

Scene components

Most projects never call the API directly — these components fire haptics from physics and events on their own.

HexRGrabbable

Makes an object pickable by the HEXR hands. Needs a Collider (trigger) and a Rigidbody on the same GameObject.

FieldDescription
TypeOfGrabPalmGrab needs the palm plus one finger; PinchGrab needs the thumb plus one finger
GravityWhether gravity acts on the object once released
HapticStrengthFeedback strength while held
TheObjectOptional — separates the grab zone from the object that actually moves
OnGrab / OnReleaseUnityEvents

SpecialHaptics

Turns a trigger collider into a haptic zone. Set TypeOfHaptics to one of:

EffectFeels like
CustomHapticsConstant pressure while touched — HapticPressure sets the strength
CustomVibrationsVibration — VibrationsFrequencyValue and HapticStrenngthValue
FountainEffectRunning water
RainDropEffectRaindrops, randomly triggered
HeartBeatEffectA beating heart — InTimer, OutTimer, regular or irregular
HandSqueezeEffectFires OnSqueezeEventTrigger when the hand closes past SqueezeTightness

HexRUsable

Fires WhenUseTriggerEvents once the fingers you marked Needed curl past UseThreshold, and WhenStopUsingTriggerEvents when they relax. Use it for triggers, handles and grips.

ProximityCheck

A trigger volume that tells HEXR a hand is near this object. Required on OpenXR — it is the only thing that sets the hand-near flag on that backend. Press Auto Set Up in its inspector to wire both Pressure Controllers.

HapticFingerTrigger

Sits on each fingertip and palm collider of the HEXR rig; Auto Setup Scene places these for you. Exposes TriggerFixPressure(float), TriggerVibrationPressure(float, float), RemoveVibration() and RemoveHaptics() if you need to drive one directly.

Example

A haptic zone that pulses the index finger on contact, then retunes a heartbeat effect when squeezed — the pattern the Tutorial Content sample uses:

csharp
using UnityEngine;
using HaptGlove;
using HexR;

public class TouchPulse : MonoBehaviour
{
    public PressureTrackerMain hand;        // Left or Right Pressure Controller
    public SpecialHaptics heartbeat;        // optional, a SpecialHaptics zone

    void OnTriggerEnter(Collider other)
    {
        // finger, on, intensity 0.1-1, ramp speed 0.1-1, bypass the hand-near check
        hand.CustomSingleHaptics(Haptics.Finger.Index, true, 0.8f, 1f, false);
    }

    void OnTriggerExit(Collider other)
    {
        hand.CustomSingleHaptics(Haptics.Finger.Index, false, 0f, 1f, false);
    }

    // Hook this to a HexRGrabbable OnGrab event
    public void OnSqueeze()
    {
        heartbeat.InTimer = 0.2f;
        heartbeat.OutTimer = 0.2f;
        heartbeat.HapticStrenngthValue = 0.5f;
    }
}
Scope

This reference covers the components in com.microtube.hexr v0.4.0. The lower-level HaptGloveHandler API — BTConnection(), GetAirPressure(), GetBatteryLevel(), HEXRPressure(), HEXRVibration() — is documented in the tutorial repository.