Updated H & V scroll snap starting page and button navigation

Updated H & V jump function to only accept values with in page range

--HG--
branch : develop_5.3
pull/413/head
Simon Jackson 2016-11-15 13:36:50 +00:00
parent 55a54816ec
commit cb535507a4
2 changed files with 21 additions and 11 deletions

View File

@ -51,8 +51,7 @@ namespace UnityEngine.UI.Extensions
[Tooltip("The distance between two pages, by default 3 times the width of the control")] [Tooltip("The distance between two pages, by default 3 times the width of the control")]
[SerializeField] [SerializeField]
[Range(0, 8)] public int PageStep = 0;
public float PageStep = 3;
public int CurrentPage public int CurrentPage
{ {
@ -75,13 +74,16 @@ namespace UnityEngine.UI.Extensions
} }
_screensContainer = _scroll_rect.content; _screensContainer = _scroll_rect.content;
PageStep = (int)_scroll_rect.GetComponent<RectTransform>().rect.width * PageStep; if (PageStep == 0)
{
PageStep = (int)_scroll_rect.GetComponent<RectTransform>().rect.width * PageStep;
}
DistributePages(); DistributePages();
_lerp = false; _lerp = false;
_currentScreen = StartingScreen; _currentScreen = StartingScreen - 1;
_scroll_rect.horizontalNormalizedPosition = (float)(_currentScreen - 1) / (_screens - 1); _scroll_rect.horizontalNormalizedPosition = (float)(_currentScreen) / (_screens - 1);
ChangeBulletsInfo(_currentScreen); ChangeBulletsInfo(_currentScreen);
@ -144,10 +146,14 @@ namespace UnityEngine.UI.Extensions
} }
} }
//Function for switching to a specific screen /// <summary>
/// Function for switching to a specific screen
/// *Note, this is based on a 0 starting index - 0 to x
/// </summary>
/// <param name="screenIndex">0 starting index of page to jump to</param>
public void GoToScreen(int screenIndex) public void GoToScreen(int screenIndex)
{ {
if (screenIndex <= _screens && screenIndex >= 0) if (screenIndex <= _screens - 1 && screenIndex >= 0)
{ {
_lerp = true; _lerp = true;
_lerp_target = _positions[screenIndex]; _lerp_target = _positions[screenIndex];

View File

@ -78,9 +78,9 @@ namespace UnityEngine.UI.Extensions
DistributePages(); DistributePages();
_lerp = false; _lerp = false;
_currentScreen = StartingScreen; _currentScreen = StartingScreen - 1;
_scroll_rect.verticalNormalizedPosition = (float)(_currentScreen - 1) / (float)(_screens - 1); _scroll_rect.verticalNormalizedPosition = (float)(_currentScreen) / (float)(_screens - 1);
ChangeBulletsInfo(_currentScreen); ChangeBulletsInfo(_currentScreen);
@ -144,10 +144,14 @@ namespace UnityEngine.UI.Extensions
} }
} }
//Function for switching to a specific screen /// <summary>
/// Function for switching to a specific screen
/// *Note, this is based on a 0 starting index - 0 to x
/// </summary>
/// <param name="screenIndex">0 starting index of page to jump to</param>
public void GoToScreen(int screenIndex) public void GoToScreen(int screenIndex)
{ {
if (screenIndex <= _screens && screenIndex >= 0) if (screenIndex <= _screens - 1 && screenIndex >= 0)
{ {
_lerp = true; _lerp = true;
_lerp_target = _positions[screenIndex]; _lerp_target = _positions[screenIndex];