Skip to content

Commit

Permalink
Added option to only have slider sounds play during manipulation (#10081
Browse files Browse the repository at this point in the history
)

* added option to only play slider sounds during manipulation

* changed default value to match existing behavior
  • Loading branch information
RogPodge committed Jul 14, 2021
1 parent 768e432 commit e140bf2
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions Assets/MRTK/SDK/Features/UX/Scripts/Sliders/SliderSounds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit e140bf2

Please sign in to comment.