From d604582279c2aa6319f096bf30be24316a5abbd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C4=B9=E2=80=9A=20Kapalla?= Date: Sat, 17 Oct 2015 23:06:09 +0200 Subject: [PATCH] added ability to open page by index from code --HG-- branch : xesenix_upgrades --- Scripts/Layout/ScrollSnap.cs | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/Scripts/Layout/ScrollSnap.cs b/Scripts/Layout/ScrollSnap.cs index ff193e3..0b311fb 100644 --- a/Scripts/Layout/ScrollSnap.cs +++ b/Scripts/Layout/ScrollSnap.cs @@ -117,7 +117,7 @@ namespace UnityEngine.UI.Extensions UpdateListItemsSize(); UpdateListItemPositions(); - ChangePage(CurrentPage()); + PageChanged(CurrentPage()); if (nextButton) { @@ -280,7 +280,7 @@ namespace UnityEngine.UI.Extensions if (itemsCount != activeCount) { - ChangePage(CurrentPage()); + PageChanged(CurrentPage()); } itemsCount = activeCount; @@ -363,7 +363,7 @@ namespace UnityEngine.UI.Extensions //change the info bullets at the bottom of the screen. Just for visual effect if (Vector3.Distance(listContainerTransform.localPosition, lerpTarget) < 10f) { - ChangePage(CurrentPage()); + PageChanged(CurrentPage()); } } @@ -388,7 +388,7 @@ namespace UnityEngine.UI.Extensions lerp = true; lerpTarget = pageAnchorPositions[CurrentPage() + 1]; - ChangePage(CurrentPage() + 1); + PageChanged(CurrentPage() + 1); } } @@ -402,7 +402,7 @@ namespace UnityEngine.UI.Extensions lerp = true; lerpTarget = pageAnchorPositions[CurrentPage() - 1]; - ChangePage(CurrentPage() - 1); + PageChanged(CurrentPage() - 1); } } @@ -416,7 +416,7 @@ namespace UnityEngine.UI.Extensions lerpTarget = pageAnchorPositions[targetPage]; - ChangePage(targetPage); + PageChanged(targetPage); } } @@ -430,7 +430,7 @@ namespace UnityEngine.UI.Extensions lerpTarget = pageAnchorPositions[targetPage]; - ChangePage(targetPage); + PageChanged(targetPage); } } @@ -458,8 +458,20 @@ namespace UnityEngine.UI.Extensions return Mathf.Clamp(Mathf.RoundToInt(page), 0, pages); } + public void ChangePage(int page) + { + if (0 <= page && page < pages) + { + lerp = true; + + lerpTarget = pageAnchorPositions[page]; + + PageChanged(page); + } + } + //changes the bullets on the bottom of the page - pagination - private void ChangePage(int currentPage) + private void PageChanged(int currentPage) { startingPage = currentPage;