Interhaptics SDK for Unity
1.6
Loading...
Searching...
No Matches
Interhaptics
sdk_unity
Interhaptics
Runtime
Samples
UI
TargetBodyPartIntensitySlider.cs
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2023 Go Touch VR SAS. All rights reserved.
3
*
4
*/
5
6
using
UnityEngine;
7
using
UnityEngine.UI;
8
using
Interhaptics.HapticBodyMapping
;
9
10
namespace
Interhaptics.Samples
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
}
Interhaptics.HapticBodyPart
Definition
HapticBodyPart.cs:15
Interhaptics.Samples.TargetBodyPartIntensitySlider
Definition
TargetBodyPartIntensitySlider.cs:14
Interhaptics.Samples.TargetBodyPartIntensitySlider.hapticBodyParts
HapticBodyPart[] hapticBodyParts
Definition
TargetBodyPartIntensitySlider.cs:15
Interhaptics.Samples.TargetBodyPartIntensitySlider.HandleIntensityChange
void HandleIntensityChange(float value)
Definition
TargetBodyPartIntensitySlider.cs:29
Interhaptics.HapticBodyMapping
Definition
BodyMapping.cs:7
Interhaptics.Samples
Definition
AudioControlGUI.cs:10
Generated by
1.11.0