/// Credit BinaryX /// Sourced from - http://forum.unity3d.com/threads/scripts-useful-4-6-scripts-collection.264161/page-2#post-1945602 /// Updated by ddreaper - removed dependency on a custom ScrollRect script. Now implements drag interfaces and standard Scroll Rect. using System; using UnityEngine.EventSystems; namespace UnityEngine.UI.Extensions { [RequireComponent(typeof(ScrollRect))] [AddComponentMenu("Layout/Extensions/Vertical Scroll Snap")] public class VerticalScrollSnap : MonoBehaviour, IBeginDragHandler, IEndDragHandler, IDragHandler { private Transform _screensContainer; private int _screens = 1; private bool _fastSwipeTimer = false; private int _fastSwipeCounter = 0; private int _fastSwipeTarget = 30; private System.Collections.Generic.List _positions; private ScrollRect _scroll_rect; private Vector3 _lerp_target; private bool _lerp; [Tooltip("The gameobject that contains toggles which suggest pagination. (optional)")] public GameObject Pagination; [Tooltip("Button to go to the next page. (optional)")] public GameObject NextButton; [Tooltip("Button to go to the previous page. (optional)")] public GameObject PrevButton; [Tooltip("Transition speed between pages. (optional)")] public float transitionSpeed = 7.5f; public Boolean UseFastSwipe = true; public int FastSwipeThreshold = 100; private bool _startDrag = true; private Vector3 _startPosition = new Vector3(); [Tooltip("The currently active page")] private int _currentScreen; [Tooltip("The screen / page to start the control on")] [SerializeField] public int StartingScreen = 1; [Tooltip("The distance between two pages, by default 3 times the width of the control")] [SerializeField] public int PageStep = 0; public int CurrentPage { get { return _currentScreen; } } // Use this for initialization void Start() { _scroll_rect = gameObject.GetComponent(); if (_scroll_rect.horizontalScrollbar || _scroll_rect.verticalScrollbar) { Debug.LogWarning("Warning, using scrollbors with the Scroll Snap controls is not advised as it causes unpredictable results"); } _screensContainer = _scroll_rect.content; if (PageStep == 0) { PageStep = (int)_scroll_rect.GetComponent().rect.height * 3; } DistributePages(); _lerp = false; _currentScreen = StartingScreen - 1; _scroll_rect.verticalNormalizedPosition = (float)(_currentScreen) / (float)(_screens - 1); ChangeBulletsInfo(_currentScreen); if (NextButton) NextButton.GetComponent