73 lines
1.9 KiB
C#
73 lines
1.9 KiB
C#
using UI.Core;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace UI.CardSystem
|
|
{
|
|
/// <summary>
|
|
/// Opens the card album view when the button is pressed.
|
|
/// Attach this to a top-level GameObject in the scene.
|
|
/// </summary>
|
|
public class CardAlbumOpener : MonoBehaviour
|
|
{
|
|
[Header("References")]
|
|
[SerializeField] private Button openAlbumButton;
|
|
[SerializeField] private AlbumViewPage albumViewPage;
|
|
|
|
private void Awake()
|
|
{
|
|
if (openAlbumButton != null)
|
|
{
|
|
openAlbumButton.onClick.AddListener(OnOpenAlbumClicked);
|
|
}
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
if (UIPageController.Instance != null)
|
|
{
|
|
UIPageController.Instance.OnPageChanged += OnPageChanged;
|
|
}
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
if (UIPageController.Instance != null)
|
|
{
|
|
UIPageController.Instance.OnPageChanged -= OnPageChanged;
|
|
}
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
if (openAlbumButton != null)
|
|
{
|
|
openAlbumButton.onClick.RemoveListener(OnOpenAlbumClicked);
|
|
}
|
|
}
|
|
|
|
private void OnOpenAlbumClicked()
|
|
{
|
|
if (openAlbumButton != null)
|
|
{
|
|
openAlbumButton.gameObject.SetActive(false);
|
|
}
|
|
|
|
if (albumViewPage != null && UIPageController.Instance != null)
|
|
{
|
|
UIPageController.Instance.PushPage(albumViewPage);
|
|
}
|
|
}
|
|
|
|
private void OnPageChanged(UIPage currentPage)
|
|
{
|
|
// If the album page is no longer active, show the button again
|
|
if (currentPage != albumViewPage && openAlbumButton != null)
|
|
{
|
|
openAlbumButton.gameObject.SetActive(true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|