You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CrowdControl/Assets/Feel/NiceVibrations/Demo/_Common/Scripts/UI/Pagination.cs

52 lines
1.5 KiB
C#

// Copyright (c) Meta Platforms, Inc. and affiliates.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace Lofelt.NiceVibrations
{
public class Pagination : MonoBehaviour
{
public GameObject PaginationDotPrefab;
public Color ActiveColor;
public Color InactiveColor;
protected List<Image> _images;
public virtual void InitializePagination(int numberOfPages)
{
_images = new List<Image>();
for (int i = 0; i < numberOfPages; i++)
{
GameObject dotPrefab = Instantiate(PaginationDotPrefab);
dotPrefab.transform.SetParent(this.transform);
dotPrefab.name = "PaginationDot" + i;
_images.Add(dotPrefab.GetComponent<Image>());
}
foreach (Image image in _images)
{
image.color = InactiveColor;
image.rectTransform.localScale = Vector3.one;
image.rectTransform.localPosition = Vector3.zero;
image.SetNativeSize();
}
}
public virtual void SetCurrentPage(int numberOfPages, int currentPage)
{
for (int i = 0; i < numberOfPages; i++)
{
if (i == currentPage)
{
_images[i].color = ActiveColor;
}
else
{
_images[i].color = InactiveColor;
}
}
}
}
}