Working pause menu re-worked with exlusive views

This commit is contained in:
Michal Pikulski
2025-10-24 10:41:27 +02:00
parent 7bb905eb6b
commit 1003c3f6ac
14 changed files with 878 additions and 116 deletions

View File

@@ -12,7 +12,6 @@ namespace UI
public class PauseMenu : UIPage
{
private static PauseMenu _instance;
private static bool _isQuitting;
/// <summary>
/// Singleton instance of the PauseMenu. No longer creates an instance if one doesn't exist.
@@ -64,11 +63,6 @@ namespace UI
SceneManagerService.Instance.SceneLoadCompleted -= SetPauseMenuByLevel;
}
}
void OnApplicationQuit()
{
_isQuitting = true;
}
/// <summary>
/// Sets the pause menu game object active or inactive based on the current level
@@ -76,7 +70,7 @@ namespace UI
/// <param name="levelName">The name of the level/scene</param>
public void SetPauseMenuByLevel(string levelName)
{
HidePauseMenu(false);
HidePauseMenu();
// TODO: Implement level-based pause menu visibility logic if needed
/*if (string.IsNullOrEmpty(levelName))
return;
@@ -94,7 +88,6 @@ namespace UI
/// </summary>
public void ShowPauseMenu()
{
if (GameManager.Instance.IsPaused) return;
if (UIPageController.Instance != null)
{
UIPageController.Instance.PushPage(this);
@@ -119,7 +112,7 @@ namespace UI
/// <summary>
/// Hides the pause menu and shows the pause button. Sets input mode to Game.
/// </summary>
public void HidePauseMenu(bool resetInput = true)
public void HidePauseMenu()
{
if (!GameManager.Instance.IsPaused)
{
@@ -139,7 +132,7 @@ namespace UI
pauseMenuPanel.SetActive(false);
if (pauseButton != null)
pauseButton.SetActive(true);
EndPauseSideEffects(resetInput);
EndPauseSideEffects();
if (canvasGroup != null)
{
canvasGroup.alpha = 0f;
@@ -161,15 +154,13 @@ namespace UI
private void BeginPauseSideEffects()
{
if (pauseButton != null) pauseButton.SetActive(false);
InputManager.Instance.SetInputMode(InputMode.UI);
GameManager.Instance.RequestPause(this);;
GameManager.Instance.RequestPause(this);
Logging.Debug("[PauseMenu] Game Paused");
}
private void EndPauseSideEffects(bool invokeEvent)
private void EndPauseSideEffects()
{
if (pauseButton != null) pauseButton.SetActive(true);
InputManager.Instance.SetInputMode(InputMode.GameAndUI);
GameManager.Instance.ReleasePause(this);
Logging.Debug("[PauseMenu] Game Resumed");
}
@@ -178,6 +169,8 @@ namespace UI
{
// Ensure the panel root is active
if (pauseMenuPanel != null) pauseMenuPanel.SetActive(true);
// Pause side effects should run immediately (hide button, set input mode, etc.).
// The tween itself must run in unscaled time so it still animates while the game is paused.
BeginPauseSideEffects();
if (canvasGroup != null)
@@ -185,7 +178,16 @@ namespace UI
canvasGroup.interactable = true;
canvasGroup.blocksRaycasts = true;
canvasGroup.alpha = 0f;
Tween.Value(0f, 1f, v => canvasGroup.alpha = v, transitionDuration, 0f, Tween.EaseInOut, Tween.LoopType.None, null, onComplete);
// pass obeyTimescale = false so this tween runs even when Time.timeScale == 0
Tween.Value(0f, 1f, (v) =>
{
Logging.Debug($"[PauseMenu] Tweening pause menu alpha: {v}");
canvasGroup.alpha = v;
}, transitionDuration, 0f, Tween.EaseInOut, Tween.LoopType.None, null, () =>
{
Logging.Debug("[PauseMenu] Finished tweening pause menu in.");
onComplete?.Invoke();
}, false);
}
else
{
@@ -199,16 +201,17 @@ namespace UI
{
canvasGroup.interactable = false;
canvasGroup.blocksRaycasts = false;
// Run out-tween in unscaled time as well so the fade completes while paused.
Tween.Value(canvasGroup.alpha, 0f, v => canvasGroup.alpha = v, transitionDuration, 0f, Tween.EaseInOut, Tween.LoopType.None, null, () =>
{
EndPauseSideEffects(true);
if (pauseMenuPanel != null) pauseMenuPanel.SetActive(false);
onComplete?.Invoke();
});
{
EndPauseSideEffects();
if (pauseMenuPanel != null) pauseMenuPanel.SetActive(false);
onComplete?.Invoke();
}, false);
}
else
{
EndPauseSideEffects(true);
EndPauseSideEffects();
if (pauseMenuPanel != null) pauseMenuPanel.SetActive(false);
onComplete?.Invoke();
}