Added optional event delta to OnEndDrag - to allow bail out of swipe action if swipe motion is actually negligible at end of drag
parent
1dc2b604e2
commit
61e019ac26
|
@ -2,6 +2,7 @@
|
|||
/// Sourced from - http://forum.unity3d.com/threads/scripts-useful-4-6-scripts-collection.264161/page-2#post-1945602
|
||||
/// Updated by ddreaper - removed dependency on a custom ScrollRect script. Now implements drag interfaces and standard Scroll Rect.
|
||||
|
||||
using System;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace UnityEngine.UI.Extensions
|
||||
|
@ -245,6 +246,12 @@ namespace UnityEngine.UI.Extensions
|
|||
_pointerDown = false;
|
||||
|
||||
if (_scroll_rect.horizontal)
|
||||
{
|
||||
if (UseSwipeDeltaThreshold && Math.Abs(eventData.delta.x) < SwipeDeltaThreshold)
|
||||
{
|
||||
ScrollToClosestElement();
|
||||
}
|
||||
else
|
||||
{
|
||||
var distance = Vector3.Distance(_startPosition, _screensContainer.localPosition);
|
||||
|
||||
|
@ -299,6 +306,7 @@ namespace UnityEngine.UI.Extensions
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
|
|
@ -70,12 +70,18 @@ namespace UnityEngine.UI.Extensions
|
|||
[Tooltip("Fast Swipe makes swiping page next / previous (optional)")]
|
||||
public Boolean UseFastSwipe = false;
|
||||
|
||||
[Tooltip("Swipe Delta Threshold looks at the speed of input to decide if a swipe will be initiated (optional)")]
|
||||
public Boolean UseSwipeDeltaThreshold = false;
|
||||
|
||||
[Tooltip("Offset for how far a swipe has to travel to initiate a page change (optional)")]
|
||||
public int FastSwipeThreshold = 100;
|
||||
|
||||
[Tooltip("Speed at which the ScrollRect will keep scrolling before slowing down and stopping (optional)")]
|
||||
public int SwipeVelocityThreshold = 100;
|
||||
|
||||
[Tooltip("Threshold for swipe speed to initiate a swipe, below threshold will return to closest page (optional)")]
|
||||
public float SwipeDeltaThreshold = 5.0f;
|
||||
|
||||
[Tooltip("Use time scale instead of unscaled time (optional)")]
|
||||
public Boolean UseTimeScale = true;
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
/// Updated by SimonDarksideJ - removed dependency on a custom ScrollRect script. Now implements drag interfaces and standard Scroll Rect.
|
||||
/// Updated by SimonDarksideJ - major refactoring on updating current position and scroll management
|
||||
|
||||
using System;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace UnityEngine.UI.Extensions
|
||||
|
@ -237,9 +238,16 @@ namespace UnityEngine.UI.Extensions
|
|||
_pointerDown = false;
|
||||
|
||||
if (_scroll_rect.vertical)
|
||||
{
|
||||
if (UseSwipeDeltaThreshold && Math.Abs(eventData.delta.y) < SwipeDeltaThreshold)
|
||||
{
|
||||
ScrollToClosestElement();
|
||||
}
|
||||
else
|
||||
{
|
||||
var distance = Vector3.Distance(_startPosition, _screensContainer.localPosition);
|
||||
if(UseHardSwipe){
|
||||
if (UseHardSwipe)
|
||||
{
|
||||
_scroll_rect.velocity = Vector3.zero;
|
||||
|
||||
if (distance > FastSwipeThreshold)
|
||||
|
@ -289,6 +297,7 @@ namespace UnityEngine.UI.Extensions
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue