Finish setting up the basic album layout
This commit is contained in:
72
Assets/Scripts/UI/CardSystem/CardAlbumOpener.cs
Normal file
72
Assets/Scripts/UI/CardSystem/CardAlbumOpener.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user