Merged in larsme/unity-ui-extensions/corrected_sign_for_horizontal_scrollsnap_left_fast_swipe (pull request #45)

corrected sign for horizontal scrollsnap left fast swipe

Approved-by: Simon Jackson <darkside@xna-uk.net>
pull/413/head
lars me 2019-02-25 15:00:23 +00:00 committed by Simon Jackson
commit 50a810ba42
1 changed files with 20 additions and 10 deletions

View File

@ -111,7 +111,8 @@ namespace UnityEngine.UI.Extensions
GO.transform.SetParent(_screensContainer, WorldPositionStays); GO.transform.SetParent(_screensContainer, WorldPositionStays);
InitialiseChildObjectsFromScene(); InitialiseChildObjectsFromScene();
DistributePages(); DistributePages();
if (MaskArea) UpdateVisible(); if (MaskArea)
UpdateVisible();
SetScrollContainerPosition(); SetScrollContainerPosition();
} }
@ -148,7 +149,8 @@ namespace UnityEngine.UI.Extensions
ChildRemoved = child.gameObject; ChildRemoved = child.gameObject;
InitialiseChildObjectsFromScene(); InitialiseChildObjectsFromScene();
DistributePages(); DistributePages();
if (MaskArea) UpdateVisible(); if (MaskArea)
UpdateVisible();
if (_currentPage > _screens - 1) if (_currentPage > _screens - 1)
{ {
@ -187,7 +189,8 @@ namespace UnityEngine.UI.Extensions
CurrentPage = 0; CurrentPage = 0;
InitialiseChildObjectsFromScene(); InitialiseChildObjectsFromScene();
DistributePages(); DistributePages();
if (MaskArea) UpdateVisible(); if (MaskArea)
UpdateVisible();
} }
private void SetScrollContainerPosition() private void SetScrollContainerPosition()
@ -204,7 +207,8 @@ namespace UnityEngine.UI.Extensions
{ {
_lerp = false; _lerp = false;
DistributePages(); DistributePages();
if (MaskArea) UpdateVisible(); if (MaskArea)
UpdateVisible();
SetScrollContainerPosition(); SetScrollContainerPosition();
OnCurrentScreenChange(_currentPage); OnCurrentScreenChange(_currentPage);
} }
@ -221,13 +225,17 @@ namespace UnityEngine.UI.Extensions
{ {
InitialiseChildObjectsFromScene(); InitialiseChildObjectsFromScene();
DistributePages(); DistributePages();
if (MaskArea) UpdateVisible(); if (MaskArea)
UpdateVisible();
if (JumpOnEnable || !RestartOnEnable) SetScrollContainerPosition(); if (JumpOnEnable || !RestartOnEnable)
if (RestartOnEnable) GoToScreen(StartingScreen); SetScrollContainerPosition();
if (RestartOnEnable)
GoToScreen(StartingScreen);
} }
#region Interfaces #region Interfaces
/// <summary> /// <summary>
/// Release screen to swipe /// Release screen to swipe
/// </summary> /// </summary>
@ -240,7 +248,8 @@ namespace UnityEngine.UI.Extensions
{ {
var distance = Vector3.Distance(_startPosition, _screensContainer.localPosition); var distance = Vector3.Distance(_startPosition, _screensContainer.localPosition);
if(UseHardSwipe){ if (UseHardSwipe)
{
_scroll_rect.velocity = Vector3.zero; _scroll_rect.velocity = Vector3.zero;
if (distance > FastSwipeThreshold) if (distance > FastSwipeThreshold)
@ -261,7 +270,7 @@ namespace UnityEngine.UI.Extensions
} }
else else
{ {
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.localPosition.x > 0)
@ -277,7 +286,7 @@ namespace UnityEngine.UI.Extensions
} }
else else
{ {
if (_startPosition.x - _screensContainer.localPosition.x > -_childSize / 3) if (_startPosition.x - _screensContainer.localPosition.x < -_childSize / 3)
{ {
ScrollToClosestElement(); ScrollToClosestElement();
} }
@ -290,6 +299,7 @@ namespace UnityEngine.UI.Extensions
} }
} }
} }
#endregion #endregion
} }
} }