added ability to open page by index from code

--HG--
branch : xesenix_upgrades
release
Paweł Kapalla 2015-10-17 23:06:09 +02:00
parent 1bb60d72b4
commit d604582279
1 changed files with 20 additions and 8 deletions

View File

@ -117,7 +117,7 @@ namespace UnityEngine.UI.Extensions
UpdateListItemsSize(); UpdateListItemsSize();
UpdateListItemPositions(); UpdateListItemPositions();
ChangePage(CurrentPage()); PageChanged(CurrentPage());
if (nextButton) if (nextButton)
{ {
@ -280,7 +280,7 @@ namespace UnityEngine.UI.Extensions
if (itemsCount != activeCount) if (itemsCount != activeCount)
{ {
ChangePage(CurrentPage()); PageChanged(CurrentPage());
} }
itemsCount = activeCount; itemsCount = activeCount;
@ -363,7 +363,7 @@ namespace UnityEngine.UI.Extensions
//change the info bullets at the bottom of the screen. Just for visual effect //change the info bullets at the bottom of the screen. Just for visual effect
if (Vector3.Distance(listContainerTransform.localPosition, lerpTarget) < 10f) if (Vector3.Distance(listContainerTransform.localPosition, lerpTarget) < 10f)
{ {
ChangePage(CurrentPage()); PageChanged(CurrentPage());
} }
} }
@ -388,7 +388,7 @@ namespace UnityEngine.UI.Extensions
lerp = true; lerp = true;
lerpTarget = pageAnchorPositions[CurrentPage() + 1]; lerpTarget = pageAnchorPositions[CurrentPage() + 1];
ChangePage(CurrentPage() + 1); PageChanged(CurrentPage() + 1);
} }
} }
@ -402,7 +402,7 @@ namespace UnityEngine.UI.Extensions
lerp = true; lerp = true;
lerpTarget = pageAnchorPositions[CurrentPage() - 1]; lerpTarget = pageAnchorPositions[CurrentPage() - 1];
ChangePage(CurrentPage() - 1); PageChanged(CurrentPage() - 1);
} }
} }
@ -416,7 +416,7 @@ namespace UnityEngine.UI.Extensions
lerpTarget = pageAnchorPositions[targetPage]; lerpTarget = pageAnchorPositions[targetPage];
ChangePage(targetPage); PageChanged(targetPage);
} }
} }
@ -430,7 +430,7 @@ namespace UnityEngine.UI.Extensions
lerpTarget = pageAnchorPositions[targetPage]; lerpTarget = pageAnchorPositions[targetPage];
ChangePage(targetPage); PageChanged(targetPage);
} }
} }
@ -458,8 +458,20 @@ namespace UnityEngine.UI.Extensions
return Mathf.Clamp(Mathf.RoundToInt(page), 0, pages); 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 //changes the bullets on the bottom of the page - pagination
private void ChangePage(int currentPage) private void PageChanged(int currentPage)
{ {
startingPage = currentPage; startingPage = currentPage;