From 1f16a65f0fda9420ff572aa1f6d57396d080d0a3 Mon Sep 17 00:00:00 2001 From: Simon Jackson Date: Sat, 12 Aug 2017 10:24:25 +0100 Subject: [PATCH] Some realignment of the H&S ScrollSnap Scripts Resolves #160 --- Scripts/Layout/HorizontalScrollSnap.cs | 10 +++++----- Scripts/Layout/VerticalScrollSnap.cs | 3 +-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Scripts/Layout/HorizontalScrollSnap.cs b/Scripts/Layout/HorizontalScrollSnap.cs index f241dc5..43b2c0d 100644 --- a/Scripts/Layout/HorizontalScrollSnap.cs +++ b/Scripts/Layout/HorizontalScrollSnap.cs @@ -66,21 +66,21 @@ namespace UnityEngine.UI.Extensions (_scroll_rect.velocity.x < startingSpeed && _scroll_rect.velocity.x > -SwipeVelocityThreshold); } - private void DistributePages() + public void DistributePages() { _screens = _screensContainer.childCount; _scroll_rect.horizontalNormalizedPosition = 0; - int _offset = 0; + float _offset = 0; float _dimension = 0; + Rect panelDimensions = gameObject.GetComponent().rect; float currentXPosition = 0; var pageStepValue = _childSize = (int)panelDimensions.width * ((PageStep == 0) ? 3 : PageStep); - for (int i = 0; i < _screensContainer.transform.childCount; i++) { RectTransform child = _screensContainer.transform.GetChild(i).gameObject.GetComponent(); - currentXPosition = _offset + (int)(i * pageStepValue); + currentXPosition = _offset + i * pageStepValue; child.sizeDelta = new Vector2(panelDimensions.width, panelDimensions.height); child.anchoredPosition = new Vector2(currentXPosition, 0f); child.anchorMin = child.anchorMax = child.pivot = _childAnchorPoint; @@ -88,7 +88,7 @@ namespace UnityEngine.UI.Extensions _dimension = currentXPosition + _offset * -1; - _screensContainer.offsetMax = new Vector2(_dimension, 0f); + _screensContainer.GetComponent().offsetMax = new Vector2(_dimension, 0f); } /// diff --git a/Scripts/Layout/VerticalScrollSnap.cs b/Scripts/Layout/VerticalScrollSnap.cs index 762a115..d6815ec 100644 --- a/Scripts/Layout/VerticalScrollSnap.cs +++ b/Scripts/Layout/VerticalScrollSnap.cs @@ -121,7 +121,7 @@ namespace UnityEngine.UI.Extensions /// *Note, this is an index address (0-x) /// /// Index element of child to remove - /// >Resulting removed GO + /// Resulting removed GO public void RemoveChild(int index, out GameObject ChildRemoved) { RemoveChild(index, false, out ChildRemoved); @@ -158,7 +158,6 @@ namespace UnityEngine.UI.Extensions SetScrollContainerPosition(); } - /// /// Remove all children from this ScrollSnap ///