Updated VSS / HSS to handle pages with interactable components.
Interactables mess with the Pointer Down/Up events that the control used when a mouse is used, so implementation changes to suit. --HG-- branch : develop_5.3release
parent
38d98a0fad
commit
344ca57f4b
|
@ -45,17 +45,20 @@ namespace UnityEngine.UI.Extensions
|
|||
CurrentPage = GetPageforPosition(_screensContainer.localPosition);
|
||||
|
||||
//If the container is moving check if it needs to settle on a page
|
||||
if (!_pointerDown && (_scroll_rect.velocity.x > 0.01 || _scroll_rect.velocity.x < 0.01))
|
||||
if (!_pointerDown)
|
||||
{
|
||||
// if the pointer is released and is moving slower than the threshold, then just land on a page
|
||||
if (IsRectMovingFasterThanThreshold(0))
|
||||
if (_scroll_rect.velocity.x > 0.01 || _scroll_rect.velocity.x < 0.01)
|
||||
{
|
||||
ScrollToClosestElement();
|
||||
//if the pointer is released and is moving slower than the threshold, then just land on a page
|
||||
if (IsRectMovingSlowerThanThreshold(0))
|
||||
{
|
||||
ScrollToClosestElement();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsRectMovingFasterThanThreshold(float startingSpeed)
|
||||
private bool IsRectMovingSlowerThanThreshold(float startingSpeed)
|
||||
{
|
||||
return (_scroll_rect.velocity.x > startingSpeed && _scroll_rect.velocity.x < SwipeVelocityThreshold) ||
|
||||
(_scroll_rect.velocity.x < startingSpeed && _scroll_rect.velocity.x > -SwipeVelocityThreshold);
|
||||
|
@ -195,6 +198,8 @@ namespace UnityEngine.UI.Extensions
|
|||
/// <param name="eventData"></param>
|
||||
public void OnEndDrag(PointerEventData eventData)
|
||||
{
|
||||
_pointerDown = false;
|
||||
|
||||
if (_scroll_rect.horizontal)
|
||||
{
|
||||
if (UseFastSwipe)
|
||||
|
|
|
@ -4,7 +4,7 @@ using UnityEngine.EventSystems;
|
|||
|
||||
namespace UnityEngine.UI.Extensions
|
||||
{
|
||||
public class ScrollSnapBase : MonoBehaviour, IBeginDragHandler, IDragHandler, IPointerDownHandler, IPointerUpHandler
|
||||
public class ScrollSnapBase : MonoBehaviour, IBeginDragHandler, IDragHandler
|
||||
{
|
||||
internal RectTransform _screensContainer;
|
||||
internal bool _isVertical;
|
||||
|
@ -404,6 +404,7 @@ namespace UnityEngine.UI.Extensions
|
|||
/// <param name="eventData"></param>
|
||||
public void OnBeginDrag(PointerEventData eventData)
|
||||
{
|
||||
_pointerDown = true;
|
||||
_settled = false;
|
||||
StartScreenChange();
|
||||
_startPosition = _screensContainer.localPosition;
|
||||
|
@ -418,15 +419,6 @@ namespace UnityEngine.UI.Extensions
|
|||
_lerp = false;
|
||||
}
|
||||
|
||||
public void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
_pointerDown = true;
|
||||
}
|
||||
|
||||
public void OnPointerUp(PointerEventData eventData)
|
||||
{
|
||||
_pointerDown = false;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -45,16 +45,23 @@ namespace UnityEngine.UI.Extensions
|
|||
CurrentPage = GetPageforPosition(_screensContainer.localPosition);
|
||||
|
||||
//If the container is moving check if it needs to settle on a page
|
||||
if (!_pointerDown && (_scroll_rect.velocity.y > 0.01 || _scroll_rect.velocity.y < -0.01))
|
||||
if (!_pointerDown)
|
||||
{
|
||||
// if the pointer is released and is moving slower than the threshold, then just land on a page
|
||||
if ((_scroll_rect.velocity.y > 0 && _scroll_rect.velocity.y < SwipeVelocityThreshold) ||
|
||||
(_scroll_rect.velocity.y < 0 && _scroll_rect.velocity.y > -SwipeVelocityThreshold))
|
||||
{
|
||||
ScrollToClosestElement();
|
||||
if (_scroll_rect.velocity.y > 0.01 || _scroll_rect.velocity.y < -0.01)
|
||||
{
|
||||
// if the pointer is released and is moving slower than the threshold, then just land on a page
|
||||
if (IsRectMovingSlowerThanThreshold(0))
|
||||
{
|
||||
ScrollToClosestElement();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsRectMovingSlowerThanThreshold(float startingSpeed)
|
||||
{
|
||||
return (_scroll_rect.velocity.y > startingSpeed && _scroll_rect.velocity.y < SwipeVelocityThreshold) ||
|
||||
(_scroll_rect.velocity.y < startingSpeed && _scroll_rect.velocity.y > -SwipeVelocityThreshold);
|
||||
}
|
||||
|
||||
public void DistributePages()
|
||||
|
@ -191,6 +198,8 @@ namespace UnityEngine.UI.Extensions
|
|||
/// <param name="eventData"></param>
|
||||
public void OnEndDrag(PointerEventData eventData)
|
||||
{
|
||||
_pointerDown = false;
|
||||
|
||||
if (_scroll_rect.vertical)
|
||||
{
|
||||
if (UseFastSwipe)
|
||||
|
|
Loading…
Reference in New Issue