2022-11-05 01:32:17 +01:00
|
|
|
using UnityEngine.UI;
|
2022-05-16 23:38:40 +02:00
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.XR;
|
2022-10-03 02:04:54 +02:00
|
|
|
public class ControllerHapticManager : MonoBehaviour
|
2022-05-16 23:38:40 +02:00
|
|
|
{
|
|
|
|
public XRNode Hand;
|
|
|
|
InputDevice device;
|
2022-10-03 02:04:54 +02:00
|
|
|
public float duration = 0.1f;
|
|
|
|
public float amplitude = 1f;
|
|
|
|
void Start()
|
|
|
|
{
|
2022-11-05 01:32:17 +01:00
|
|
|
var durationWidget = ConfigManager.GetConfigPanelWidget("HapticDuration");
|
|
|
|
var amplitudeWidget = ConfigManager.GetConfigPanelWidget("HapticAmplitude");
|
|
|
|
var durationSlider = durationWidget.GetComponent<Slider>();
|
|
|
|
var amplitudeSlider = amplitudeWidget.GetComponent<Slider>();
|
|
|
|
durationSlider.onValueChanged.AddListener( (float value) => { duration = value;});
|
|
|
|
amplitudeSlider.onValueChanged.AddListener( (float value) => { amplitude = value;});
|
|
|
|
durationSlider.onValueChanged?.Invoke(duration);
|
|
|
|
amplitudeSlider.onValueChanged?.Invoke(amplitude);
|
2022-10-03 02:04:54 +02:00
|
|
|
}
|
2022-05-16 23:38:40 +02:00
|
|
|
private void OnTriggerEnter(Collider other)
|
|
|
|
{
|
|
|
|
device = InputDevices.GetDeviceAtXRNode(Hand);
|
|
|
|
device.SendHapticImpulse(0, amplitude, duration);
|
|
|
|
}
|
|
|
|
private void OnTriggerExit(Collider other)
|
|
|
|
{
|
|
|
|
device = InputDevices.GetDeviceAtXRNode(Hand);
|
|
|
|
device.StopHaptics();
|
|
|
|
}
|
|
|
|
}
|