The forgotten push
This commit is contained in:
@@ -324,6 +324,13 @@ namespace Core
|
||||
{
|
||||
LogDebugMessage($"Skipping save for: {oldSceneName} (skipSave=true)");
|
||||
}
|
||||
|
||||
// PHASE 4: Clear PuzzleManager state before scene transition
|
||||
if (PuzzleS.PuzzleManager.Instance != null)
|
||||
{
|
||||
LogDebugMessage($"Clearing puzzle state before scene transition");
|
||||
PuzzleS.PuzzleManager.Instance.ClearPuzzleState();
|
||||
}
|
||||
|
||||
// PHASE 5: Remove all AstarPath (A* Pathfinder) singletons before loading the new scene
|
||||
var astarPaths = FindObjectsByType<AstarPath>(FindObjectsSortMode.None);
|
||||
|
||||
@@ -184,6 +184,8 @@ namespace PuzzleS
|
||||
return;
|
||||
}
|
||||
|
||||
// Reset restoration flag when loading new scene data
|
||||
_isDataRestored = false;
|
||||
_isDataLoaded = false;
|
||||
string addressablePath = $"Puzzles/{currentScene}";
|
||||
|
||||
@@ -213,11 +215,10 @@ namespace PuzzleS
|
||||
_currentLevelData = handle.Result;
|
||||
Logging.Debug($"[Puzzles] Loaded level data: {_currentLevelData.levelId} with {_currentLevelData.allSteps.Count} steps");
|
||||
|
||||
// Reset state
|
||||
_completedSteps.Clear();
|
||||
_unlockedSteps.Clear();
|
||||
// Don't clear steps here - SceneManagerService calls ClearPuzzleState() before scene transitions
|
||||
// This allows save restoration to work properly without race conditions
|
||||
|
||||
// Unlock initial steps
|
||||
// Unlock initial steps (adds to existing unlocked steps from save restoration)
|
||||
UnlockInitialSteps();
|
||||
|
||||
// Update all registered behaviors now that data is loaded
|
||||
@@ -567,6 +568,27 @@ namespace PuzzleS
|
||||
return _isDataLoaded;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears all puzzle state (completed steps, unlocked steps, registrations).
|
||||
/// Called by SceneManagerService before scene transitions to ensure clean state.
|
||||
/// </summary>
|
||||
public void ClearPuzzleState()
|
||||
{
|
||||
Logging.Debug("[PuzzleManager] Clearing puzzle state");
|
||||
|
||||
_completedSteps.Clear();
|
||||
_unlockedSteps.Clear();
|
||||
_isDataRestored = false;
|
||||
|
||||
// Clear any pending registrations from the old scene
|
||||
_pendingRegistrations.Clear();
|
||||
_pendingUnlocks.Clear();
|
||||
|
||||
// Unregister all step behaviours from the old scene
|
||||
_stepBehaviours.Clear();
|
||||
_registeredBehaviours.Clear();
|
||||
}
|
||||
|
||||
#region Save/Load Lifecycle Hooks
|
||||
|
||||
protected override string OnSceneSaveRequested()
|
||||
@@ -591,6 +613,8 @@ namespace PuzzleS
|
||||
|
||||
protected override void OnSceneRestoreRequested(string data)
|
||||
{
|
||||
Debug.Log("[XAXA] PuzzleManager loading with data: " + data);
|
||||
|
||||
if (string.IsNullOrEmpty(data) || data == "{}")
|
||||
{
|
||||
Logging.Debug("[PuzzleManager] No puzzle save data to restore");
|
||||
|
||||
Reference in New Issue
Block a user