Pages
A gesture-based swipeable page system
Overview
Pages is a page navigation and swiping system that supports touch/mouse gestures, animated transitions, button navigation, and event callbacks. Each page contains a content object, optional button reference, and full animation control with elastic drag resistance.
The component handles showing the selected page, hiding or disabling others, playing transition animations, responding to swipe gestures with velocity detection, and reacting to multiple triggers (buttons, swipe, or external code).
Usage
Add Pages component to a parent object
Assign the Container RectTransform that holds all pages
Create page entries and assign:
- Page ID for referencing by string
- Page Object for content panels
- Page Button (optional) to switch on click
Set your Default Page Index
Configure swipe and animation settings
Swipe to navigate or click assigned page buttons
Properties
References
| Field | Type | Description |
|---|---|---|
container | RectTransform | Parent container that holds all pages |
Pages
| Field | Type | Description |
|---|---|---|
pages | List<Page> | List of page definitions |
defaultPageIndex | int | Index of the page to open at Start |
pageID | string | Optional unique ID for string based switching |
pageObject | RectTransform | Content object for the page |
pageButton | Button | Clicking this button opens the page |
Settings
| Name | Type | Description |
|---|---|---|
disableInvisiblePages | bool | Completely disables pages that are not selected |
useUnscaledTime | bool | Use real time instead of game time scale |
interruptTransitions | bool | Allow drag gestures to interrupt ongoing transitions |
Swipe Settings
| Name | Type | Description |
|---|---|---|
swipeThreshold | float | Distance threshold (0.1-0.9) to trigger page change |
elasticResistance | float | Resistance factor (0.1-1) when dragging beyond bounds |
velocityThreshold | float | Velocity required for quick swipe detection |
swipeDirection | SwipeDirection | Horizontal or Vertical swipe direction |
Animation Settings
| Name | Type | Description |
|---|---|---|
transitionCurve | AnimationCurve | Easing curve for page transitions |
transitionDuration | float | Duration of the transition (0-2 seconds) |
pageSpacing | float | Spacing between pages |
Events
| Name | Type | Description |
|---|---|---|
onPageChanged | UnityEvent<int> | Triggered when a new page becomes active |
Public Methods
| Name | Parameters | Description |
|---|---|---|
OpenPage(int index, bool animate) | int, bool | Switch to a page by index with optional animation |
OpenNextPage() | None | Navigate to the next page |
OpenPreviousPage() | None | Navigate to the previous page |
PositionPages() | None | Repositions all pages based on current settings |
Public Properties
| Name | Type | Description |
|---|---|---|
CurrentPageIndex | int | Returns the active page index |
IsTransitioning | bool | Returns true if a transition animation is playing |
Code Example
using UnityEngine;
using Evo.UI;
public class PagesExample : MonoBehaviour
{
public Pages pages;
void Start()
{
// Configure page behavior
pages.disableInvisiblePages = true;
pages.swipeDirection = Pages.SwipeDirection.Horizontal;
pages.swipeThreshold = 0.3f;
pages.interruptTransitions = true;
// Event: log the selected page index
pages.onPageChanged.AddListener(index =>
{
Debug.Log("Current Page: " + index);
});
// Open default page
pages.OpenPage(0);
}
public void GoToOnboarding()
{
pages.OpenPage(0);
}
public void GoToTutorial()
{
pages.OpenPage(1);
}
public void NextPage()
{
if (!pages.IsTransitioning)
{
pages.OpenNextPage();
}
}
public void PreviousPage()
{
if (!pages.IsTransitioning)
{
pages.OpenPreviousPage();
}
}
}