Clean up IPausable interafaces a little bit and start refactoring the pause-game flow in the minigame

This commit is contained in:
Michal Adam Pikulski
2025-10-23 09:31:09 +02:00
parent 35acaddca5
commit ef3b4bf369
15 changed files with 423 additions and 579 deletions

View File

@@ -1,10 +1,8 @@
using System;
using System.Collections;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Serialization;
using Pooling;
using AppleHills.Core.Settings;
using Utils;
using AppleHills.Core.Interfaces;
@@ -113,12 +111,6 @@ namespace Minigames.DivingForPictures
}
}
// Pause state
private bool _isPaused = false;
// IPausable implementation
public bool IsPaused => _isPaused;
private void Awake()
{
_mainCamera = UnityEngine.Camera.main;
@@ -193,9 +185,7 @@ namespace Minigames.DivingForPictures
/// </summary>
public void Pause()
{
if (_isPaused) return; // Already paused
_isPaused = true;
if (GameManager.Instance.IsPaused) return; // Already paused
// Stop all active coroutines but save their references
if (_movementCoroutine != null)
@@ -230,9 +220,7 @@ namespace Minigames.DivingForPictures
/// </summary>
public void DoResume()
{
if (!_isPaused) return; // Already running
_isPaused = false;
if (!GameManager.Instance.IsPaused) return; // Already running
// Restart all necessary coroutines
StartMovementCoroutine();
@@ -500,7 +488,7 @@ namespace Minigames.DivingForPictures
/// </summary>
private void StartMovementCoroutine()
{
if (_movementCoroutine == null && !_isPaused)
if (_movementCoroutine == null && !GameManager.Instance.IsPaused)
{
_movementCoroutine = StartCoroutine(MoveActiveTilesRoutine());
}
@@ -513,7 +501,7 @@ namespace Minigames.DivingForPictures
{
Logging.Debug($"[TrenchTileSpawner] Started movement coroutine with normalized speed: {_baseMoveSpeed:F3}");
while (enabled && gameObject.activeInHierarchy && !_isPaused)
while (enabled && gameObject.activeInHierarchy && !GameManager.Instance.IsPaused)
{
// Skip if no active tiles
if (_activeTiles.Count == 0)
@@ -554,7 +542,7 @@ namespace Minigames.DivingForPictures
const float checkInterval = 1.0f; // Check once per second
Logging.Debug($"[TrenchTileSpawner] Started speed ramping coroutine with interval: {checkInterval}s");
while (enabled && gameObject.activeInHierarchy && !_isPaused)
while (enabled && gameObject.activeInHierarchy && !GameManager.Instance.IsPaused)
{
// Increase the base move speed up to the maximum
_baseMoveSpeed = Mathf.Min(_baseMoveSpeed + _settings.SpeedUpFactor, _settings.MaxNormalizedMoveSpeed);