45 lines
934 B
C#
45 lines
934 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class RulesController : MonoBehaviour
|
|
{
|
|
|
|
|
|
private int currentIndex;
|
|
[SerializeField] List<GameObject> pages;
|
|
|
|
|
|
public void Open()
|
|
{
|
|
currentIndex = 0;
|
|
OpenPage(currentIndex);
|
|
|
|
}
|
|
public void Close() => CloseAllPages();
|
|
public void SwitchPage(int direction)
|
|
{
|
|
bool invalidOperation = pages.Count == 0 || direction == 0;
|
|
if (invalidOperation) return;
|
|
|
|
direction = Mathf.Clamp(direction, -1, 1);
|
|
currentIndex = (currentIndex + direction + pages.Count) % pages.Count;
|
|
OpenPage(currentIndex);
|
|
}
|
|
|
|
|
|
|
|
private void OpenPage(int index)
|
|
{
|
|
CloseAllPages();
|
|
pages[index].SetActive(true);
|
|
}
|
|
private void CloseAllPages()
|
|
{
|
|
foreach (GameObject page in pages)
|
|
{
|
|
page.SetActive(false);
|
|
}
|
|
}
|
|
}
|