diff --git a/Scripts/Layout/ScrollSnapBase.cs b/Scripts/Layout/ScrollSnapBase.cs index 44867e3..336777f 100644 --- a/Scripts/Layout/ScrollSnapBase.cs +++ b/Scripts/Layout/ScrollSnapBase.cs @@ -31,7 +31,10 @@ namespace UnityEngine.UI.Extensions internal int _previousPage; internal int _halfNoVisibleItems; internal bool _moveStarted; - private int _bottomItem, _topItem; + internal bool _isInfinate; // Is a UI Infinate 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; [Serializable] public class SelectionChangeStartEvent : UnityEvent { } @@ -85,6 +88,25 @@ namespace UnityEngine.UI.Extensions internal set { + if (_isInfinate) + { + //Work out which infinate window we are in + _infiniteWindow = value / _screensContainer.childCount; + //Invert the value if negative and differentiate from Window 0 + _infiniteWindow = value < 0 ? (-_infiniteWindow) + 1 : _infiniteWindow; + //Multiplying values by zero doesn't help, so start at Window 1 + //_infiniteWindow += 1; + //Calculate the page within the child count range + value = value % _screensContainer.childCount; + if (value < 0) + { + value = _screensContainer.childCount + value; + } + else if (value > _screensContainer.childCount - 1) + { + value = value - _screensContainer.childCount; + } + } if ((value != _currentPage && value >= 0 && value < _screensContainer.childCount) || (value == 0 && _screensContainer.childCount == 0)) { _previousPage = _currentPage; @@ -156,6 +178,8 @@ namespace UnityEngine.UI.Extensions if (PrevButton) PrevButton.GetComponent