Files
beyond/Assets/Scripts/UI/PanelSwitcher.cs
2024-11-20 15:21:28 +01:00

52 lines
1.1 KiB
C#

using System;
using DanielLochner.Assets.SimpleScrollSnap;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Beyond
{
public class PanelSwitcher : MonoBehaviour
{
public SimpleScrollSnap snap;
private int latestPanelIndex = 0;
private delegate void EnableCallback(int index);
private Action enableCallback;
private void OnEnable()
{
enableCallback?.Invoke();
enableCallback = null;
}
public void SwapToNextPanel()
{
snap.GoToNextPanel();
}
public void SwapToLastPanel()
{
latestPanelIndex = snap.CurrentPanel;
snap.GoToPanel(snap.Panels.Length - 1);
}
public void GoBackToLatestPanel()
{
snap.GoToPanel(latestPanelIndex);
}
public void SetPanelToIndex(int index)
{
if (gameObject.activeInHierarchy)
{
snap.GoToPanel(index);
}
else
{
enableCallback += () => snap.GoToPanel(index);
}
}
}
}