2025-10-21 15:40:47 +02:00
|
|
|
|
using Bootstrap;
|
|
|
|
|
|
using Core;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
2025-10-22 09:05:18 +02:00
|
|
|
|
|
|
|
|
|
|
// TODO: Yeet this class
|
2025-10-21 15:40:47 +02:00
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
{
|
2025-10-28 14:31:17 +01:00
|
|
|
|
// TODO: Implement actual visibility logic based on sceneName
|
2025-10-22 09:05:18 +02:00
|
|
|
|
SetActiveSafe(true);
|
|
|
|
|
|
// if (targetRoot == null)
|
|
|
|
|
|
// return;
|
|
|
|
|
|
//
|
|
|
|
|
|
// if (string.IsNullOrEmpty(sceneName))
|
|
|
|
|
|
// return;
|
|
|
|
|
|
//
|
|
|
|
|
|
// if (hideInBootstrapScene && sceneName == "BootstrapScene")
|
|
|
|
|
|
// {
|
|
|
|
|
|
// SetActiveSafe(false);
|
|
|
|
|
|
// return;
|
|
|
|
|
|
// }
|
|
|
|
|
|
//
|
|
|
|
|
|
// bool shouldShow = sceneName != startingSceneName;
|
|
|
|
|
|
// SetActiveSafe(shouldShow);
|
2025-10-21 15:40:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void SetActiveSafe(bool active)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (targetRoot.activeSelf != active)
|
|
|
|
|
|
{
|
|
|
|
|
|
targetRoot.SetActive(active);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|