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.3
pull/413/head
Simon Jackson 2017-01-04 13:18:28 +00:00
parent 38d98a0fad
commit 344ca57f4b
3 changed files with 28 additions and 22 deletions

View File

@ -43,19 +43,22 @@ namespace UnityEngine.UI.Extensions
} }
CurrentPage = GetPageforPosition(_screensContainer.localPosition); CurrentPage = GetPageforPosition(_screensContainer.localPosition);
//If the container is moving check if it needs to settle on a page //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 (_scroll_rect.velocity.x > 0.01 || _scroll_rect.velocity.x < 0.01)
if (IsRectMovingFasterThanThreshold(0))
{ {
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) || return (_scroll_rect.velocity.x > startingSpeed && _scroll_rect.velocity.x < SwipeVelocityThreshold) ||
(_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> /// <param name="eventData"></param>
public void OnEndDrag(PointerEventData eventData) public void OnEndDrag(PointerEventData eventData)
{ {
_pointerDown = false;
if (_scroll_rect.horizontal) if (_scroll_rect.horizontal)
{ {
if (UseFastSwipe) if (UseFastSwipe)

View File

@ -4,7 +4,7 @@ using UnityEngine.EventSystems;
namespace UnityEngine.UI.Extensions namespace UnityEngine.UI.Extensions
{ {
public class ScrollSnapBase : MonoBehaviour, IBeginDragHandler, IDragHandler, IPointerDownHandler, IPointerUpHandler public class ScrollSnapBase : MonoBehaviour, IBeginDragHandler, IDragHandler
{ {
internal RectTransform _screensContainer; internal RectTransform _screensContainer;
internal bool _isVertical; internal bool _isVertical;
@ -404,6 +404,7 @@ namespace UnityEngine.UI.Extensions
/// <param name="eventData"></param> /// <param name="eventData"></param>
public void OnBeginDrag(PointerEventData eventData) public void OnBeginDrag(PointerEventData eventData)
{ {
_pointerDown = true;
_settled = false; _settled = false;
StartScreenChange(); StartScreenChange();
_startPosition = _screensContainer.localPosition; _startPosition = _screensContainer.localPosition;
@ -418,15 +419,6 @@ namespace UnityEngine.UI.Extensions
_lerp = false; _lerp = false;
} }
public void OnPointerDown(PointerEventData eventData)
{
_pointerDown = true;
}
public void OnPointerUp(PointerEventData eventData)
{
_pointerDown = false;
}
#endregion #endregion
} }
} }

View File

@ -45,16 +45,23 @@ namespace UnityEngine.UI.Extensions
CurrentPage = GetPageforPosition(_screensContainer.localPosition); CurrentPage = GetPageforPosition(_screensContainer.localPosition);
//If the container is moving check if it needs to settle on a page //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.01 || _scroll_rect.velocity.y < -0.01)
if ((_scroll_rect.velocity.y > 0 && _scroll_rect.velocity.y < SwipeVelocityThreshold) || {
(_scroll_rect.velocity.y < 0 && _scroll_rect.velocity.y > -SwipeVelocityThreshold)) // if the pointer is released and is moving slower than the threshold, then just land on a page
{ if (IsRectMovingSlowerThanThreshold(0))
ScrollToClosestElement(); {
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() public void DistributePages()
@ -191,6 +198,8 @@ namespace UnityEngine.UI.Extensions
/// <param name="eventData"></param> /// <param name="eventData"></param>
public void OnEndDrag(PointerEventData eventData) public void OnEndDrag(PointerEventData eventData)
{ {
_pointerDown = false;
if (_scroll_rect.vertical) if (_scroll_rect.vertical)
{ {
if (UseFastSwipe) if (UseFastSwipe)