Clean up IPausable interafaces a little bit and start refactoring the pause-game flow in the minigame
This commit is contained in:
@@ -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,9 +121,7 @@ namespace Minigames.DivingForPictures
|
||||
/// </summary>
|
||||
public void Pause()
|
||||
{
|
||||
if (_isPaused) return; // Already paused
|
||||
|
||||
_isPaused = true;
|
||||
if (GameManager.Instance.IsPaused) return; // Already paused
|
||||
|
||||
// Stop spawning coroutine
|
||||
if (_spawnCoroutine != null)
|
||||
@@ -159,9 +151,8 @@ namespace Minigames.DivingForPictures
|
||||
/// </summary>
|
||||
public void DoResume()
|
||||
{
|
||||
if (!_isPaused) return; // Already running
|
||||
|
||||
_isPaused = false;
|
||||
if (!GameManager.Instance.IsPaused) return; // Already running
|
||||
|
||||
|
||||
// Restart spawning coroutine if not in surfacing mode
|
||||
if (!_isSurfacing)
|
||||
@@ -190,7 +181,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 +192,7 @@ namespace Minigames.DivingForPictures
|
||||
/// </summary>
|
||||
private void StartMoveCoroutine()
|
||||
{
|
||||
if (_moveCoroutine == null && !_isPaused)
|
||||
if (_moveCoroutine == null && !GameManager.Instance.IsPaused)
|
||||
{
|
||||
_moveCoroutine = StartCoroutine(MoveObstaclesRoutine());
|
||||
}
|
||||
@@ -212,7 +203,7 @@ namespace Minigames.DivingForPictures
|
||||
/// </summary>
|
||||
private void StartDespawnCoroutine()
|
||||
{
|
||||
if (_despawnCoroutine == null && !_isPaused)
|
||||
if (_despawnCoroutine == null && !GameManager.Instance.IsPaused)
|
||||
{
|
||||
_despawnCoroutine = StartCoroutine(DespawnObstaclesRoutine());
|
||||
}
|
||||
@@ -553,7 +544,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 +668,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 +698,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 +720,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
|
||||
|
||||
Reference in New Issue
Block a user