Interhaptics Mobile SDK
Interhaptics Mobile SDK is an integration tool for Haptics on IOS and Android. It utilizes three scripts: MobileHapticsStiffness, MobileHapticsTexture, and MobileHapticsVibration, which handle different haptic
Before adding these scripts to a GameObject, create an empty GameObject for the HapticManager, which can be set to be persistent if desired.
All three scripts are inherited from the abstract class AMobileHapticsReader, and the implementation of each script is the same. To use them, follow these steps:
- Add the script to a GameObject.
- Add preloaded materials to the array on the inspector.
- Call one of the public Play functions (PlayStiffness, PlayTexture, or PlayVibration) contained in the corresponding haptic perception handler (MobileHapticsStiffness, MobileHapticsTexture, or MobileHapticsVibration) and pass the index of the material as a parameter.
- If you want to add materials at runtime, you have to create a class that inherits from AMobileHapticsReader and call the protected function AddMaterial(TextAsset material).
- The loaded materials list is different from the preloaded materials array (that you can see on the inspector). If you modified the materials loading process, the index can be different than the index of the preloaded materials array, otherwise, it remains the same.
- You can use the public function GetIndexFromTextAsset(TextAsset material, out int index) to retrieve the index of material from your perception handler’s loaded materials List.
- You can add each perception handler on the same GameObject.
- You can’t add multiple handlers of the same perception on the same GameObject.
- The sample scene located in the MobileHaptics package includes three points of interaction – a button that plays a vibration on click, a textured slider that plays a texture on drag, and a stiffness slider that plays stiffness on interaction.
- Note: Stiffness is only supported on IOS.
To use the MobileHapticsVibration script, add it to a GameObject and assign a material that contains a vibration perception to its array of preloaded materials. The MobileHapticsVibration script contains one public method:
- public void PlayVibration(int index): This method plays the vibration perception of the material, the index of the material is passed as a parameter.
To call the vibration when the button is clicked, call the function PlayVibration(0) if only one material is set on the MobileHapticsVibration handler.
2 – MobileHapticsTexture
To use the MobileHapticsTexture script, add it to a GameObject and assign a material that contains a texture perception to its array of preloaded materials. The MobileHapticsTexture script contains two public methods:
- public void PlayTexture(int index, float distance): This method plays the texture perception of a material based on its length, the index of the material and the distance are passed as parameters.
- public void PlayTexture01(int index, float distance01): This method plays the texture perception of a material based on its normalized distance (between 0 and 1), the index of the material and the normalized distance are passed as parameters.
To call the texture when the slider value changes, call the function PlayTexture01(0, sliderValue) in the case that the slider value is clamped between 0 and 1, that allows you to play the whole texture from its beginning (0) to its end (1). An example script, TextureSlider, is located in the package and it requires a Slider script. It takes two parameters:
- The index of the material to play.
- The MobileHapticsTexture handler.
Please note that this feature is only available on IOS devices.
MobileHapticsStiffness contains one public method:
- public void PlayStiffness(int index, float distance): This method plays the stiffness perception of a material based on its length, the index of the material and the distance are passed as parameters.
Note that the stiffness perception length is always clamped between 0 and 1. To call the stiffness when the user interacts with the slider, call the function PlayStiffness(0, sliderValue) on the update method, using the slider value clamped between 0 and 1.
An example script, StiffnessSlider, is located in the package and it requires a Slider script. It takes two parameters:
- The index of the material to play.
- The MobileHapticsStiffness handler.