SaveLoad using managed lifecycle

This commit is contained in:
Michal Pikulski
2025-11-04 20:01:27 +01:00
parent 379a033d6b
commit bb68d1fd31
23 changed files with 1083 additions and 648 deletions

View File

@@ -2,6 +2,7 @@
using Interactions;
using UnityEngine;
using Core;
using Core.Lifecycle;
namespace PuzzleS
{
@@ -9,7 +10,7 @@ namespace PuzzleS
/// Manages the state and interactions for a single puzzle step, including unlock/lock logic and event handling.
/// </summary>
[RequireComponent(typeof(InteractableBase))]
public class ObjectiveStepBehaviour : MonoBehaviour, IPuzzlePrompt
public class ObjectiveStepBehaviour : ManagedBehaviour, IPuzzlePrompt
{
/// <summary>
/// The data object representing this puzzle step.
@@ -31,8 +32,10 @@ namespace PuzzleS
// Enum for tracking proximity state (simplified to just Close and Far)
public enum ProximityState { Close, Far }
void Awake()
protected override void Awake()
{
base.Awake();
_interactable = GetComponent<InteractableBase>();
// Initialize the indicator if it exists, but ensure it's hidden initially
@@ -57,6 +60,21 @@ namespace PuzzleS
}
}
protected override void OnManagedAwake()
{
base.OnManagedAwake();
// Register with PuzzleManager - safe to access .Instance here
if (stepData != null && PuzzleManager.Instance != null)
{
PuzzleManager.Instance.RegisterStepBehaviour(this);
}
else if (stepData == null)
{
Logging.Warning($"[Puzzles] Cannot register step on {gameObject.name}: stepData is null");
}
}
void OnEnable()
{
if (_interactable == null)
@@ -68,28 +86,19 @@ namespace PuzzleS
_interactable.interactionComplete.AddListener(OnInteractionComplete);
}
}
void Start()
{
// Simply register with the PuzzleManager
// The manager will handle state updates appropriately based on whether data is loaded
if (stepData != null && PuzzleManager.Instance != null)
{
PuzzleManager.Instance.RegisterStepBehaviour(this);
}
else if (stepData == null)
{
Logging.Warning($"[Puzzles] Cannot register step on {gameObject.name}: stepData is null");
}
}
void OnDestroy()
void OnDisable()
{
if (_interactable != null)
{
_interactable.interactionStarted.RemoveListener(OnInteractionStarted);
_interactable.interactionComplete.RemoveListener(OnInteractionComplete);
}
}
protected override void OnDestroy()
{
base.OnDestroy();
if (PuzzleManager.Instance != null && stepData != null)
{