diff --git a/Assets/MRTK/SDK/Features/UX/Scripts/Sliders/SliderSounds.cs b/Assets/MRTK/SDK/Features/UX/Scripts/Sliders/SliderSounds.cs index 7d205ed4b35..48dca52e502 100644 --- a/Assets/MRTK/SDK/Features/UX/Scripts/Sliders/SliderSounds.cs +++ b/Assets/MRTK/SDK/Features/UX/Scripts/Sliders/SliderSounds.cs @@ -13,6 +13,9 @@ namespace Microsoft.MixedReality.Toolkit.UI [AddComponentMenu("Scripts/MRTK/SDK/SliderSounds")] public class SliderSounds : MonoBehaviour { + [SerializeField] + private bool playSoundsOnlyOnInteract = false; + [Header("Audio Clips")] [SerializeField] [Tooltip("Sound to play when interaction with slider starts")] @@ -48,10 +51,12 @@ public class SliderSounds : MonoBehaviour [SerializeField] private float minSecondsBetweenTicks = 0.01f; - #region Private members private PinchSlider slider; + // Check to see if the slider is being interacted with + private bool isInteracting; + // Play sound when passing through slider notches private float accumulatedDeltaSliderValue = 0; private float lastSoundPlayTime; @@ -83,7 +88,7 @@ private void Start() private void OnValueUpdated(SliderEventData eventData) { - if (playTickSounds && passNotchAudioSource != null && passNotchSound != null) + if (!(playSoundsOnlyOnInteract && !isInteracting) && playTickSounds && passNotchAudioSource != null && passNotchSound != null) { float delta = eventData.NewValue - eventData.OldValue; accumulatedDeltaSliderValue += Mathf.Abs(delta); @@ -104,6 +109,7 @@ private void OnValueUpdated(SliderEventData eventData) private void OnInteractionEnded(SliderEventData arg0) { + isInteracting = false; if (interactionEndSound != null && grabReleaseAudioSource != null && grabReleaseAudioSource.isActiveAndEnabled) { grabReleaseAudioSource.PlayOneShot(interactionEndSound); @@ -112,6 +118,7 @@ private void OnInteractionEnded(SliderEventData arg0) private void OnInteractionStarted(SliderEventData arg0) { + isInteracting = true; if (interactionStartSound != null && grabReleaseAudioSource != null && grabReleaseAudioSource.isActiveAndEnabled) { grabReleaseAudioSource.PlayOneShot(interactionStartSound);