Guide for Unity
Using our Unity SDK Plugin, you can implement the haptic into your content made with Unity.
- Import SDK Plugin
- Link the Haptic App
- Add Prefab to Initialize
Prerequisite
If you want to use haptic feature in your game, the haptic application should be linked to your game. Make sure you have a haptic application(haptic app, for short) corresponding to your game.
You can create and manage haptic apps in Developer Portal(Portal, for short), a web-based program. If you don't know about haptic app or don't have one, please visit Portal first and make your own haptic app. (Protip: Use template to make the app quickly)
Prepare your haptic app
To link the haptic app to the game, the haptic app should meet these requirements. Go to your haptic app in the Portal, and check these requirements.
- Haptic app should contain at least one haptic event
- The event named
game_start
already exists, unless you manually removed it.
- The event named
- API Key should be generated
- There is no API Key until you generate it. Go to the "API Key" tab and click "New" button to generate one.
- Haptic app should be deployed
- If you see "Deploy Now" button on the top right, press it to deploy your haptic app. Otherwise, if you can see "Up to date", it means that the latest haptic app has already been deployed.
Get App ID & API Key
Link process requires App ID and API Key which can be browsed in the "Settings" tab. Go to the "Settings" tab, and check the App ID and API Key.
Import SDK Plugin
Get bHaptics Haptic Plugin in Unity Asset Store, and import the package into your Unity project.
For more information about importing the Unity package to your Unity project, follow the official Unity documentation.
Link the Haptic App
- In the toolbar, select "bHaptics" → "Developer Window".
- Enter your App ID and API Key from Portal, then click "LINK" button.
note
You can press "Forgot your App ID & API Key?" to visit Portal and retrieve the information.
- After successful certification, the application will appear on bHaptics Developer Window.
Browse App in bHaptics Developer Window
There are multiple tabs you can explore.
- Home: View the sample guide, and information about your application.
- Events: Browse and play the latest events you deployed from bHaptics developer portal.
- Documentation: Browse the documents about the SDK(including this site!)
- Latest Deployed Version: Check the version or refresh.
note
Ensure the version in the portal matches the version in the editor; if not, press refresh icon.
- Unlink: Disconnet between the game and the haptic app.
Add Prefab for Initialization
There is a prefab named "[bhaptics]" for initalizing the haptic environment. It should be instantiated before using haptic-related functions. We highly recommend to place it at the first scene.
- Go to your first scene.
- In the Project Window, Go to "Assets" → "Bhaptics" → "SDK2" → "Prefabs".
- Add "[bHaptics]" prefab into your scene.
The component in this prefab uses the common Unity Singleton pattern with DontDestroyOnLoad. You only need to place it in the first scene, but it is okay to place multiple places since duplicates are automatically destroyed.
Update Android Manifest
If your Android Target API Level is 30 or higher, you need to update your AndroidManifest.xml
for the bHaptics integration in your game.
To check the project's Android target API level, Go to Project Settings → Player → Android settings(Android icon) → Other Settings → Identification → Target API Level. Refer the Unity manual for more information.
- Enable Android app manifest override. Go to Project Settings → Player → Android settings(Android icon) → Publishing Settings → Build → Custom Main Manifest. Then enable it if it's disabled. The directory of the manifest file is shown below.
- Open your
AndroidManifest.xml
file, which is usually located in theAssets/Plugins/Android/
directory. - Add queries element to the manifest file.
<queries>
<package android:name="com.bhaptics.player" />
</queries> - Update and Add Permissions to the manifest file.
<uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30"/>
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
After the process is complete, the manifest file should look like this.
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.unity3d.player"
xmlns:tools="http://schemas.android.com/tools">
<application>
<activity android:name="com.unity3d.player.UnityPlayerActivity"
android:theme="@style/UnityThemeSelector">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="unityplayer.UnityActivity" android:value="true" />
</activity>
</application>
<queries>
<package android:name="com.bhaptics.player" />
</queries>
<uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
</manifest>
For more information, please refer to the following resources.
If you've activated Minify option, you should add exceptions to the Custom Proguard file (proguard-user.txt).
Further Reading
You're now ready to use the bHaptics haptic feature! Visit our Unity References page to play haptics in your game.
If you want to feel haptics right now, we provide a sample scene to explore the haptic events you can playtest. Go to "Assets" → "Bhaptics" → "SDK2" → "Examples" → "Scenes", and open "PlayParamSample" scene. You can play all haptic events with adjusting related parameters.