Interhaptics SDK for Unity 1.6
Loading...
Searching...
No Matches
TargetBodyPartIntensitySlider.cs
Go to the documentation of this file.
1/* ​
2* Copyright (c) 2023 Go Touch VR SAS. All rights reserved. ​
3* ​
4*/
5
6using UnityEngine;
7using UnityEngine.UI;
9
11{
12 [RequireComponent(typeof(Slider))]
13 public class TargetBodyPartIntensitySlider : MonoBehaviour
14 {
15 public HapticBodyPart[] hapticBodyParts; // Reference to the array of HapticBodyPart components
16 private Slider slider;
17
18 private void Awake()
19 {
20 slider = GetComponent<Slider>();
21 // Initialize the slider value to the first haptic body part's intensity and subscribe to the onValueChanged event
22 if (hapticBodyParts.Length > 0 && hapticBodyParts[0] != null)
23 {
24 slider.value = (float)hapticBodyParts[0].TargetIntensity; // Assuming all haptic body parts have the same initial intensity
25 slider.onValueChanged.AddListener(HandleIntensityChange);
26 }
27 }
28
29 public void HandleIntensityChange(float value)
30 {
31 // Update the TargetIntensity of each HapticBodyPart
32 foreach (HapticBodyPart hapticBodyPart in hapticBodyParts)
33 {
34 if (hapticBodyPart != null)
35 {
36 hapticBodyPart.TargetIntensity = value; // Updating only the value and not calling UpdateTargetIntensity() to avoid crash calls to the native plugin - no HapticMaterialId is set yet
37 }
38 }
39 }
40 }
41}