From 3d39d1da4796cdbfa0f904a0c4f0dc96ec46ac0c Mon Sep 17 00:00:00 2001 From: "Simon (darkside) Jackson" Date: Tue, 17 May 2016 22:37:01 +0100 Subject: [PATCH] Updated Vertical and Horrizontal Scroll Snaps controls to include: * Tranisition speed * Starting page * Page Snap size (to control distribution of pages) Resolves requested issues / fixes --HG-- branch : develop_5.3 --- Scripts/Layout/HorizontalScrollSnap.cs | 109 +++++++++++++------------ Scripts/Layout/UIVerticalScroller.cs | 2 +- Scripts/Layout/VerticalScrollSnap.cs | 69 ++++++++++------ Scripts/ToolTips/HoverTooltip.cs | 2 +- Scripts/ToolTips/ToolTip.cs | 2 +- 5 files changed, 105 insertions(+), 79 deletions(-) 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