/// 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; using UnityEngine.EventSystems; using UnityEngine.UI; [RequireComponent(typeof(ScrollRect))] public class HorizontalScrollSnap : MonoBehaviour, IBeginDragHandler, IEndDragHandler, IDragHandler { private Transform _screensContainer; private int _screens = 1; private int _startingScreen = 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; private int _containerSize; [Tooltip("The gameobject that contains toggles which suggest pagination. THIS CAN BE MISSING")] 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; public Boolean UseFastSwipe = true; public int FastSwipeThreshold = 100; private bool _startDrag = true; private Vector3 _startPosition = new Vector3(); private int _currentScreen; // Use this for initialization void Start() { _scroll_rect = gameObject.GetComponent(); _screensContainer = _scroll_rect.content; DistributePages(); _screens = _screensContainer.childCount; _lerp = false; _positions = new System.Collections.Generic.List(); if (_screens > 0) { for (int i = 0; i < _screens; ++i) { _scroll_rect.horizontalNormalizedPosition = (float)i / (float)(_screens - 1); _positions.Add(_screensContainer.localPosition); } } _scroll_rect.horizontalNormalizedPosition = (float)(_startingScreen - 1) / (float)(_screens - 1); _containerSize = (int)_screensContainer.gameObject.GetComponent().offsetMax.x; ChangeBulletsInfo(CurrentScreen()); if (NextButton) NextButton.GetComponent