@@ -13,6 +13,9 @@ namespace Microsoft.MixedReality.Toolkit.UI
1313 [ AddComponentMenu ( "Scripts/MRTK/SDK/SliderSounds" ) ]
1414 public class SliderSounds : MonoBehaviour
1515 {
16+ [ SerializeField ]
17+ private bool playSoundsOnlyOnInteract = false ;
18+
1619 [ Header ( "Audio Clips" ) ]
1720 [ SerializeField ]
1821 [ Tooltip ( "Sound to play when interaction with slider starts" ) ]
@@ -48,10 +51,12 @@ public class SliderSounds : MonoBehaviour
4851 [ SerializeField ]
4952 private float minSecondsBetweenTicks = 0.01f ;
5053
51-
5254 #region Private members
5355 private PinchSlider slider ;
5456
57+ // Check to see if the slider is being interacted with
58+ private bool isInteracting ;
59+
5560 // Play sound when passing through slider notches
5661 private float accumulatedDeltaSliderValue = 0 ;
5762 private float lastSoundPlayTime ;
@@ -83,7 +88,7 @@ private void Start()
8388
8489 private void OnValueUpdated ( SliderEventData eventData )
8590 {
86- if ( playTickSounds && passNotchAudioSource != null && passNotchSound != null )
91+ if ( ! ( playSoundsOnlyOnInteract && ! isInteracting ) && playTickSounds && passNotchAudioSource != null && passNotchSound != null )
8792 {
8893 float delta = eventData . NewValue - eventData . OldValue ;
8994 accumulatedDeltaSliderValue += Mathf . Abs ( delta ) ;
@@ -104,6 +109,7 @@ private void OnValueUpdated(SliderEventData eventData)
104109
105110 private void OnInteractionEnded ( SliderEventData arg0 )
106111 {
112+ isInteracting = false ;
107113 if ( interactionEndSound != null && grabReleaseAudioSource != null && grabReleaseAudioSource . isActiveAndEnabled )
108114 {
109115 grabReleaseAudioSource . PlayOneShot ( interactionEndSound ) ;
@@ -112,6 +118,7 @@ private void OnInteractionEnded(SliderEventData arg0)
112118
113119 private void OnInteractionStarted ( SliderEventData arg0 )
114120 {
121+ isInteracting = true ;
115122 if ( interactionStartSound != null && grabReleaseAudioSource != null && grabReleaseAudioSource . isActiveAndEnabled )
116123 {
117124 grabReleaseAudioSource . PlayOneShot ( interactionStartSound ) ;
0 commit comments