commit
93fda056a0
|
@ -27,7 +27,7 @@ namespace UnityEngine.UI.Extensions
|
||||||
{
|
{
|
||||||
if (!_settled && !_pointerDown)
|
if (!_settled && !_pointerDown)
|
||||||
{
|
{
|
||||||
if (!IsRectSettledOnaPage(_screensContainer.localPosition))
|
if (!IsRectSettledOnaPage(_screensContainer.anchoredPosition))
|
||||||
{
|
{
|
||||||
ScrollToClosestElement();
|
ScrollToClosestElement();
|
||||||
}
|
}
|
||||||
|
@ -36,16 +36,16 @@ namespace UnityEngine.UI.Extensions
|
||||||
}
|
}
|
||||||
else if (_lerp)
|
else if (_lerp)
|
||||||
{
|
{
|
||||||
_screensContainer.localPosition = Vector3.Lerp(_screensContainer.localPosition, _lerp_target, transitionSpeed * (UseTimeScale ? Time.deltaTime : Time.unscaledDeltaTime));
|
_screensContainer.anchoredPosition = Vector3.Lerp(_screensContainer.anchoredPosition, _lerp_target, transitionSpeed * (UseTimeScale ? Time.deltaTime : Time.unscaledDeltaTime));
|
||||||
if (Vector3.Distance(_screensContainer.localPosition, _lerp_target) < 0.1f)
|
if (Vector3.Distance(_screensContainer.anchoredPosition, _lerp_target) < 0.1f)
|
||||||
{
|
{
|
||||||
_screensContainer.localPosition = _lerp_target;
|
_screensContainer.anchoredPosition = _lerp_target;
|
||||||
_lerp = false;
|
_lerp = false;
|
||||||
EndScreenChange();
|
EndScreenChange();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CurrentPage = GetPageforPosition(_screensContainer.localPosition);
|
CurrentPage = GetPageforPosition(_screensContainer.anchoredPosition);
|
||||||
|
|
||||||
//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)
|
if (!_pointerDown)
|
||||||
|
@ -196,7 +196,7 @@ namespace UnityEngine.UI.Extensions
|
||||||
|
|
||||||
private void SetScrollContainerPosition()
|
private void SetScrollContainerPosition()
|
||||||
{
|
{
|
||||||
_scrollStartPosition = _screensContainer.localPosition.x;
|
_scrollStartPosition = _screensContainer.anchoredPosition.x;
|
||||||
_scroll_rect.horizontalNormalizedPosition = (float)(_currentPage) / (_screens - 1);
|
_scroll_rect.horizontalNormalizedPosition = (float)(_currentPage) / (_screens - 1);
|
||||||
OnCurrentScreenChange(_currentPage);
|
OnCurrentScreenChange(_currentPage);
|
||||||
}
|
}
|
||||||
|
@ -251,7 +251,7 @@ namespace UnityEngine.UI.Extensions
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var distance = Vector3.Distance(_startPosition, _screensContainer.localPosition);
|
var distance = Vector3.Distance(_startPosition, _screensContainer.anchoredPosition);
|
||||||
|
|
||||||
if (UseHardSwipe)
|
if (UseHardSwipe)
|
||||||
{
|
{
|
||||||
|
@ -259,7 +259,7 @@ namespace UnityEngine.UI.Extensions
|
||||||
|
|
||||||
if (distance > FastSwipeThreshold)
|
if (distance > FastSwipeThreshold)
|
||||||
{
|
{
|
||||||
if (_startPosition.x - _screensContainer.localPosition.x > 0)
|
if (_startPosition.x - _screensContainer.anchoredPosition.x > 0)
|
||||||
{
|
{
|
||||||
NextScreen();
|
NextScreen();
|
||||||
}
|
}
|
||||||
|
@ -278,9 +278,9 @@ namespace UnityEngine.UI.Extensions
|
||||||
if (UseFastSwipe && distance < panelDimensions.width && distance >= FastSwipeThreshold)
|
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.anchoredPosition.x > 0)
|
||||||
{
|
{
|
||||||
if (_startPosition.x - _screensContainer.localPosition.x > _childSize / 3)
|
if (_startPosition.x - _screensContainer.anchoredPosition.x > _childSize / 3)
|
||||||
{
|
{
|
||||||
ScrollToClosestElement();
|
ScrollToClosestElement();
|
||||||
}
|
}
|
||||||
|
@ -291,7 +291,7 @@ namespace UnityEngine.UI.Extensions
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (_startPosition.x - _screensContainer.localPosition.x < -_childSize / 3)
|
if (_startPosition.x - _screensContainer.anchoredPosition.x < -_childSize / 3)
|
||||||
{
|
{
|
||||||
ScrollToClosestElement();
|
ScrollToClosestElement();
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ using UnityEngine.EventSystems;
|
||||||
|
|
||||||
namespace UnityEngine.UI.Extensions
|
namespace UnityEngine.UI.Extensions
|
||||||
{
|
{
|
||||||
public class ScrollSnapBase : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler, IScrollSnap
|
public class ScrollSnapBase : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler, IScrollSnap, IPointerClickHandler
|
||||||
{
|
{
|
||||||
internal Rect panelDimensions;
|
internal Rect panelDimensions;
|
||||||
internal RectTransform _screensContainer;
|
internal RectTransform _screensContainer;
|
||||||
|
@ -390,13 +390,13 @@ namespace UnityEngine.UI.Extensions
|
||||||
_childPos = -_childSize * page;
|
_childPos = -_childSize * page;
|
||||||
if (_isVertical)
|
if (_isVertical)
|
||||||
{
|
{
|
||||||
_infiniteOffset = _screensContainer.localPosition.y < 0 ? -_screensContainer.sizeDelta.y * _infiniteWindow : _screensContainer.sizeDelta.y * _infiniteWindow;
|
_infiniteOffset = _screensContainer.anchoredPosition.y < 0 ? -_screensContainer.sizeDelta.y * _infiniteWindow : _screensContainer.sizeDelta.y * _infiniteWindow;
|
||||||
_infiniteOffset = _infiniteOffset == 0 ? 0 : _infiniteOffset < 0 ? _infiniteOffset - _childSize * _infiniteWindow : _infiniteOffset + _childSize * _infiniteWindow;
|
_infiniteOffset = _infiniteOffset == 0 ? 0 : _infiniteOffset < 0 ? _infiniteOffset - _childSize * _infiniteWindow : _infiniteOffset + _childSize * _infiniteWindow;
|
||||||
target.y = _childPos + _scrollStartPosition + _infiniteOffset;
|
target.y = _childPos + _scrollStartPosition + _infiniteOffset;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_infiniteOffset = _screensContainer.localPosition.x < 0 ? -_screensContainer.sizeDelta.x * _infiniteWindow : _screensContainer.sizeDelta.x * _infiniteWindow;
|
_infiniteOffset = _screensContainer.anchoredPosition.x < 0 ? -_screensContainer.sizeDelta.x * _infiniteWindow : _screensContainer.sizeDelta.x * _infiniteWindow;
|
||||||
_infiniteOffset = _infiniteOffset == 0 ? 0 : _infiniteOffset < 0 ? _infiniteOffset - _childSize * _infiniteWindow : _infiniteOffset + _childSize * _infiniteWindow;
|
_infiniteOffset = _infiniteOffset == 0 ? 0 : _infiniteOffset < 0 ? _infiniteOffset - _childSize * _infiniteWindow : _infiniteOffset + _childSize * _infiniteWindow;
|
||||||
target.x = _childPos + _scrollStartPosition + _infiniteOffset;
|
target.x = _childPos + _scrollStartPosition + _infiniteOffset;
|
||||||
}
|
}
|
||||||
|
@ -408,7 +408,7 @@ namespace UnityEngine.UI.Extensions
|
||||||
internal void ScrollToClosestElement()
|
internal void ScrollToClosestElement()
|
||||||
{
|
{
|
||||||
_lerp = true;
|
_lerp = true;
|
||||||
CurrentPage = GetPageforPosition(_screensContainer.localPosition);
|
CurrentPage = GetPageforPosition(_screensContainer.anchoredPosition);
|
||||||
GetPositionforPage(_currentPage, ref _lerp_target);
|
GetPositionforPage(_currentPage, ref _lerp_target);
|
||||||
OnCurrentScreenChange(_currentPage);
|
OnCurrentScreenChange(_currentPage);
|
||||||
}
|
}
|
||||||
|
@ -570,7 +570,7 @@ namespace UnityEngine.UI.Extensions
|
||||||
_pointerDown = true;
|
_pointerDown = true;
|
||||||
_settled = false;
|
_settled = false;
|
||||||
StartScreenChange();
|
StartScreenChange();
|
||||||
_startPosition = _screensContainer.localPosition;
|
_startPosition = _screensContainer.anchoredPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -593,7 +593,7 @@ namespace UnityEngine.UI.Extensions
|
||||||
/// </summary>
|
/// </summary>
|
||||||
int IScrollSnap.CurrentPage()
|
int IScrollSnap.CurrentPage()
|
||||||
{
|
{
|
||||||
return CurrentPage = GetPageforPosition(_screensContainer.localPosition);
|
return CurrentPage = GetPageforPosition(_screensContainer.anchoredPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -612,6 +612,11 @@ namespace UnityEngine.UI.Extensions
|
||||||
GoToScreen(page);
|
GoToScreen(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void OnPointerClick(PointerEventData eventData)
|
||||||
|
{
|
||||||
|
var position = _screensContainer.anchoredPosition;
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ namespace UnityEngine.UI.Extensions
|
||||||
{
|
{
|
||||||
if (!_settled && !_pointerDown)
|
if (!_settled && !_pointerDown)
|
||||||
{
|
{
|
||||||
if (!IsRectSettledOnaPage(_screensContainer.localPosition))
|
if (!IsRectSettledOnaPage(_screensContainer.anchoredPosition))
|
||||||
{
|
{
|
||||||
ScrollToClosestElement();
|
ScrollToClosestElement();
|
||||||
}
|
}
|
||||||
|
@ -36,16 +36,16 @@ namespace UnityEngine.UI.Extensions
|
||||||
}
|
}
|
||||||
else if (_lerp)
|
else if (_lerp)
|
||||||
{
|
{
|
||||||
_screensContainer.localPosition = Vector3.Lerp(_screensContainer.localPosition, _lerp_target, transitionSpeed * (UseTimeScale ? Time.deltaTime : Time.unscaledDeltaTime));
|
_screensContainer.anchoredPosition = Vector3.Lerp(_screensContainer.anchoredPosition, _lerp_target, transitionSpeed * (UseTimeScale ? Time.deltaTime : Time.unscaledDeltaTime));
|
||||||
if (Vector3.Distance(_screensContainer.localPosition, _lerp_target) < 0.1f)
|
if (Vector3.Distance(_screensContainer.anchoredPosition, _lerp_target) < 0.1f)
|
||||||
{
|
{
|
||||||
_screensContainer.localPosition = _lerp_target;
|
_screensContainer.anchoredPosition = _lerp_target;
|
||||||
_lerp = false;
|
_lerp = false;
|
||||||
EndScreenChange();
|
EndScreenChange();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CurrentPage = GetPageforPosition(_screensContainer.localPosition);
|
CurrentPage = GetPageforPosition(_screensContainer.anchoredPosition);
|
||||||
|
|
||||||
//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)
|
if (!_pointerDown)
|
||||||
|
@ -193,7 +193,7 @@ namespace UnityEngine.UI.Extensions
|
||||||
|
|
||||||
private void SetScrollContainerPosition()
|
private void SetScrollContainerPosition()
|
||||||
{
|
{
|
||||||
_scrollStartPosition = _screensContainer.localPosition.y;
|
_scrollStartPosition = _screensContainer.anchoredPosition.y;
|
||||||
_scroll_rect.verticalNormalizedPosition = (float)(_currentPage) / (_screens - 1);
|
_scroll_rect.verticalNormalizedPosition = (float)(_currentPage) / (_screens - 1);
|
||||||
OnCurrentScreenChange(_currentPage);
|
OnCurrentScreenChange(_currentPage);
|
||||||
}
|
}
|
||||||
|
@ -244,14 +244,14 @@ namespace UnityEngine.UI.Extensions
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var distance = Vector3.Distance(_startPosition, _screensContainer.localPosition);
|
var distance = Vector3.Distance(_startPosition, _screensContainer.anchoredPosition);
|
||||||
if (UseHardSwipe)
|
if (UseHardSwipe)
|
||||||
{
|
{
|
||||||
_scroll_rect.velocity = Vector3.zero;
|
_scroll_rect.velocity = Vector3.zero;
|
||||||
|
|
||||||
if (distance > FastSwipeThreshold)
|
if (distance > FastSwipeThreshold)
|
||||||
{
|
{
|
||||||
if (_startPosition.y - _screensContainer.localPosition.y > 0)
|
if (_startPosition.y - _screensContainer.anchoredPosition.y > 0)
|
||||||
{
|
{
|
||||||
NextScreen();
|
NextScreen();
|
||||||
}
|
}
|
||||||
|
@ -270,9 +270,9 @@ namespace UnityEngine.UI.Extensions
|
||||||
if (UseFastSwipe && distance < panelDimensions.height + FastSwipeThreshold && distance >= 1f)
|
if (UseFastSwipe && distance < panelDimensions.height + FastSwipeThreshold && distance >= 1f)
|
||||||
{
|
{
|
||||||
_scroll_rect.velocity = Vector3.zero;
|
_scroll_rect.velocity = Vector3.zero;
|
||||||
if (_startPosition.y - _screensContainer.localPosition.y > 0)
|
if (_startPosition.y - _screensContainer.anchoredPosition.y > 0)
|
||||||
{
|
{
|
||||||
if (_startPosition.y - _screensContainer.localPosition.y > _childSize / 3)
|
if (_startPosition.y - _screensContainer.anchoredPosition.y > _childSize / 3)
|
||||||
{
|
{
|
||||||
ScrollToClosestElement();
|
ScrollToClosestElement();
|
||||||
}
|
}
|
||||||
|
@ -283,7 +283,7 @@ namespace UnityEngine.UI.Extensions
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (_startPosition.y - _screensContainer.localPosition.y > -_childSize / 3)
|
if (_startPosition.y - _screensContainer.anchoredPosition.y > -_childSize / 3)
|
||||||
{
|
{
|
||||||
ScrollToClosestElement();
|
ScrollToClosestElement();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue