Add a pausable interface and make minigameobjecs pausable

This commit is contained in:
Michal Pikulski
2025-10-08 12:36:08 +02:00
parent 3807ac652c
commit 0e17516df7
11 changed files with 1101 additions and 395 deletions

View File

@@ -1,6 +1,7 @@
using UnityEngine;
using System.Collections;
using Pooling;
using AppleHills.Core.Interfaces;
namespace Minigames.DivingForPictures
{
@@ -8,7 +9,7 @@ namespace Minigames.DivingForPictures
/// Represents a single bubble, handling its movement, wobble effect, scaling, and sprite assignment.
/// Uses coroutines for better performance instead of Update() calls.
/// </summary>
public class Bubble : MonoBehaviour, IPoolableWithReference<BubblePool>
public class Bubble : MonoBehaviour, IPoolableWithReference<BubblePool>, IPausable
{
public float speed = 1f;
public float wobbleSpeed = 1f;
@@ -26,6 +27,12 @@ namespace Minigames.DivingForPictures
private Coroutine _movementCoroutine;
private Coroutine _wobbleCoroutine;
private Coroutine _offScreenCheckCoroutine;
// Pause state tracking
private bool _isPaused = false;
// IPausable implementation
public bool IsPaused => _isPaused;
void Awake()
{
@@ -53,12 +60,42 @@ namespace Minigames.DivingForPictures
{
StopBubbleBehavior();
}
/// <summary>
/// Pauses all bubble behaviors
/// </summary>
public void Pause()
{
if (_isPaused) return; // Already paused
_isPaused = true;
StopBubbleBehavior();
// Debug log for troubleshooting
Debug.Log($"[Bubble] Paused bubble: {name}");
}
/// <summary>
/// Resumes all bubble behaviors
/// </summary>
public void Resume()
{
if (!_isPaused) return; // Already running
_isPaused = false;
StartBubbleBehavior();
// Debug log for troubleshooting
Debug.Log($"[Bubble] Resumed bubble: {name}");
}
/// <summary>
/// Starts all bubble behavior coroutines
/// </summary>
private void StartBubbleBehavior()
{
if (_isPaused) return; // Don't start if paused
_movementCoroutine = StartCoroutine(MovementCoroutine());
_wobbleCoroutine = StartCoroutine(WobbleCoroutine());
_offScreenCheckCoroutine = StartCoroutine(OffScreenCheckCoroutine());