Interhaptics SDK for Unity 1.6
Loading...
Searching...
No Matches
GlobalIntensitySlider.cs
Go to the documentation of this file.
1/* ​
2* Copyright (c) 2023 Go Touch VR SAS. All rights reserved. ​
3* ​
4*/
5
7using UnityEngine;
8using UnityEngine.UI;
9
11{
12 [RequireComponent(typeof(Slider))]
13 public class GlobalIntensitySlider : MonoBehaviour
14 {
16 private Slider slider;
17
18 private void Awake()
19 {
20 slider = GetComponent<Slider>();
21 if (hapticController!=null)
22 {
23 slider.value = (float)hapticController.globalIntensity;
24 slider.onValueChanged.AddListener(HandleSliderValueChanged);
25 // Subscribe to the onIntensityChanged event
26 hapticController.onIntensityChanged += UpdateSliderPosition;
27 }
28 }
29
30 private void OnDestroy()
31 {
32 if (hapticController != null)
33 {
34 // Unsubscribe to avoid memory leaks
35 hapticController.onIntensityChanged -= UpdateSliderPosition;
36 }
37 }
38
39 public void HandleSliderValueChanged(float value)
40 {
41 // Update the global intensity when the slider's value changes
43 }
44 private void UpdateSliderPosition(double newIntensity)
45 {
46 slider.value = (float)newIntensity;
47 }
48 }
49}
GlobalHapticIntensityController hapticController