Fix pausing etc. issues in the minigame
This commit is contained in:
@@ -66,21 +66,17 @@ namespace Minigames.DivingForPictures
|
||||
|
||||
SetNextSpawnInterval();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
DivingGameManager.Instance.RegisterPausableComponent(this);
|
||||
}
|
||||
|
||||
|
||||
void Start()
|
||||
{
|
||||
// Start spawning if not paused
|
||||
DivingGameManager.Instance.RegisterPausableComponent(this);
|
||||
StartSpawningCoroutine();
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
DivingGameManager.Instance.UnregisterPausableComponent(this);
|
||||
DivingGameManager.Instance?.UnregisterPausableComponent(this);
|
||||
|
||||
// Clean up any active coroutines
|
||||
StopAllCoroutines();
|
||||
|
||||
@@ -98,24 +98,10 @@ namespace Minigames.DivingForPictures
|
||||
public event Action<Monster, float> OnPhotoSequenceCompleted; // Now includes proximity score
|
||||
public event Action<float> OnPhotoSequenceProgressUpdated;
|
||||
|
||||
private static DivingGameManager _instance;
|
||||
private static DivingGameManager _instance = null;
|
||||
private static bool _isQuitting = false;
|
||||
public static DivingGameManager Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_instance == null && Application.isPlaying && !_isQuitting)
|
||||
{
|
||||
_instance = FindAnyObjectByType<DivingGameManager>();
|
||||
if (_instance == null)
|
||||
{
|
||||
var go = new GameObject("DivingGameManager");
|
||||
_instance = go.AddComponent<DivingGameManager>();
|
||||
}
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
|
||||
public static DivingGameManager Instance => _instance;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
|
||||
@@ -29,8 +29,11 @@ namespace Minigames.DivingForPictures
|
||||
private void OnDestroy()
|
||||
{
|
||||
// Unsubscribe from events
|
||||
DivingGameManager.Instance.OnScoreChanged -= UpdateScoreDisplay;
|
||||
DivingGameManager.Instance.OnPictureTaken -= ShowScorePopup;
|
||||
if (DivingGameManager.Instance)
|
||||
{
|
||||
DivingGameManager.Instance.OnScoreChanged -= UpdateScoreDisplay;
|
||||
DivingGameManager.Instance.OnPictureTaken -= ShowScorePopup;
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateScoreDisplay(int score)
|
||||
|
||||
@@ -82,17 +82,13 @@ namespace Minigames.DivingForPictures
|
||||
if (onObstacleDestroyed == null)
|
||||
onObstacleDestroyed = new UnityEvent<GameObject>();
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
// Register with the DivingGameManager for pause/resume events
|
||||
DivingGameManager.Instance.RegisterPausableComponent(this);
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
// Register with the DivingGameManager for pause/resume events
|
||||
DivingGameManager.Instance.RegisterPausableComponent(this);
|
||||
DivingGameManager.Instance.OnGameInitialized += Initialize;
|
||||
|
||||
|
||||
// If game is already initialized, initialize immediately
|
||||
if (DivingGameManager.Instance.GetType().GetField("_isGameInitialized",
|
||||
System.Reflection.BindingFlags.NonPublic |
|
||||
@@ -104,7 +100,7 @@ namespace Minigames.DivingForPictures
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
DivingGameManager.Instance.UnregisterPausableComponent(this);
|
||||
DivingGameManager.Instance?.UnregisterPausableComponent(this);
|
||||
|
||||
// Clean up any active coroutines
|
||||
StopAllCoroutines();
|
||||
|
||||
@@ -42,15 +42,12 @@ namespace Minigames.DivingForPictures.Player
|
||||
Debug.LogError("[PlayerController] Failed to load diving minigame settings!");
|
||||
}
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
// Register as a pausable component with DivingGameManager
|
||||
DivingGameManager.Instance.RegisterPausableComponent(this);
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
// Register as a pausable component with DivingGameManager
|
||||
DivingGameManager.Instance.RegisterPausableComponent(this);
|
||||
|
||||
// Initialize target to current position
|
||||
targetFingerX = transform.position.x;
|
||||
isTouchActive = false;
|
||||
@@ -114,10 +111,11 @@ namespace Minigames.DivingForPictures.Player
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
DivingGameManager.Instance.OnGameInitialized -= Initialize;
|
||||
|
||||
// Unregister as a pausable component
|
||||
DivingGameManager.Instance.UnregisterPausableComponent(this);
|
||||
if (DivingGameManager.Instance)
|
||||
{
|
||||
DivingGameManager.Instance.OnGameInitialized -= Initialize;
|
||||
DivingGameManager.Instance.UnregisterPausableComponent(this);
|
||||
}
|
||||
|
||||
// Unsubscribe from edge anchor events
|
||||
if (edgeAnchor != null)
|
||||
|
||||
@@ -168,14 +168,10 @@ namespace Minigames.DivingForPictures
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
private void Start()
|
||||
{
|
||||
// Register with the DivingGameManager for pause/resume events
|
||||
DivingGameManager.Instance.RegisterPausableComponent(this);
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
DivingGameManager.Instance.OnGameInitialized += Initialize;
|
||||
|
||||
// If game is already initialized, initialize immediately
|
||||
@@ -189,7 +185,7 @@ namespace Minigames.DivingForPictures
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
DivingGameManager.Instance.UnregisterPausableComponent(this);
|
||||
DivingGameManager.Instance?.UnregisterPausableComponent(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Minigames.DivingForPictures.Utilities
|
||||
|
||||
private bool isPaused = false;
|
||||
|
||||
private void OnEnable()
|
||||
private void Start()
|
||||
{
|
||||
DivingGameManager.Instance.RegisterPausableComponent(this);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Minigames.DivingForPictures.Utilities
|
||||
|
||||
private bool isPaused = false;
|
||||
|
||||
private void OnEnable()
|
||||
private void Start()
|
||||
{
|
||||
DivingGameManager.Instance.RegisterPausableComponent(this);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user