SaveLoad using managed lifecycle

This commit is contained in:
Michal Pikulski
2025-11-04 20:01:27 +01:00
parent 379a033d6b
commit bb68d1fd31
23 changed files with 1083 additions and 648 deletions

View File

@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using AppleHills.Data.CardSystem;
using Core;
using Data.CardSystem;
@@ -34,8 +34,6 @@ namespace UI.CardSystem
private void Awake()
{
_cardManager = CardSystemManager.Instance;
// Make sure we have a CanvasGroup for transitions
if (canvasGroup == null)
canvasGroup = GetComponent<CanvasGroup>();
@@ -48,6 +46,14 @@ namespace UI.CardSystem
backButton.onClick.AddListener(OnBackButtonClicked);
}
}
protected override void OnManagedAwake()
{
base.OnManagedAwake();
// Safe to access manager instance here
_cardManager = CardSystemManager.Instance;
}
/// <summary>
/// Sets up the album when the page becomes active

View File

@@ -1,4 +1,4 @@
using System.Collections;
using System.Collections;
using System.Collections.Generic;
using AppleHills.Data.CardSystem;
using Core;
@@ -52,7 +52,6 @@ namespace UI.CardSystem
private void Awake()
{
_cardManager = CardSystemManager.Instance;
_cardAlbumUI = FindFirstObjectByType<CardAlbumUI>();
// Set up button listeners
@@ -86,6 +85,14 @@ namespace UI.CardSystem
HideAllCardBacks();
}
protected override void OnManagedAwake()
{
base.OnManagedAwake();
// Safe to access manager instance here
_cardManager = CardSystemManager.Instance;
}
/// <summary>
/// Cache all card back buttons from the container
/// </summary>

View File

@@ -38,6 +38,11 @@ namespace UI.CardSystem
protected override void OnManagedAwake()
{
base.OnManagedAwake();
// Get card manager - safe to access .Instance here
_cardManager = CardSystemManager.Instance;
// Set up backpack button
if (backpackButton != null)
{
@@ -54,20 +59,7 @@ namespace UI.CardSystem
// Initialize pages and hide them
InitializePages();
// React to global UI hide/show events (top-page only) by toggling this GameObject
if (UIPageController.Instance != null)
{
UIPageController.Instance.OnAllUIHidden += HandleAllUIHidden;
UIPageController.Instance.OnAllUIShown += HandleAllUIShown;
}
}
private void Start()
{
// Get card manager
_cardManager = CardSystemManager.Instance;
// Subscribe to events
// Subscribe to card manager events
if (_cardManager != null)
{
_cardManager.OnBoosterCountChanged += UpdateBoosterCount;
@@ -78,6 +70,13 @@ namespace UI.CardSystem
// Initialize UI with current values
UpdateBoosterCount(_cardManager.GetBoosterPackCount());
}
// React to global UI hide/show events (top-page only) by toggling this GameObject
if (UIPageController.Instance != null)
{
UIPageController.Instance.OnAllUIHidden += HandleAllUIHidden;
UIPageController.Instance.OnAllUIShown += HandleAllUIShown;
}
}
private void OnDestroy()

View File

@@ -1,4 +1,4 @@
using Core;
using Core;
using Data.CardSystem;
using Pixelplacement;
using UI.Core;
@@ -28,9 +28,8 @@ namespace UI.CardSystem
private void Awake()
{
// Get references
// Get UI reference
_cardAlbumUI = FindAnyObjectByType<CardAlbumUI>();
_cardManager = CardSystemManager.Instance;
// Make sure we have a CanvasGroup
if (canvasGroup == null)
@@ -48,6 +47,14 @@ namespace UI.CardSystem
{
viewAlbumButton.onClick.AddListener(OnViewAlbumClicked);
}
}
protected override void OnManagedAwake()
{
base.OnManagedAwake();
// Safe to access manager instance here
_cardManager = CardSystemManager.Instance;
if (changeClothesButton != null)
{