{"id":14960675,"url":"https://github.com/mfdeveloper/vibration","last_synced_at":"2025-09-30T12:30:47.262Z","repository":{"id":142051437,"uuid":"268269411","full_name":"mfdeveloper/Vibration","owner":"mfdeveloper","description":"Use custom vibrations on mobile with this native Plugin for Unity (Android, iOS \u0026 WebGL)","archived":false,"fork":true,"pushed_at":"2024-02-15T14:33:49.000Z","size":462,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"upm-package-embedded","last_synced_at":"2024-09-27T23:20:54.205Z","etag":null,"topics":["unity","unity-android","unity-mobile","unity-plugin"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"BenoitFreslon/Vibration","license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mfdeveloper.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-05-31T11:50:59.000Z","updated_at":"2024-01-30T09:40:21.000Z","dependencies_parsed_at":"2023-10-04T13:50:10.107Z","dependency_job_id":null,"html_url":"https://github.com/mfdeveloper/Vibration","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mfdeveloper%2FVibration","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mfdeveloper%2FVibration/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mfdeveloper%2FVibration/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mfdeveloper%2FVibration/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mfdeveloper","download_url":"https://codeload.github.com/mfdeveloper/Vibration/tar.gz/refs/heads/upm-package-embedded","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234737799,"owners_count":18879179,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["unity","unity-android","unity-mobile","unity-plugin"],"created_at":"2024-09-24T13:22:43.481Z","updated_at":"2025-09-30T12:30:41.875Z","avatar_url":"https://github.com/mfdeveloper.png","language":"Kotlin","funding_links":["https://paypal.me/UnityVibrationPlugin"],"categories":[],"sub_categories":[],"readme":"# Vibration/Haptics: Unity Plugin\n\n\u003ch1 align=\"left\"\u003e\n    \u003cimg src=\"./Images/haptic-logo-color.png\"\u003e\n\u003c/h1\u003e\n\n[![openupm](https://img.shields.io/npm/v/com.benoitfreslon.vibration?label=openupm\u0026registry_uri=https://package.openupm.com)](https://openupm.com/packages/com.benoitfreslon.vibration/)\n\n\u003e**PS:** This is a fork of original Vibration package **[BenoitFreslon/Vibration](https://github.com/BenoitFreslon/Vibration)** to be published in [openupm](https://openupm.com) registry, while the changes aren't merged into it!\n\nNative **free** plugin for Unity for Android, iOS and [WebGL](https://caniuse.com/webgl2) (with some limitations).\nUse custom vibrations/haptics on mobile.\n\nIf you like this free plugin, that's be cool if you can buy me a coffee 😀☕️\nSend tips to \u003chttps://paypal.me/UnityVibrationPlugin\u003e\n\n## Supported Platforms\n\n- \u003cimg src=\"./Images/Icons/android-icon.png\" alt=\"Aimeos logo\" title=\"Android\" align=\"center\" height=\"32\" /\u003e Android\n- \u003cimg src=\"./Images/Icons/ios-icon.png\" alt=\"Aimeos logo\" title=\"iOS\" align=\"center\" height=\"32\" /\u003e iOS\n- \u003cimg src=\"./Images/Icons/webgl-icon.png\" alt=\"Aimeos logo\" title=\"iOS\" align=\"center\" height=\"32\" /\u003e [WebGL](https://caniuse.com/webgl2) (some limitations apply on Mobile)\n\n## Installation\n\n### OpenUPM\n\nInstall the [OpenUPM](https://openupm.com) CLI and add the [com.benoitfreslon.vibration](https://openupm.com/packages/com.benoitfreslon.vibration) package\n\n```bash\n\n# Install node (e.g using NVM)\ncurl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash\n# \"node\" is an alias for the latest version\nnvm install node\n# You can list available versions using \"ls-remote\"\nnvm ls-remote\n# or 16.3.0, 12.22.1, etc\nnvm install 14.7.0\n\n# Install openupm-cli\nnpm install -g openupm-cli\n\n# Go to your Unity project directory\ncd YOUR_UNITY_PROJECT_DIR\n\n# Install package: com.benoitfreslon.vibration\nopenupm add com.benoitfreslon.vibration\n\n```\n\n### OpenUPM package\n\nFollow the installation guide from: [openupm/com.benoitfreslon.vibration](https://openupm.com/packages/com.benoitfreslon.vibration).\n\nAlternatively, merge the snippet below to [Packages/manifest.json](https://docs.unity3d.com/Manual/upm-manifestPrj.html) manually\n\n```jsonc\n{\n    // Verifiy which is the latest tag in this repository\n    \"dependencies\": {\n        \"com.benoitfreslon.vibration\": \"\u003cLATEST_VERSION\u003e\"\n    },\n    // If you already have the openupm registry,\n    // only add this package to \"scopes\" array\n    \"scopedRegistries\": [\n        {\n            \"name\": \"package.openupm.com\",\n            \"url\": \"https://package.openupm.com\",\n            \"scopes\": [\n                \"com.benoitfreslon.vibration\"\n            ]\n        }\n    ]\n}\n```\n\n### Github package\n\n1. Generate an **access token** on your Github account, following the guide: [Creating a personal access token (classic)](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-personal-access-token-classic).\n\n2. Add a **`$HOME/.upmconfig.toml`** file with the TOKEN to authenticate on registry\n\n    ```toml\n    [npmAuth.\"https://npm.pkg.github.com/@mfdeveloper\"]\n    # Generate the token from your github profile:\n    # https://github.com/settings/tokens\n    _authToken = \"\u003cTOKEN-VALUE\u003e\"\n    email = \"\u003cYOUR_EMAIL\u003e\"\n    alwaysAuth = true\n    ```\n\n    \u003e **WARNING:** _GitHub/Gitlab_ Packages registry always requires authentication. For **_private_** and **_public_** packages. If you don't have a Github account, or won't create a TOKEN, try use the [openupm](#openupm-package) package above.\n\n    ![Github package authentication](./Images/github-package-auth-require-token.jpg)\n\n3. Configure the scope **registry** and **dependency** in your Unity project `Packages/manifest.json`\n\n    ```jsonc\n    {\n        \"dependencies\": {\n            // Verifiy which is the latest tag in this repository\n            \"com.benoitfreslon.vibration\": \"\u003cLATEST_VERSION\u003e\"\n        },\n        \"scopedRegistries\": [\n            {\n                \"name\": \"Github Packages: mfdeveloper\",\n                \"url\": \"https://npm.pkg.github.com/@mfdeveloper\",\n                \"scopes\": [\n                    \"com.benoitfreslon\"\n                ]\n            }\n        ]\n    }\n    ```\n\n### Git dependency\n\nThe minimal checked Unity Version is **`2019.3.*`** LTS\n\nOpen Package Manager and \"Add package from git url...\" using next string:\n\n- `https://github.com/BenoitFreslon/Vibration.git#upm`\n\nOr use the latest git release/tag:\n\n- `https://github.com/BenoitFreslon/Vibration.git#\u003cLATEST_VERSION\u003e`\n\nYou also can edit `Packages/manifest.json` manually, just add:\n\n- `\"com.benoitfreslon.vibration\": \"https://github.com/BenoitFreslon/Vibration.git#\u003cLATEST_VERSION\u003e\",`\n\nOr you can simply copy and paste the entire `[upm]` branch content from this repo, to your Unity3D `Packages/\u003cPACKAGE_NAME\u003e` folder.\n\n## Getting Started\n\nThere are 2 ways to use this plugin:\n\n1. Use the `Runtime/VibrationComponent.cs` script attached to a _gameObject_ **(Recommended)**\n\n    ![Vibration Component](./Images/Screenshots/vibration-component-inspector.png)\n\n    On that script, you can:\n\n    - Enable/Disable vibration from inspector or programatically\n        \u003e **TIP:** Useful for enable/disable from a menu settings in your game!\n    - Add a `ScriptableObject` asset with vibration settings (only enable/disable for now)\n    - Configure the duration and/or select a pre-defined vibration effect type\n\n    This `MonoBehaviour` component use `Runtime/Vibration.cs` static class as a \"_fallback_\" for some implemented native integrations (**IOS** and **WebGL**)\n\n2. Use the `Runtime/Vibration.cs` static class\n\n    See the scene and a sample `MonoBehaviour` script under folder: `Samples/VibrationExample`\n\n## Vibrations\n\nUsing `Runtime/VibrationComponent`\n\n```csharp\n// That's the main method to pass a duration (milliseconds)\n// and/or a pre-defined `VibrationType` effect\nVibrate(\n    milliseconds: 20, \n    vibrationType: VibrationType.Click\n);\n\n```\n\nOptionally, you can pass an array of values of **_pattern_** as well:\n\n```csharp\n// That's the main method to pass a duration (milliseconds)\n// and/or a pre-defined `VibrationType` effect\nVibrate(\n    pattern: new[] { 200, 10, 50 }, \n    repeat: VibrationRepeat.Once\n);\n\n```\n\nAlso, it's possible define the **timeunit** of the duration value:\n\n```csharp\n// That's the main method to pass a duration (milliseconds)\n// and/or a pre-defined `VibrationType` effect\nVibrate(\n    duration: 10, \n    timeUnit: MobileTimeUnit.Seconds\n);\n\n```\n\nCheck if the mobile device has **vibration support**:\n\n```csharp\n// Fallback to \"Vibration.HasVibrator()\" on iOS and WebGL\nHasVibrator();\n```\n\n### Android (only)\n\nCheck if an Android [VibrationEffect](https://developer.android.com/reference/android/os/VibrationEffect) is supported:\n\n```csharp\n// Where: \"0\" is `VibrationEffect.EFFECT_CLICK` value \n// from native Android Kotlin/Java\nIsEffectSupported(0);\n```\n\nCheck if an Android [VibrationEffect.Composition](https://developer.android.com/reference/android/os/VibrationEffect.Composition) is supported:\n\n```csharp\n// Where: \"1\" is `VibrationEffect.Composition.PRIMITIVE_CLICK` value \n// from native Android Kotlin/Java\nIsPrimitiveSupported(1);\n```\n\n### iOS and Android\n\nUsing `Runtime/Vibration.cs` static class\n\n#### Default vibration\n\nUse `Vibration.Vibrate();` for a classic default ~400ms vibration\n\n#### Pop vibration\n\nPop vibration: weak boom (For iOS: only available with the haptic engine. iPhone 6s minimum or Android)\n\n`Vibration.VibratePop();`\n\n#### Peek Vibration\n\nPeek vibration: strong boom (For iOS: only available on iOS with the haptic engine. iPhone 6s minimum or Android)\n\n`Vibration.VibratePeek();`\n\n#### Nope Vibration\n\nNope vibration: series of three weak booms (For iOS: only available with the haptic engine. iPhone 6s minimum or Android)\n\n`Vibration.VibrateNope();`\n\n---\n\n## Android Only\n\n### Custom duration in milliseconds\n\n`Vibration.Vibrate(500);`\n\n#### Pattern\n\n```csharp\nlong[] pattern = { 0, 1000, 1000, 1000, 1000 };\nVibration.Vibrate (pattern, -1);\n```\n\n#### Cancel\n\nUsing `Runtime/VibrationComponent.cs`\n\n```csharp\n\n// Cancel for Android and WebGL\nVibrationComponent.Cancel();\n```\n\nUsing `Runtime/Vibration.cs` static class\n\n```csharp\nVibration.Cancel();\n```\n\n---\n\n## IOS only\n\nvibration using haptic engine\n\n`Vibration.VibrateIOS(ImpactFeedbackStyle.Light);`\n\n`Vibration.VibrateIOS(ImpactFeedbackStyle.Medium);`\n\n`Vibration.VibrateIOS(ImpactFeedbackStyle.Heavy);`\n\n`Vibration.VibrateIOS(ImpactFeedbackStyle.Rigid);`\n\n`Vibration.VibrateIOS(ImpactFeedbackStyle.Soft);`\n\n`Vibration.VibrateIOS(NotificationFeedbackStyle.Error);`\n\n`Vibration.VibrateIOS(NotificationFeedbackStyle.Success);`\n\n`Vibration.VibrateIOS(NotificationFeedbackStyle.Warning);`\n\n`Vibration.VibrateIOS_SelectionChanged();`\n\n## Development\n\n### Publish (Github Packages)\n\n1. Install `node` (e.g using [NVM](https://github.com/nvm-sh/nvm))\n\n2. Generate a [Github access token (classic)](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-personal-access-token-classic)\n\n3. Authenticate using the generated TOKEN:\n\n   Create a user `$HOME/.npmrc` file\n\n    ```ini\n    # Where: \u003cGITHUB_TOKEN\u003e is the access token (classic) generated in your profile\n    @github:registry=https://npm.pkg.github.com\n    //npm.pkg.github.com/:_authToken=\u003cGITHUB_TOKEN\u003e\n    ```\n\n    Or, use the file `Packages/\u003cPACKAGE_NAME\u003e/.npmrc` that already exists in this repository:\n\n    ```bash\n    # Export the environment variable \"$GITHUB_TOKEN\"\n    # the file \".npmrc\" inside of this repo will use this variable\n    export GITHUB_TOKEN=\u003cGITHUB_TOKEN\u003e\n    ```\n\n4. Publish the package with [npm publish](https://docs.npmjs.com/cli/v9/commands/npm-publish)\n\n    From [`[upm-package-embedded]`](https://github.com/mfdeveloper/Vibration/tree/upm-package-embedded) git branch\n\n    ```bash\n    # Clone this repo and checkout to branch \"[upm-package-embedded]\"\n    git clone https://github.com/mfdeveloper/Vibration.git\n    git checkout upm-package-embedded\n\n    # Run the npm scripts\n    npm install\n    npm run publish:package # Publish from repository ROOT path\n\n    cd Packages/\u003cPACKAGE_NAME\u003e\n    npm run pack:package # Pack in a .tgz for testing (optional)\n    npm run package:publish-from-local # Publish from package path\n    npm run publish:from-local # Or use this another script alias for publishing (optional)\n    ``````\n\n    \u003e **WARNING:** Avoid use the common **`npm publish`** directly, because the hooks `prepare`, `prepublish` ... aren't triggered in this package. They have conflicts with [OpenUPM Azure pipelines](https://dev.azure.com/openupm/openupm/_build?definitionId=1\u0026_a=summary) and fail when try run automation publishing tags to OpenUPM :(\n\n#### NPM Scripts (optional)\n\nOptionally, you can run specific npm scripts inside of `Packages/\u003cPACKAGE_NAME\u003e` or from **`[upm]`** branch:\n\n```bash\n# Go to the package dir\ncd Packages/\u003cPACKAGE_NAME\u003e\n\n# Pack a .tgz for testing (optional)\nnpm run package:pack\n\n# Run the publish script (with $PUBLISH_FORCE environment variable)\nnpm run package:publish-from-local\n# Alias script to \"package:publish-from-local\" above\nnpm run publish:from-local\n# Or simply run the command line below from any unix-like bash terminal\n# (e.g from Git bash on Windows)\nPUBLISH_FORCE=1 \u0026\u0026 npm run package:prepare \u0026\u0026 npm publish\n```\n\n### Publish (OpenUPM)\n\n1. Bump the version with a new Github release or Git tag\n    \u003e **PS:** Avoid change/rewrite a existent git tag. If you really need do that, create a new issue on Github repo =\u003e [openupm: Unpublish a Package Version](https://github.com/openupm/openupm/issues/new?title=Unpublish%20package%20version\u0026template=unpublish_version.md)\n2. The changes should be reflected in: [https://openupm.com/packages/com.benoitfreslon.vibration](https://openupm.com/packages/com.benoitfreslon.vibration)\n\n\u003e **See:** [Modifying UPM Package](https://openupm.com/docs/modifying-upm-package.html#modifying-upm-package)\n\n## References\n\n### ANDROID\n\n- [Using Vibrate In Android](https://proandroiddev.com/using-vibrate-in-android-b0e3ef5d5e07)\n- [Android 12: VibratorManager \u0026 New Vibration Primitives](https://yggr.medium.com/exploring-android-12-vibratormanager-new-vibration-primitives-e862c95fe938)\n- [Developers Android: VibrationEffect](https://developer.android.com/reference/android/os/VibrationEffect)\n- [Developers Android: VibrationEffect.Composition](https://developer.android.com/reference/android/os/VibrationEffect.Composition)\n\n### OPENUPM\n\n- [Adding UPM Package](https://openupm.com/docs/adding-upm-package.html)\n- [Modifying UPM Package](https://openupm.com/docs/modifying-upm-package.html#modifying-upm-package)\n\n### GITHUB PACKAGES\n\n- [Custom Package with Git Dependencies](https://forum.unity.com/threads/custom-package-with-git-dependencies.628390/)\n- [Using GitHub Packages Registry with Unity Package Manager](https://forum.unity.com/threads/using-github-packages-registry-with-unity-package-manager.861076)\n- [Package manager not displaying all packages in scoped registry](https://forum.unity.com/threads/package-manager-not-displaying-all-packages-in-scoped-registry.791598/#post-5666161)\n\n#### ICONS (Copyright)\n\n\u003ca href=\"https://www.flaticon.com/free-icons/haptic\" title=\"haptic icons\"\u003eHaptic icons created by Uniconlabs - Flaticon\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmfdeveloper%2Fvibration","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmfdeveloper%2Fvibration","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmfdeveloper%2Fvibration/lists"}