/// <summary> /// Init this instance. /// </summary> protected virtual void Init() { if (isInited) { return; } isInited = true; //ScrollRect.horizontal = false; //ScrollRect.vertical = false; var resizeListener = Utilites.GetOrAddComponent <ResizeListener>(ScrollRect); resizeListener.OnResize.AddListener(RecalculatePages); var contentResizeListener = Utilites.GetOrAddComponent <ResizeListener>(ScrollRect.content); contentResizeListener.OnResize.AddListener(RecalculatePages); var dragListener = Utilites.GetOrAddComponent <OnDragListener>(ScrollRect); dragListener.OnDragStartEvent.AddListener(OnScrollRectDragStart); dragListener.OnDragEvent.AddListener(OnScrollRectDrag); dragListener.OnDragEndEvent.AddListener(OnScrollRectDragEnd); ScrollRect.onValueChanged.AddListener(OnScrollRectValueChanged); var scroll_listener = Utilites.GetOrAddComponent <ScrollListener>(ScrollRect); scroll_listener.ScrollEvent.AddListener(ContainerScroll); if (DefaultPage != null) { SRDefaultPage = Utilites.GetOrAddComponent <ScrollRectPage>(DefaultPage); SRDefaultPage.gameObject.SetActive(false); } if (ActivePage != null) { SRActivePage = Utilites.GetOrAddComponent <ScrollRectPage>(ActivePage); } if (PrevPage != null) { SRPrevPage = Utilites.GetOrAddComponent <ScrollRectPage>(PrevPage); SRPrevPage.SetPage(0); SRPrevPage.OnPageSelect.AddListener(Prev); } if (NextPage != null) { SRNextPage = Utilites.GetOrAddComponent <ScrollRectPage>(NextPage); SRNextPage.OnPageSelect.AddListener(Next); } RecalculatePages(); var page = currentPage; currentPage = -1; GoToPage(page); }
/// <summary> /// Removes the callback. /// </summary> /// <param name="page">Page.</param> protected virtual void RemoveCallback(ScrollRectPage page) { page.OnPageSelect.RemoveListener(GoToPage); }
/// <summary> /// Gets the page number. /// </summary> /// <returns>The page number.</returns> /// <param name="pageComponent">Page component.</param> protected int GetPageNumber(ScrollRectPage pageComponent) { return(pageComponent.Page); }
/// <summary> /// Determines whether tthe specified pageComponent is null. /// </summary> /// <returns><c>true</c> if the specified pageComponent is null; otherwise, <c>false</c>.</returns> /// <param name="pageComponent">Page component.</param> protected bool IsNullComponent(ScrollRectPage pageComponent) { return(pageComponent == null); }
/// <summary> /// Start this instance. /// </summary> protected virtual void Start() { if (isStarted) { return; } isStarted = true; var resizeListener = ScrollRect.GetComponent <ResizeListener>(); if (resizeListener == null) { resizeListener = ScrollRect.gameObject.AddComponent <ResizeListener>(); } resizeListener.OnResize.AddListener(RecalculatePages); var contentResizeListener = ScrollRect.content.GetComponent <ResizeListener>(); if (contentResizeListener == null) { contentResizeListener = ScrollRect.content.gameObject.AddComponent <ResizeListener>(); } contentResizeListener.OnResize.AddListener(RecalculatePages); var dragListener = ScrollRect.GetComponent <OnDragListener>(); if (dragListener == null) { dragListener = ScrollRect.gameObject.AddComponent <OnDragListener>(); } dragListener.OnDragStartEvent.AddListener(OnScrollRectDragStart); dragListener.OnDragEvent.AddListener(OnScrollRectDrag); dragListener.OnDragEndEvent.AddListener(OnScrollRectDragEnd); ScrollRect.onValueChanged.AddListener(OnScrollRectValueChanged); if (DefaultPage != null) { SRDefaultPage = DefaultPage.GetComponent <ScrollRectPage>(); if (SRDefaultPage == null) { SRDefaultPage = DefaultPage.gameObject.AddComponent <ScrollRectPage>(); } SRDefaultPage.gameObject.SetActive(false); } if (ActivePage != null) { SRActivePage = ActivePage.GetComponent <ScrollRectPage>(); if (SRActivePage == null) { SRActivePage = ActivePage.gameObject.AddComponent <ScrollRectPage>(); } } if (PrevPage != null) { SRPrevPage = PrevPage.GetComponent <ScrollRectPage>(); if (SRPrevPage == null) { SRPrevPage = PrevPage.gameObject.AddComponent <ScrollRectPage>(); } SRPrevPage.SetPage(0); SRPrevPage.OnPageSelect.AddListener(Prev); } if (NextPage != null) { SRNextPage = NextPage.GetComponent <ScrollRectPage>(); if (SRNextPage == null) { SRNextPage = NextPage.gameObject.AddComponent <ScrollRectPage>(); } SRNextPage.OnPageSelect.AddListener(Next); } RecalculatePages(); var page = currentPage; currentPage = -1; GoToPage(page); }