Tested locally and seems to work as expected. Thanks for the update.

Merged in johannski/unity-ui-extensions/ScrollSnapRefactoring (pull request #14)

ScrollSnapRefactoring
pull/413/head
Johannes Deml 2017-08-02 16:19:43 +00:00 committed by Simon Jackson
commit e7406318c9
2 changed files with 5 additions and 5 deletions

View File

@ -238,7 +238,7 @@ namespace UnityEngine.UI.Extensions
if (_scroll_rect.horizontal) if (_scroll_rect.horizontal)
{ {
var distance = Vector3.Distance(_startPosition, _screensContainer.localPosition); var distance = Vector3.Distance(_startPosition, _screensContainer.localPosition);
if (UseFastSwipe && distance < panelDimensions.width + FastSwipeThreshold && distance >=1f) if (UseFastSwipe && distance < panelDimensions.width && distance >= FastSwipeThreshold)
{ {
_scroll_rect.velocity = Vector3.zero; _scroll_rect.velocity = Vector3.zero;
if (_startPosition.x - _screensContainer.localPosition.x > 0) if (_startPosition.x - _screensContainer.localPosition.x > 0)
@ -252,6 +252,6 @@ namespace UnityEngine.UI.Extensions
} }
} }
} }
#endregion #endregion
} }
} }

View File

@ -64,7 +64,7 @@ namespace UnityEngine.UI.Extensions
[Tooltip("Fast Swipe makes swiping page next / previous (optional)")] [Tooltip("Fast Swipe makes swiping page next / previous (optional)")]
public Boolean UseFastSwipe = false; public Boolean UseFastSwipe = false;
[Tooltip("Offset for how far a swipe has to travel to initiate a page change (optional)\nDefault is the panel dimensions")] [Tooltip("Offset for how far a swipe has to travel to initiate a page change (optional)")]
public int FastSwipeThreshold = 100; public int FastSwipeThreshold = 100;
[Tooltip("Speed at which the ScrollRect will keep scrolling before slowing down and stopping (optional)")] [Tooltip("Speed at which the ScrollRect will keep scrolling before slowing down and stopping (optional)")]
@ -314,8 +314,8 @@ namespace UnityEngine.UI.Extensions
internal int GetPageforPosition(Vector3 pos) internal int GetPageforPosition(Vector3 pos)
{ {
return _isVertical ? return _isVertical ?
-(int)Math.Round((pos.y - _scrollStartPosition) / _childSize) : (int)Math.Round((_scrollStartPosition - pos.y) / _childSize) :
-(int)Math.Round((pos.x - _scrollStartPosition) / _childSize); (int)Math.Round((_scrollStartPosition - pos.x) / _childSize);
} }
/// <summary> /// <summary>