Rework of base interactables and managed behaviors
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
using AppleHills.Data.CardSystem;
|
||||
using Bootstrap;
|
||||
using Core;
|
||||
using Core.Lifecycle;
|
||||
using Data.CardSystem;
|
||||
using Pixelplacement;
|
||||
using UI.Core;
|
||||
@@ -13,7 +13,7 @@ namespace UI.CardSystem
|
||||
/// Main UI controller for the card album system.
|
||||
/// Manages the backpack icon and navigation between card system pages.
|
||||
/// </summary>
|
||||
public class CardAlbumUI : MonoBehaviour
|
||||
public class CardAlbumUI : ManagedBehaviour
|
||||
{
|
||||
[Header("UI References")]
|
||||
[SerializeField] private GameObject backpackIcon;
|
||||
@@ -34,7 +34,9 @@ namespace UI.CardSystem
|
||||
private CardSystemManager _cardManager;
|
||||
private bool _hasUnseenCards;
|
||||
|
||||
private void Awake()
|
||||
public override int ManagedAwakePriority => 65; // UI card systems
|
||||
|
||||
protected override void OnManagedAwake()
|
||||
{
|
||||
// Set up backpack button
|
||||
if (backpackButton != null)
|
||||
@@ -45,13 +47,7 @@ namespace UI.CardSystem
|
||||
// Hide notification dot initially
|
||||
if (boosterNotificationDot != null)
|
||||
boosterNotificationDot.gameObject.SetActive(false);
|
||||
|
||||
// Register for post-boot initialization
|
||||
BootCompletionService.RegisterInitAction(InitializePostBoot);
|
||||
}
|
||||
|
||||
private void InitializePostBoot()
|
||||
{
|
||||
|
||||
// Initially show only the backpack icon
|
||||
ShowOnlyBackpackIcon();
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using Bootstrap;
|
||||
using Core;
|
||||
using Core;
|
||||
using Core.Lifecycle;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
@@ -11,49 +11,34 @@ namespace UI.CardSystem
|
||||
/// Attach this to your Card System root GameObject. It subscribes to SceneManagerService.SceneLoadCompleted
|
||||
/// and applies visibility: hidden in "StartingScene" (configurable), visible in all other gameplay scenes.
|
||||
/// </summary>
|
||||
public class CardSystemSceneVisibility : MonoBehaviour
|
||||
public class CardSystemSceneVisibility : ManagedBehaviour
|
||||
{
|
||||
[Header("Target Root")]
|
||||
[Tooltip("The GameObject to show/hide. Defaults to this GameObject if not assigned.")]
|
||||
[SerializeField] private GameObject targetRoot;
|
||||
|
||||
private void Awake()
|
||||
public override int ManagedAwakePriority => 95; // Scene-specific UI visibility
|
||||
|
||||
protected override void OnManagedAwake()
|
||||
{
|
||||
if (targetRoot == null)
|
||||
targetRoot = gameObject;
|
||||
|
||||
// Defer subscription to after boot so SceneManagerService is guaranteed ready.
|
||||
BootCompletionService.RegisterInitAction(InitializePostBoot, priority: 95, name: "CardSystem Scene Visibility Init");
|
||||
}
|
||||
|
||||
private void InitializePostBoot()
|
||||
{
|
||||
var sceneSvc = SceneManagerService.Instance;
|
||||
if (sceneSvc == null)
|
||||
{
|
||||
Debug.LogWarning("[CardSystemSceneVisibility] SceneManagerService.Instance is null post-boot.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Subscribe to scene load completion notifications
|
||||
sceneSvc.SceneLoadCompleted += OnSceneLoaded;
|
||||
|
||||
// Apply initial state based on current gameplay scene
|
||||
ApplyVisibility(sceneSvc.CurrentGameplayScene);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
protected override void OnSceneReady()
|
||||
{
|
||||
// Replaces SceneLoadCompleted subscription
|
||||
var sceneSvc = SceneManagerService.Instance;
|
||||
if (sceneSvc != null)
|
||||
{
|
||||
sceneSvc.SceneLoadCompleted -= OnSceneLoaded;
|
||||
ApplyVisibility(sceneSvc.CurrentGameplayScene);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnSceneLoaded(string sceneName)
|
||||
protected override void OnDestroy()
|
||||
{
|
||||
ApplyVisibility(sceneName);
|
||||
base.OnDestroy();
|
||||
// No additional cleanup needed
|
||||
}
|
||||
|
||||
private void ApplyVisibility(string sceneName)
|
||||
|
||||
Reference in New Issue
Block a user