Further updates to state machines

This commit is contained in:
Michal Pikulski
2025-11-05 13:48:25 +01:00
committed by Michal Pikulski
parent 199480447e
commit b3e0f90e09
26 changed files with 2211 additions and 4383 deletions

View File

@@ -46,13 +46,12 @@ namespace UI
protected override void OnManagedAwake()
{
// Component setup already done in Awake
}
protected override void OnSceneReady()
{
// Subscribe to scene-dependent events
SceneManagerService.Instance.SceneLoadCompleted += SetPauseMenuByLevel;
// Subscribe to scene-dependent events - must be in OnManagedAwake, not OnSceneReady
// because PauseMenu is in DontDestroyOnLoad and OnSceneReady only fires once
if (SceneManagerService.Instance != null)
{
SceneManagerService.Instance.SceneLoadCompleted += SetPauseMenuByLevel;
}
// Also react to global UI hide/show events from the page controller
if (UIPageController.Instance != null)
@@ -67,6 +66,11 @@ namespace UI
Logging.Debug("[PauseMenu] Subscribed to SceneManagerService events");
}
protected override void OnSceneReady()
{
// This only fires once for DontDestroyOnLoad objects, so we handle scene loads in OnManagedAwake
}
protected override void OnDestroy()
{
base.OnDestroy();
@@ -89,17 +93,30 @@ namespace UI
/// <param name="levelName">The name of the level/scene</param>
public void SetPauseMenuByLevel(string levelName)
{
HidePauseMenu();
// TODO: Implement level-based pause menu visibility logic if needed
/*if (string.IsNullOrEmpty(levelName))
return;
bool isStartingLevel = levelName.ToLower().Contains("startingscene");
// When a new scene loads, ensure pause menu is removed from UIPageController stack
// and properly hidden, regardless of pause state
if (UIPageController.Instance != null && UIPageController.Instance.CurrentPage == this)
{
UIPageController.Instance.PopPage();
}
if(isStartingLevel)
HidePauseMenu(false); // Ensure menu is hidden when switching to a game level
// Ensure pause state is cleared
if (GameManager.Instance != null && GameManager.Instance.IsPaused)
{
EndPauseSideEffects();
}
Logging.Debug($"[PauseMenu] Setting pause menu active: {!isStartingLevel} for scene: {levelName}");*/
// Hide the menu UI
if (pauseMenuPanel != null) pauseMenuPanel.SetActive(false);
if (canvasGroup != null)
{
canvasGroup.alpha = 0f;
canvasGroup.interactable = false;
canvasGroup.blocksRaycasts = false;
}
gameObject.SetActive(false);
Logging.Debug($"[PauseMenu] Cleaned up pause menu state for scene: {levelName}");
}
/// <summary>
@@ -246,6 +263,18 @@ namespace UI
/// </summary>
public async void ExitToAppleHills()
{
// Pop from UIPageController stack before switching scenes
if (UIPageController.Instance != null && UIPageController.Instance.CurrentPage == this)
{
UIPageController.Instance.PopPage();
}
// Ensure pause state is cleared
if (GameManager.Instance != null && GameManager.Instance.IsPaused)
{
EndPauseSideEffects();
}
// Replace with the actual scene name as set in Build Settings
var progress = new Progress<float>(p => Logging.Debug($"Loading progress: {p * 100:F0}%"));
await SceneManagerService.Instance.SwitchSceneAsync("AppleHillsOverworld", progress);