1
0
mirror of synced 2024-12-20 10:15:54 +01:00
WACVR/Assets/Script/Controller/ControllerHapticManager.cs

33 lines
891 B
C#
Raw Normal View History

2022-05-16 23:38:40 +02:00
using System.Collections;
using System.Collections.Generic;
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()
{
ConfigManager.onConfigChanged += ApplyConfig;
ConfigManager.EnsureInitialization();
ApplyConfig();
}
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();
}
2022-10-03 02:04:54 +02:00
void ApplyConfig()
{
duration = ConfigManager.config.HapticDuration;
amplitude = ConfigManager.config.HapticAmplitude;
}
2022-05-16 23:38:40 +02:00
}