8 using UnityEngine.Events;
9 using System.Collections;
11 namespace Valve.VR.InteractionSystem
14 [RequireComponent( typeof( Interactable ) )]
17 [Tooltip(
"The linear mapping driving the haptic rack" )]
20 [Tooltip(
"The number of haptic pulses evenly distributed along the mapping" )]
21 public int teethCount = 128;
23 [Tooltip(
"Minimum duration of the haptic pulse" )]
24 public int minimumPulseDuration = 500;
26 [Tooltip(
"Maximum duration of the haptic pulse" )]
27 public int maximumPulseDuration = 900;
29 [Tooltip(
"This event is triggered every time a haptic pulse is made" )]
30 public UnityEvent onPulse;
33 private int previousToothIndex = -1;
38 if ( linearMapping == null )
40 linearMapping = GetComponent<LinearMapping>();
46 private void OnHandHoverBegin(
Hand hand )
53 private void OnHandHoverEnd(
Hand hand )
62 int currentToothIndex = Mathf.RoundToInt( linearMapping.value * teethCount - 0.5f );
63 if ( currentToothIndex != previousToothIndex )
66 previousToothIndex = currentToothIndex;
74 if ( hand && ( hand.controller != null ) && ( hand.GetStandardInteractionButton() ) )
76 ushort duration = (ushort)Random.Range( minimumPulseDuration, maximumPulseDuration + 1 );
77 hand.controller.TriggerHapticPulse( duration );