From 54488e108924fc54c91e9fafae2707a9d51b8a6c Mon Sep 17 00:00:00 2001 From: "Simon (Darkside) Jackson" Date: Thu, 19 Oct 2017 13:11:09 +0100 Subject: [PATCH] Experimental ScrollSnap base with support for the UI Infinite scroll component * Does not yet work with buttons * GoTo screen not tested New features only activate with a UI Infinite Scroll attached. --- Scripts/Layout/ScrollSnapBase.cs | 54 +++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 11 deletions(-) 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