From 774f8de199ca4a6a5897c899bbe70777a7cf9792 Mon Sep 17 00:00:00 2001 From: Simon Jackson Date: Sun, 5 Sep 2021 09:33:19 +0100 Subject: [PATCH] Resolves issue where the lower range value would become stuck when moved to the max value position Resolves: https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/issues/381/cant-move-range-slider-if-low-is-moved-to --- Runtime/Scripts/Controls/RangeSlider.cs | 56 +++++++++++++++---------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/Runtime/Scripts/Controls/RangeSlider.cs b/Runtime/Scripts/Controls/RangeSlider.cs index ceeb6da..4477017 100644 --- a/Runtime/Scripts/Controls/RangeSlider.cs +++ b/Runtime/Scripts/Controls/RangeSlider.cs @@ -533,31 +533,17 @@ namespace UnityEngine.UI.Extensions //HANDLE DRAG EVENTS m_LowOffset = m_HighOffset = Vector2.zero; Vector2 localMousePos; - if (m_HighHandleRect != null && RectTransformUtility.RectangleContainsScreenPoint(m_HighHandleRect, eventData.position, eventData.enterEventCamera)) + if(m_LowHandleRect != null && LowValue == MaxValue && RectTransformUtility.RectangleContainsScreenPoint(m_LowHandleRect, eventData.position, eventData.enterEventCamera)) { - //dragging the high value handle - if (RectTransformUtility.ScreenPointToLocalPointInRectangle(m_HighHandleRect, eventData.position, eventData.pressEventCamera, out localMousePos)) - { - m_HighOffset = localMousePos; - } - interactionState = InteractionState.High; - if (transition == Transition.ColorTint) - { - targetGraphic = m_HighHandleRect.GetComponent(); - } + SetToMoveLowValueHandle(m_LowHandleRect, eventData); + } + else if (m_HighHandleRect != null && RectTransformUtility.RectangleContainsScreenPoint(m_HighHandleRect, eventData.position, eventData.enterEventCamera)) + { + SetToMoveHighValueHandle(m_HighHandleRect, eventData); } else if (m_LowHandleRect != null && RectTransformUtility.RectangleContainsScreenPoint(m_LowHandleRect, eventData.position, eventData.enterEventCamera)) { - //dragging the low value handle - if (RectTransformUtility.ScreenPointToLocalPointInRectangle(m_LowHandleRect, eventData.position, eventData.pressEventCamera, out localMousePos)) - { - m_LowOffset = localMousePos; - } - interactionState = InteractionState.Low; - if (transition == Transition.ColorTint) - { - targetGraphic = m_LowHandleRect.GetComponent(); - } + SetToMoveLowValueHandle(m_LowHandleRect, eventData); } else { @@ -575,6 +561,34 @@ namespace UnityEngine.UI.Extensions base.OnPointerDown(eventData); } + private void SetToMoveLowValueHandle(RectTransform transform, PointerEventData eventData) + { + //dragging the low value handle + if (RectTransformUtility.ScreenPointToLocalPointInRectangle(transform, eventData.position, eventData.pressEventCamera, out var localMousePos)) + { + m_LowOffset = localMousePos; + } + interactionState = InteractionState.Low; + if (transition == Transition.ColorTint) + { + targetGraphic = m_LowHandleRect.GetComponent(); + } + } + + private void SetToMoveHighValueHandle(RectTransform transform, PointerEventData eventData) + { + //dragging the low value handle + if (RectTransformUtility.ScreenPointToLocalPointInRectangle(transform, eventData.position, eventData.pressEventCamera, out var localMousePos)) + { + m_HighOffset = localMousePos; + } + interactionState = InteractionState.High; + if (transition == Transition.ColorTint) + { + targetGraphic = m_HighHandleRect.GetComponent(); + } + } + public virtual void OnDrag(PointerEventData eventData) { if (!MayDrag(eventData))