Skip to content

Repository files navigation

MobileHapticFeedback

📘 Read this document in other languages:

MobileHapticFeedback is a cross-platform haptic feedback library for Unity,
providing a unified API for iOS (Core Haptics / UIKit) and Android (VibrationEffect).

It allows you to use UIKit-style feedback, parameterized one-shot impacts, and waveform-based haptic patterns with a consistent programming model across platforms.

Features

  • iOS
    • Core Haptics–based impacts (CHHapticEngine)
    • UIKit-style feedback (Impact / Selection / Notification)
  • Android
    • VibrationEffect-based haptics (API 26+)
    • Envelope-based impacts / patterns with sharpness control (Android 16+, supported devices)
  • Unity
    • Unified cross-platform API
    • Safe no-op behavior when haptics are unavailable or muted

⚠️ Note (Android)
UIKit-style feedback and Core Haptics–like APIs are conceptually mapped to
the closest available vibration patterns supported by the platform.

Supported Platforms

  • iOS 15+
  • Android API 26+
  • Unity 6000.0 or later

Installation ( Unity Package Manager )

Add via Git URL:

https://github.com/tsyk5/MobileHapticFeedback.git?path=package/com.tsyk5.mobilehapticfeedback

To install a specific version, append a tag:

https://github.com/tsyk5/MobileHapticFeedback.git?path=package/com.tsyk5.mobilehapticfeedback#v0.5.0

Quick Start

UIKit-like APIs

MobileHapticFeedback.PlayImpact(ImpactStyle.Medium);
MobileHapticFeedback.PlaySelection();
MobileHapticFeedback.PlayNotification(NotificationType.Success);

These calls are safe to use without checking availability.

If haptics are unsupported or muted by OS/user settings, calls may simply do nothing.

Core Haptics-like API ( One-shot impact )

MobileHapticFeedback.Prepare();
MobileHapticFeedback.PlayImpact(intensity: 0.6f, sharpness: 0.3f, durationSec: 0.2);

MobileHapticFeedback.Stop();

Parameters

  • intensity (0..1): Strength of the haptic.
  • sharpness (0..1): Crispness / sharp edge of the haptic.
  • durationSec (sec): Duration of the haptic (clamped to 0.01-10s, see MinDurationSec / MaxDurationSec).

⚠️ Note (Android):
sharpness is honored only on Android 16+ devices that support envelope effects (VibrationEffect.BasicEnvelopeBuilder). On other devices the value is ignored.
Check MobileHapticFeedback.IsSharpnessSupported at runtime to adapt your UI.

Patterns API ( Waveform-style )

MobileHapticFeedback.Prepare();

// One PatternSegment = (durationSec, amplitude, sharpness = 0.5)
MobileHapticFeedback.PlayPattern(
    new PatternSegment(0.6f, 0.1f),
    new PatternSegment(0.15f, 0f),              // amplitude 0 = silence
    new PatternSegment(0.2f, 0.8f, sharpness: 0.9f)
);

Parameters

  • durationSec (sec): Duration of the segment.
  • amplitude (0..1): Strength of the segment. 0 means silence, 1 means maximum strength.
  • sharpness (0..1, optional): Crispness of the segment. Defaults to PatternSegment.DefaultSharpness (0.5). Honored where IsSharpnessSupported is true, ignored elsewhere.

PlayPattern(float[] durationsSec, float[] amplitudes) is deprecated since v0.4.0: the parallel arrays could get out of sync and fail silently.

Samples ( Sample01 )

The following patterns are available in the Sample01 scene.

After building the Sample01 scene, press the buttons in each section to test and experience the haptic feedback behavior on a real device.

⚠️
Haptics cannot be reproduced in the Unity Editor.Please run the sample on a physical device.

⭐️ Core Haptics-like API ( One-shot impact )

This section demonstrates a single, parameterized haptic impact.

Adjust the sliders and press “Play Impact” to trigger the haptic.

Press “Stop” at any time to interrupt playback, even during the duration.

⭐️ Patterns API ( Waveform-style )

Construct custom haptic patterns by combining explicit duration (time) and amplitude (strength) values.

All patterns can be interrupted at any time by pressing “Stop”.

SOS

Represents the Morse code SOS (… --- …) using haptics.

Short and long pulses are combined to form a clear emergency signal.

Heartbeat

A rhythmic pattern inspired by a human heartbeat.

Double pulses and pauses create a natural, biological rhythm.

StepUp

A pattern where haptic intensity gradually increases over time.

Useful for expressing buildup, progress, or emphasis.

⭐️ UIKit-like APIs

UIKit-style haptics follow Apple’s system-defined haptic behaviors.

These APIs provide standardized feedback patterns for common UI interactions, ensuring consistency across iOS applications.

For detailed design intent and official diagrams, please refer to Apple’s Human Interface Guidelines:

Apple – Human Interface Guidelines / Playing Haptics

License

MIT

About

Cross-platform haptics plugin for Unity (iOS & Android)

Topics

Resources

Stars

10 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages