123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- using UnityEngine;
- using System.Collections;
- /// <summary>
- /// This component is responsible for having paging with a next and prev buttons.
- /// It enables/disables the buttons according to whether there are more pages to go through
- /// Each page is a GameObject, which is activated when the user is paging.
- /// The next/prev buttons need to send a message to this component accordingly (OnNextPageButtonMsg and OnPrevPageButtonMsg).
- /// For sending such a message the buttons can easily use UIButtonMessage component.
- /// </summary>
- public class PagingDialog : MonoBehaviour
- {
- public GameObject[] pages;
- public GameObject prevButton, nextButton;
- public bool WinCondomPages;
- public UILabel LabelPages;
- int _currentPageIndex;
- private UIElementTransition transaction;
- void Star()
- {
- //transaction = GetComponent<>()
- }
- void OnEnable()
- {
- _currentPageIndex = 0;
-
- LabelPages.text = string.Format("{0}/{1}", _currentPageIndex + 1, pages.Length);
-
- RefreshPage();
- }
- /// <summary>
- /// Enables the current page, disables the others.
- /// Updates the buttons state according to the current page.
- /// This needs to be called whenever the current page index is changed.
- /// </summary>
- void RefreshPage()
- {
- for (int i = 0; i < pages.Length; i++)
- {
- bool isPageActive = _currentPageIndex == i;
- if(pages[i].GetComponent<UIElementTransition>()!=null)
- {
- if (isPageActive)
- {
- pages[i].GetComponent<UIElementTransition>().Show();
- }
- else
- {
- pages[i].GetComponent<UIElementTransition>().Hide();
- }
- }
- else
- {
- pages[i].SetActive(isPageActive);
- }
-
- //
- }
- //prevButton enable/disable
- if (_currentPageIndex == 0)
- {
- UIUtils.EnableWidgets(prevButton, false);
- } else
- {
- UIUtils.EnableWidgets(prevButton, true);
- }
- //nextButton enable/disable
- if (_currentPageIndex == pages.Length - 1)
- {
- UIUtils.EnableWidgets(nextButton, false);
- } else
- {
- UIUtils.EnableWidgets(nextButton, true);
- }
- }
- #region Next/Prev button messages
- void OnNextPageButtonMsg()
- {
- if (_currentPageIndex < pages.Length - 1)
- {
- ++_currentPageIndex;
- RefreshPage();
- }
-
- LabelPages.text = string.Format("{0}/{1}", _currentPageIndex + 1, pages.Length);
-
- }
- void OnPrevPageButtonMsg()
- {
- if (_currentPageIndex > 0)
- {
- --_currentPageIndex;
- RefreshPage();
- }
-
- LabelPages.text = string.Format("{0}/{1}", _currentPageIndex + 1, pages.Length);
-
- }
- #endregion
- }
|