diff --git a/Scripts/Layout/HorizontalScrollSnap.cs b/Scripts/Layout/HorizontalScrollSnap.cs index aecfef3..e94150a 100644 --- a/Scripts/Layout/HorizontalScrollSnap.cs +++ b/Scripts/Layout/HorizontalScrollSnap.cs @@ -7,6 +7,7 @@ using UnityEngine.EventSystems; namespace UnityEngine.UI.Extensions { + [RequireComponent(typeof(ScrollRect))] [AddComponentMenu("Layout/Extensions/Horizontal Scroll Snap")] public class HorizontalScrollSnap : MonoBehaviour, IBeginDragHandler, IEndDragHandler, IDragHandler @@ -14,7 +15,6 @@ namespace UnityEngine.UI.Extensions private Transform _screensContainer; private int _screens = 1; - private int _startingScreen = 2; private bool _fastSwipeTimer = false; private int _fastSwipeCounter = 0; @@ -28,31 +28,6 @@ namespace UnityEngine.UI.Extensions private int _containerSize; - public int StartingScreen - { - get - { - return _startingScreen; - } - set - { - if (_startingScreen == value) - return; - if (value < _screens) - { - _startingScreen = 1; - } - else if (value > _screens) - { - _startingScreen = transform.childCount; - } - else - { - _startingScreen = value; - } - } - } - [Tooltip("The gameobject that contains toggles which suggest pagination. (optional)")] public GameObject Pagination; @@ -70,11 +45,20 @@ namespace UnityEngine.UI.Extensions private Vector3 _startPosition = new Vector3(); private int _currentScreen; + public int StartingScreen = 1; + public int PageStep = 0; + + + // Use this for initialization void Start() { _scroll_rect = gameObject.GetComponent(); _screensContainer = _scroll_rect.content; + if (PageStep == 0) + { + PageStep = (int)_scroll_rect.GetComponent().rect.width * 3; + } DistributePages(); _screens = _screensContainer.childCount; @@ -85,18 +69,18 @@ namespace UnityEngine.UI.Extensions if (_screens > 0) { - for (int i = 0; i < _screens; ++i) + for (float i = 0; i < _screens; ++i) { - _scroll_rect.horizontalNormalizedPosition = (float)i / (float)(_screens - 1); + _scroll_rect.horizontalNormalizedPosition = i / (_screens - 1); _positions.Add(_screensContainer.localPosition); } } - _scroll_rect.horizontalNormalizedPosition = (float)(_startingScreen - 1) / (_screens - 1); + _scroll_rect.horizontalNormalizedPosition = (float)(StartingScreen - 1) / (_screens - 1); _containerSize = (int)_screensContainer.gameObject.GetComponent().offsetMax.x; - ChangeBulletsInfo(CurrentScreen()); + ChangeBulletsInfo(_currentScreen); if (NextButton) NextButton.GetComponent