Revamp game pausing and input handling. Fix minigame tutorial and end sequence. (#39)

- Revamp pausing and centralize management in GameManager
- Switch Pause implementation to be counter-based to solve corner case of multiple pause requests
- Remove duplicated Pause logic from other components
- Add pausing when browsing the card album
- Fully deliver the exclusive UI implementation
- Spruce up the MiniGame tutorial with correct pausing, hiding other UI
- Correctly unpause after showing tutorial
- Fix minigame ending sequence. The cinematic correctly plays only once now
- Replaying the minigame works

Co-authored-by: Michal Adam Pikulski <michal@foolhardyhorizons.com>
Co-authored-by: Michal Pikulski <michal@foolhardyhorizons.com>
Reviewed-on: #39
This commit is contained in:
2025-10-24 11:09:32 +00:00
parent 35acaddca5
commit 5a85a602bd
26 changed files with 1342 additions and 1023 deletions

View File

@@ -43,12 +43,6 @@ namespace Minigames.DivingForPictures
private bool _isSurfacing = false; // Flag to track surfacing state
private float _velocityFactor = 1.0f; // Current velocity factor from the game manager
// Pause state
private bool _isPaused = false;
// IPausable implementation
public bool IsPaused => _isPaused;
private void Awake()
{
_mainCamera = UnityEngine.Camera.main;
@@ -127,10 +121,6 @@ namespace Minigames.DivingForPictures
/// </summary>
public void Pause()
{
if (_isPaused) return; // Already paused
_isPaused = true;
// Stop spawning coroutine
if (_spawnCoroutine != null)
{
@@ -159,10 +149,6 @@ namespace Minigames.DivingForPictures
/// </summary>
public void DoResume()
{
if (!_isPaused) return; // Already running
_isPaused = false;
// Restart spawning coroutine if not in surfacing mode
if (!_isSurfacing)
{
@@ -190,7 +176,7 @@ namespace Minigames.DivingForPictures
/// </summary>
private void StartSpawnCoroutine()
{
if (_spawnCoroutine == null && !_isPaused && !_isSurfacing)
if (_spawnCoroutine == null && !GameManager.Instance.IsPaused && !_isSurfacing)
{
_spawnCoroutine = StartCoroutine(SpawnObstacleRoutine());
}
@@ -201,7 +187,7 @@ namespace Minigames.DivingForPictures
/// </summary>
private void StartMoveCoroutine()
{
if (_moveCoroutine == null && !_isPaused)
if (_moveCoroutine == null && !GameManager.Instance.IsPaused)
{
_moveCoroutine = StartCoroutine(MoveObstaclesRoutine());
}
@@ -212,7 +198,7 @@ namespace Minigames.DivingForPictures
/// </summary>
private void StartDespawnCoroutine()
{
if (_despawnCoroutine == null && !_isPaused)
if (_despawnCoroutine == null && !GameManager.Instance.IsPaused)
{
_despawnCoroutine = StartCoroutine(DespawnObstaclesRoutine());
}
@@ -553,7 +539,7 @@ namespace Minigames.DivingForPictures
obstacleComponent.SetSpawner(this);
// If spawner is already paused, pause the obstacle immediately
if (_isPaused)
if (GameManager.Instance.IsPaused)
{
obstacleComponent.Pause();
}
@@ -677,7 +663,7 @@ namespace Minigames.DivingForPictures
{
Logging.Debug("[ObstacleSpawner] Started spawning coroutine");
while (enabled && gameObject.activeInHierarchy && !_isPaused && !_isSurfacing)
while (enabled && gameObject.activeInHierarchy && !GameManager.Instance.IsPaused && !_isSurfacing)
{
// Calculate next spawn time with variation
float nextSpawnTime = _settings.ObstacleSpawnInterval +
@@ -707,7 +693,7 @@ namespace Minigames.DivingForPictures
Logging.Debug("[ObstacleSpawner] Started obstacle monitoring coroutine");
// This coroutine now just monitors obstacles, not moves them
while (enabled && gameObject.activeInHierarchy && !_isPaused)
while (enabled && gameObject.activeInHierarchy && !GameManager.Instance.IsPaused)
{
// Clean up any null references in the active obstacles list
_activeObstacles.RemoveAll(obstacle => obstacle == null);
@@ -729,7 +715,7 @@ namespace Minigames.DivingForPictures
const float checkInterval = 0.5f; // Check every half second
Logging.Debug("[ObstacleSpawner] Started despawn coroutine with interval: " + checkInterval);
while (enabled && gameObject.activeInHierarchy && !_isPaused)
while (enabled && gameObject.activeInHierarchy && !GameManager.Instance.IsPaused)
{
// Calculate screen bounds for despawning
float despawnBuffer = 2f; // Extra buffer beyond screen edges