@@ -13,6 +13,9 @@ namespace Microsoft.MixedReality.Toolkit.UI
13
13
[ AddComponentMenu ( "Scripts/MRTK/SDK/SliderSounds" ) ]
14
14
public class SliderSounds : MonoBehaviour
15
15
{
16
+ [ SerializeField ]
17
+ private bool playSoundsOnlyOnInteract = false ;
18
+
16
19
[ Header ( "Audio Clips" ) ]
17
20
[ SerializeField ]
18
21
[ Tooltip ( "Sound to play when interaction with slider starts" ) ]
@@ -48,10 +51,12 @@ public class SliderSounds : MonoBehaviour
48
51
[ SerializeField ]
49
52
private float minSecondsBetweenTicks = 0.01f ;
50
53
51
-
52
54
#region Private members
53
55
private PinchSlider slider ;
54
56
57
+ // Check to see if the slider is being interacted with
58
+ private bool isInteracting ;
59
+
55
60
// Play sound when passing through slider notches
56
61
private float accumulatedDeltaSliderValue = 0 ;
57
62
private float lastSoundPlayTime ;
@@ -83,7 +88,7 @@ private void Start()
83
88
84
89
private void OnValueUpdated ( SliderEventData eventData )
85
90
{
86
- if ( playTickSounds && passNotchAudioSource != null && passNotchSound != null )
91
+ if ( ! ( playSoundsOnlyOnInteract && ! isInteracting ) && playTickSounds && passNotchAudioSource != null && passNotchSound != null )
87
92
{
88
93
float delta = eventData . NewValue - eventData . OldValue ;
89
94
accumulatedDeltaSliderValue += Mathf . Abs ( delta ) ;
@@ -104,6 +109,7 @@ private void OnValueUpdated(SliderEventData eventData)
104
109
105
110
private void OnInteractionEnded ( SliderEventData arg0 )
106
111
{
112
+ isInteracting = false ;
107
113
if ( interactionEndSound != null && grabReleaseAudioSource != null && grabReleaseAudioSource . isActiveAndEnabled )
108
114
{
109
115
grabReleaseAudioSource . PlayOneShot ( interactionEndSound ) ;
@@ -112,6 +118,7 @@ private void OnInteractionEnded(SliderEventData arg0)
112
118
113
119
private void OnInteractionStarted ( SliderEventData arg0 )
114
120
{
121
+ isInteracting = true ;
115
122
if ( interactionStartSound != null && grabReleaseAudioSource != null && grabReleaseAudioSource . isActiveAndEnabled )
116
123
{
117
124
grabReleaseAudioSource . PlayOneShot ( interactionStartSound ) ;
0 commit comments