Rework of base interactables and managed behaviors
This commit is contained in:
committed by
Michal Pikulski
parent
00e1746ac4
commit
f88bd0e2c9
@@ -2,14 +2,13 @@
|
||||
using AppleHills.Core.Settings;
|
||||
using Cinematics;
|
||||
using Core;
|
||||
using Core.Lifecycle;
|
||||
using Input;
|
||||
using Minigames.DivingForPictures.PictureCamera;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Bootstrap;
|
||||
using Minigames.DivingForPictures.Bubbles;
|
||||
using UI;
|
||||
using UI.Core;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
@@ -17,7 +16,7 @@ using UnityEngine.Playables;
|
||||
|
||||
namespace Minigames.DivingForPictures
|
||||
{
|
||||
public class DivingGameManager : MonoBehaviour, IPausable
|
||||
public class DivingGameManager : ManagedBehaviour, IPausable
|
||||
{
|
||||
[Header("Monster Prefabs")]
|
||||
[Tooltip("Array of monster prefabs to spawn randomly")]
|
||||
@@ -104,7 +103,10 @@ namespace Minigames.DivingForPictures
|
||||
|
||||
public static DivingGameManager Instance => _instance;
|
||||
|
||||
private void Awake()
|
||||
public override int ManagedAwakePriority => 190;
|
||||
public override bool AutoRegisterPausable => true; // Automatic GameManager registration
|
||||
|
||||
protected override void OnManagedAwake()
|
||||
{
|
||||
_settings = GameManager.GetSettingsObject<IDivingMinigameSettings>();
|
||||
_currentSpawnProbability = _settings?.BaseSpawnProbability ?? 0.2f;
|
||||
@@ -120,13 +122,18 @@ namespace Minigames.DivingForPictures
|
||||
|
||||
// Ensure any previous run state is reset when this manager awakes
|
||||
_isGameOver = false;
|
||||
|
||||
Logging.Debug("[DivingGameManager] Initialized");
|
||||
}
|
||||
|
||||
protected override void OnSceneReady()
|
||||
{
|
||||
InitializeGame();
|
||||
CinematicsManager.Instance.OnCinematicStopped += EndGame;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
// Register for post-boot initialization
|
||||
BootCompletionService.RegisterInitAction(InitializePostBoot);
|
||||
|
||||
// Subscribe to player damage events (this doesn't depend on initialization)
|
||||
PlayerCollisionBehavior.OnDamageTaken += OnPlayerDamageTaken;
|
||||
|
||||
@@ -155,29 +162,14 @@ namespace Minigames.DivingForPictures
|
||||
OnMonsterSpawned += DoMonsterSpawned;
|
||||
}
|
||||
|
||||
private void InitializePostBoot()
|
||||
protected override void OnDestroy()
|
||||
{
|
||||
// Register this manager with the global GameManager
|
||||
if (GameManager.Instance != null)
|
||||
{
|
||||
GameManager.Instance.RegisterPausableComponent(this);
|
||||
}
|
||||
base.OnDestroy(); // Handles auto-unregister from GameManager
|
||||
|
||||
InitializeGame();
|
||||
CinematicsManager.Instance.OnCinematicStopped += EndGame;
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
// Unsubscribe from events when the manager is destroyed
|
||||
PlayerCollisionBehavior.OnDamageTaken -= OnPlayerDamageTaken;
|
||||
|
||||
// Unregister from GameManager
|
||||
if (GameManager.Instance != null)
|
||||
{
|
||||
GameManager.Instance.UnregisterPausableComponent(this);
|
||||
}
|
||||
|
||||
|
||||
// Unregister all pausable components
|
||||
_pausableComponents.Clear();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user