Updated HSS/VSS to include a new HARD swipe option. Forces scroll snap to ONLy move one page when swiped.

pull/413/head
Simon (Darkside) Jackson 2018-03-24 15:36:38 +00:00
parent 6a4256738a
commit 104002eaa5
5 changed files with 830 additions and 927 deletions

File diff suppressed because it is too large Load Diff

View File

@ -150,8 +150,8 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 225.10002, y: -99.100006}
m_SizeDelta: {x: -496.4, y: -233.4}
m_AnchoredPosition: {x: 298, y: -155.1}
m_SizeDelta: {x: -642.3, y: -345.4}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &2641525
MonoBehaviour:

View File

@ -239,13 +239,26 @@ namespace UnityEngine.UI.Extensions
if (_scroll_rect.horizontal)
{
var distance = Vector3.Distance(_startPosition, _screensContainer.localPosition);
if (UseFastSwipe && distance < panelDimensions.width && distance >= FastSwipeThreshold)
if ((UseFastSwipe && distance < panelDimensions.width && distance >= FastSwipeThreshold) || UseHardSwipe)
{
_scroll_rect.velocity = Vector3.zero;
if (_startPosition.x - _screensContainer.localPosition.x > 0)
{
if (_startPosition.x - _screensContainer.localPosition.x > _childSize / 3)
{
ScrollToClosestElement();
}
else
{
NextScreen();
}
}
else
{
if (_startPosition.x - _screensContainer.localPosition.x > -_childSize / 3)
{
ScrollToClosestElement();
}
else
{
PreviousScreen();
@ -253,6 +266,7 @@ namespace UnityEngine.UI.Extensions
}
}
}
}
#endregion
}
}

View File

@ -31,7 +31,7 @@ namespace UnityEngine.UI.Extensions
internal int _previousPage;
internal int _halfNoVisibleItems;
internal bool _moveStarted;
internal bool _isInfinate; // Is a UI Infinate scroller attached to the control
internal bool _isInfinate; // Is a UI Infinite scroller attached to the control
internal int _infiniteWindow; // The infinite window the control is in
internal float _infiniteOffset; // How much to offset a repositioning
private int _bottomItem, _topItem;
@ -64,6 +64,9 @@ namespace UnityEngine.UI.Extensions
[Tooltip("Transition speed between pages. (optional)")]
public float transitionSpeed = 7.5f;
[Tooltip("Hard Swipe forces to swiping to the next / previous page (optional)")]
public Boolean UseHardSwipe = false;
[Tooltip("Fast Swipe makes swiping page next / previous (optional)")]
public Boolean UseFastSwipe = false;
@ -76,7 +79,7 @@ namespace UnityEngine.UI.Extensions
[Tooltip("The visible bounds area, controls which items are visible/enabled. *Note Should use a RectMask. (optional)")]
public RectTransform MaskArea;
[Tooltip("Pixel size to buffer arround Mask Area. (optional)")]
[Tooltip("Pixel size to buffer around Mask Area. (optional)")]
public float MaskBuffer = 1;
public int CurrentPage
@ -90,7 +93,7 @@ namespace UnityEngine.UI.Extensions
{
if (_isInfinate)
{
//Work out which infinate window we are in
//Work out which infinite window we are in
_infiniteWindow = value / _screensContainer.childCount;
//Invert the value if negative and differentiate from Window 0
_infiniteWindow = value < 0 ? (-_infiniteWindow) + 1 : _infiniteWindow;
@ -417,7 +420,7 @@ namespace UnityEngine.UI.Extensions
/// <param name="targetScreen"></param>
private void ToggleNavigationButtons(int targetScreen)
{
//Ifthis is using an Infinate Scoll, then don't disable
//If this is using an Infinite Scroll, then don't disable
if (!_isInfinate)
{
if (PrevButton)
@ -509,7 +512,7 @@ namespace UnityEngine.UI.Extensions
}
/// <summary>
/// Returns the Transform of the Currentpage
/// Returns the Transform of the Current page
/// </summary>
/// <returns>Currently selected Page Transform</returns>
public Transform CurrentPageObject()
@ -518,7 +521,7 @@ namespace UnityEngine.UI.Extensions
}
/// <summary>
/// Returns the Transform of the Currentpage in an out param for performance
/// Returns the Transform of the Current page in an out parameter for performance
/// </summary>
/// <param name="returnObject">Currently selected Page Transform</param>
public void CurrentPageObject(out Transform returnObject)

View File

@ -239,13 +239,26 @@ namespace UnityEngine.UI.Extensions
if (_scroll_rect.vertical)
{
var distance = Vector3.Distance(_startPosition, _screensContainer.localPosition);
if (UseFastSwipe && distance < panelDimensions.height + FastSwipeThreshold && distance >=1f)
if ((UseFastSwipe && distance < panelDimensions.height + FastSwipeThreshold && distance >=1f) || UseHardSwipe)
{
_scroll_rect.velocity = Vector3.zero;
if (_startPosition.y - _screensContainer.localPosition.y > 0)
{
if (_startPosition.y - _screensContainer.localPosition.y > _childSize / 3)
{
ScrollToClosestElement();
}
else
{
NextScreen();
}
}
else
{
if (_startPosition.y - _screensContainer.localPosition.y > -_childSize / 3)
{
ScrollToClosestElement();
}
else
{
PreviousScreen();
@ -253,6 +266,7 @@ namespace UnityEngine.UI.Extensions
}
}
}
}
#endregion
}
}