Skip to content

Commit e140bf2

Browse files
authored
Added option to only have slider sounds play during manipulation (#10081)
* added option to only play slider sounds during manipulation * changed default value to match existing behavior
1 parent 768e432 commit e140bf2

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

Assets/MRTK/SDK/Features/UX/Scripts/Sliders/SliderSounds.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)