Merged in chrisparton1991/unity-ui-extensions/navigation_button_toggle (pull request #39)

Improved scroll snap containers to disable navigation buttons when appropriate.

--HG--
branch : develop_5.3
pull/413/head
Simon Jackson 2017-02-07 11:44:28 +00:00
commit 9f293eba7e
2 changed files with 30 additions and 7 deletions

View File

@ -181,7 +181,7 @@ namespace UnityEngine.UI.Extensions
DistributePages(); DistributePages();
if (MaskArea) UpdateVisible(); if (MaskArea) UpdateVisible();
SetScrollContainerPosition(); SetScrollContainerPosition();
ChangeBulletsInfo(_currentPage); OnCurrentScreenChange(_currentPage);
} }
private void OnRectTransformDimensionsChange() private void OnRectTransformDimensionsChange()

View File

@ -46,12 +46,12 @@ namespace UnityEngine.UI.Extensions
[Tooltip("The gameobject that contains toggles which suggest pagination. (optional)")] [Tooltip("The gameobject that contains toggles which suggest pagination. (optional)")]
public GameObject Pagination; public GameObject Pagination;
[Tooltip("Button to go to the next page. (optional)")]
public GameObject NextButton;
[Tooltip("Button to go to the previous page. (optional)")] [Tooltip("Button to go to the previous page. (optional)")]
public GameObject PrevButton; public GameObject PrevButton;
[Tooltip("Button to go to the next page. (optional)")]
public GameObject NextButton;
[Tooltip("Transition speed between pages. (optional)")] [Tooltip("Transition speed between pages. (optional)")]
public float transitionSpeed = 7.5f; public float transitionSpeed = 7.5f;
@ -84,7 +84,7 @@ namespace UnityEngine.UI.Extensions
_currentPage = value; _currentPage = value;
if(MaskArea) UpdateVisible(); if(MaskArea) UpdateVisible();
if(!_lerp) ScreenChange(); if(!_lerp) ScreenChange();
ChangeBulletsInfo(_currentPage); OnCurrentScreenChange(_currentPage);
} }
} }
} }
@ -326,13 +326,23 @@ namespace UnityEngine.UI.Extensions
_lerp = true; _lerp = true;
CurrentPage = GetPageforPosition(_screensContainer.localPosition); CurrentPage = GetPageforPosition(_screensContainer.localPosition);
GetPositionforPage(_currentPage, ref _lerp_target); GetPositionforPage(_currentPage, ref _lerp_target);
ChangeBulletsInfo(_currentPage); OnCurrentScreenChange(_currentPage);
} }
/// <summary>
/// notifies pagination indicator and navigation buttons of a screen change
/// </summary>
internal void OnCurrentScreenChange(int currentScreen)
{
ChangeBulletsInfo(currentScreen);
ToggleNavigationButtons(currentScreen);
}
/// <summary> /// <summary>
/// changes the bullets on the bottom of the page - pagination /// changes the bullets on the bottom of the page - pagination
/// </summary> /// </summary>
/// <param name="targetScreen"></param> /// <param name="targetScreen"></param>
internal void ChangeBulletsInfo(int targetScreen) private void ChangeBulletsInfo(int targetScreen)
{ {
if (Pagination) if (Pagination)
for (int i = 0; i < Pagination.transform.childCount; i++) for (int i = 0; i < Pagination.transform.childCount; i++)
@ -343,6 +353,19 @@ namespace UnityEngine.UI.Extensions
} }
} }
/// <summary>
/// disables the page navigation buttons when at the first or last screen
/// </summary>
/// <param name="targetScreen"></param>
private void ToggleNavigationButtons(int targetScreen) {
if (PrevButton) {
PrevButton.GetComponent<Button>().interactable = targetScreen > 0;
}
if (NextButton) {
NextButton.GetComponent<Button>().interactable = targetScreen < _screensContainer.transform.childCount - 1;
}
}
private void OnValidate() private void OnValidate()
{ {
var children = gameObject.GetComponent<ScrollRect>().content.childCount; var children = gameObject.GetComponent<ScrollRect>().content.childCount;