Add a pausable interface and make minigameobjecs pausable
This commit is contained in:
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user