private void SetPage(int page, bool force) { if (pageCount == 0) { this.page = -1; return; } page = page % pageCount; if (page < 0) { page += pageCount; } prevPageButton.interactable = buttonsWrap || page != 0; nextPageButton.interactable = buttonsWrap || page != pageCount - 1; if (this.page != page) { this.page = page; onPageChanged.Invoke(page, pageCount); } if (indicator) { indicator.SetPageIndication(page, pageCount); } }
private void InitializePages() { if (m_Pages.Length > 0) { for (int i = 0; i < m_Pages.Length; i++) { m_Pages[i].gameObject.SetActive(true); } } m_PageSize = m_PagesRect.GetProperSize(); for (int i = 0; i < m_Pages.Length; i++) { RectTransform page = m_Pages[i].rectTransform; page.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, i * m_PageSize.x, m_PageSize.x); } m_PagesContainer.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, 0, m_PageSize.x * m_Pages.Length); OverscrollConfig overscrollConfig = m_PagesRect.GetComponent <OverscrollConfig>(); if (overscrollConfig != null) { overscrollConfig.Setup(); } SetPage(m_CurrentPage, false); m_OnPageChanged.Invoke(m_CurrentPage); // Added by Pavan Jakhu AppBarController app = FindObjectOfType <AppBarController>(); // Added by Pavan Jakhu if (app != null) { app.SetTitle(pages[m_CurrentPage].tabName); // Added by Pavan Jakhu } }
public static void FiredPageChangeEvent(string pageName) { PageChangedEvent?.Invoke(null, new PageChangedEventArge(pageName)); }
/// <summary> /// Set the Current Page of this PagedRect (by its position in the hierarchy) /// </summary> /// <param name="newPage"></param> /// <param name="initial"></param> public virtual void SetCurrentPage(int newPage, bool initial) { if (NumberOfPages == 0) { return; } if (newPage > NumberOfPages) { throw new UnityException("PagedRect.SetCurrentPage(int newPage) :: The value provided for 'newPage' is greater than the number of pages."); } else if (newPage <= 0) { throw new UnityException("PagedRect.SetCurrentPage(int newPage) :: The value provided for 'newPage' is less than zero."); } _timeSinceLastPage = 0.0f; //if (CurrentPage == newPage && !UsingScrollRect) return; UpdatePages(false, false, false); var previousPage = CurrentPage; _timeSinceLastPage = 0f; CurrentPage = newPage; var newPageIndex = GetPagePosition(newPage) - 1; if (!UsingScrollRect) { if (initial) { Pages.ForEach(p => { p.LegacyReset(); }); } var direction = CurrentPage < previousPage ? eDirection.Left : eDirection.Right; for (var i = 0; i < NumberOfPages; i++) { var page = Pages[i]; if (i == newPageIndex) { PageEnterAnimation(page, direction, initial); if (Application.isPlaying) { page.OnShow(); } } else { if (page.gameObject.activeSelf) { if (Application.isPlaying) { page.OnHide(); } PageExitAnimation(page, direction == eDirection.Left ? eDirection.Right : eDirection.Left); } } } } else { if (Application.isPlaying) { // Using a Scroll Rect means that the ScrollRect itself will handle animation, we just need to trigger OnShow and OnHide events here for (var i = 0; i < NumberOfPages; i++) { var page = Pages[i]; if (i == newPageIndex) { page.OnShow(); } else { if (page.Visible) { page.OnHide(); } } } } CenterScrollRectOnCurrentPage(initial); } UpdatePagination(); if (!initial && PageChangedEvent != null) { PageChangedEvent.Invoke(GetPageByNumber(CurrentPage), GetPageByNumber(previousPage)); } if (UsingScrollRect && ShowPagePreviews) { UpdateSeamlessPagePositions_PagePreviews(); } UpdateScrollBarPosition(); }