Add a dirty booster pack opening sequence
This commit is contained in:
89
Assets/Scripts/UI/CardSystem/CardSystemSceneVisibility.cs
Normal file
89
Assets/Scripts/UI/CardSystem/CardSystemSceneVisibility.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
using Bootstrap;
|
||||
using Core;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UI.CardSystem
|
||||
{
|
||||
/// <summary>
|
||||
/// One-off helper that shows/hides the Card System root based on scene loads.
|
||||
/// 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
|
||||
{
|
||||
[Header("Target Root")]
|
||||
[Tooltip("The GameObject to show/hide. Defaults to this GameObject if not assigned.")]
|
||||
[SerializeField] private GameObject targetRoot;
|
||||
|
||||
[Header("Rules")]
|
||||
[Tooltip("The scene name in which the Card System should be hidden.")]
|
||||
[SerializeField] private string startingSceneName = "StartingScene";
|
||||
[Tooltip("Also hide when SceneManagerService reports the Bootstrap scene.")]
|
||||
[SerializeField] private bool hideInBootstrapScene = true;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
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()
|
||||
{
|
||||
var sceneSvc = SceneManagerService.Instance;
|
||||
if (sceneSvc != null)
|
||||
{
|
||||
sceneSvc.SceneLoadCompleted -= OnSceneLoaded;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnSceneLoaded(string sceneName)
|
||||
{
|
||||
ApplyVisibility(sceneName);
|
||||
}
|
||||
|
||||
private void ApplyVisibility(string sceneName)
|
||||
{
|
||||
if (targetRoot == null)
|
||||
return;
|
||||
|
||||
if (string.IsNullOrEmpty(sceneName))
|
||||
return;
|
||||
|
||||
if (hideInBootstrapScene && sceneName == "BootstrapScene")
|
||||
{
|
||||
SetActiveSafe(false);
|
||||
return;
|
||||
}
|
||||
|
||||
bool shouldShow = sceneName != startingSceneName;
|
||||
SetActiveSafe(shouldShow);
|
||||
}
|
||||
|
||||
private void SetActiveSafe(bool active)
|
||||
{
|
||||
if (targetRoot.activeSelf != active)
|
||||
{
|
||||
targetRoot.SetActive(active);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user