diff --git a/com.microsoft.mrtk.uxcomponents.noncanvas/Tests/Runtime/SliderTests.cs b/com.microsoft.mrtk.uxcomponents.noncanvas/Tests/Runtime/SliderTests.cs index eed8f9a15a8..76e6b35f498 100644 --- a/com.microsoft.mrtk.uxcomponents.noncanvas/Tests/Runtime/SliderTests.cs +++ b/com.microsoft.mrtk.uxcomponents.noncanvas/Tests/Runtime/SliderTests.cs @@ -395,6 +395,7 @@ public IEnumerator TestAssembleTouchNoSnapSlider() Assert.IsFalse(interactionUpdated, "Slider updated value when we didn't touch the handle and snapToPosition = false"); Assert.AreEqual(0.5f, slider.Value, "Slider shouldn't have snapped to the finger point when SnapToPosition = false"); + // Must move down then up in order to avoid nudging the slider yield return rightHand.MoveTo(Vector3.zero, 60); yield return RuntimeTestUtilities.WaitForUpdates(); @@ -404,7 +405,7 @@ public IEnumerator TestAssembleTouchNoSnapSlider() Assert.IsTrue(slider.IsPokeSelected, "Slider should be poked!"); Assert.IsTrue(interactionStarted, "Slider didn't start interaction when we poked the handle"); - Assert.IsTrue(interactionUpdated, "Slider didn't invoke OnValueUpdated when we poked the handle"); + Assert.IsFalse(interactionUpdated, "Slider incorrectly invoked OnValueUpdated when we poked the handle"); Assert.AreEqual(0.5f, slider.Value, 0.001f, "Slider should still be roughly the same value"); interactionUpdated = false; @@ -682,4 +683,4 @@ private void InstantiateDefaultSliderPrefab(Vector3 position, Vector3 rotation, #endregion Private methods } } -#pragma warning restore CS1591 \ No newline at end of file +#pragma warning restore CS1591 diff --git a/com.microsoft.mrtk.uxcore/Slider/Slider.cs b/com.microsoft.mrtk.uxcore/Slider/Slider.cs index bbf9b84890a..00e188e41a3 100644 --- a/com.microsoft.mrtk.uxcore/Slider/Slider.cs +++ b/com.microsoft.mrtk.uxcore/Slider/Slider.cs @@ -358,7 +358,7 @@ private float SnapSliderToStepPositions(float value) { var stepCount = value / SliderStepVal; var snappedValue = SliderStepVal * Mathf.RoundToInt(stepCount); - Mathf.Clamp(snappedValue, MinValue, MaxValue); + Mathf.Clamp(snappedValue, 0f, 1.0f); return snappedValue; } @@ -369,10 +369,11 @@ private void UpdateSliderValue() var handDelta = Vector3.Dot(SliderTrackDirection.normalized, interactorDelta); - float unsnappedValue = Mathf.Clamp(StartSliderValue + handDelta / SliderTrackDirection.magnitude, MinValue, MaxValue); + float unsnappedValue = Mathf.Clamp(StartSliderValue + handDelta / SliderTrackDirection.magnitude, 0f, 1.0f); - Value = useSliderStepDivisions ? SnapSliderToStepPositions(unsnappedValue) : unsnappedValue; - } + var normalizedValue = useSliderStepDivisions ? SnapSliderToStepPositions(unsnappedValue) : unsnappedValue; + Value = normalizedValue * (MaxValue - MinValue) + MinValue; + } #endregion diff --git a/com.microsoft.mrtk.uxcore/Slider/Visuals/CanvasSliderVisuals.cs b/com.microsoft.mrtk.uxcore/Slider/Visuals/CanvasSliderVisuals.cs index f6329777877..c5adae2981c 100644 --- a/com.microsoft.mrtk.uxcore/Slider/Visuals/CanvasSliderVisuals.cs +++ b/com.microsoft.mrtk.uxcore/Slider/Visuals/CanvasSliderVisuals.cs @@ -193,7 +193,7 @@ private void Update() // Update the things that depend on the slider value. void UpdateHandle(SliderEventData data) { - UpdateHandle(data.NewValue); + UpdateHandle(SliderState.NormalizedValue); } // Update the things that depend on the slider value.