Change the puzzle system to an offline-processed data structure to get around activation issues
This commit is contained in:
committed by
Michal Pikulski
parent
dcd8dc63d0
commit
64be688f6b
@@ -1,10 +1,7 @@
|
||||
using Input;
|
||||
using Interactions;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using AppleHills.Core.Settings;
|
||||
using Core;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
namespace PuzzleS
|
||||
{
|
||||
@@ -48,12 +45,13 @@ namespace PuzzleS
|
||||
_interactable.interactionStarted.AddListener(OnInteractionStarted);
|
||||
_interactable.interactionComplete.AddListener(OnInteractionComplete);
|
||||
}
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
// Register with PuzzleManager, regardless of enabled/disabled state
|
||||
// This happens in Start instead of OnEnable to ensure PuzzleManager has loaded level data
|
||||
PuzzleManager.Instance?.RegisterStepBehaviour(this);
|
||||
// Check if this step was already unlocked
|
||||
if (stepData != null && PuzzleManager.Instance != null && PuzzleManager.Instance.IsStepUnlocked(stepData))
|
||||
{
|
||||
UnlockStep();
|
||||
}
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
@@ -73,7 +71,7 @@ namespace PuzzleS
|
||||
public void UpdateProximityState(ProximityState newState)
|
||||
{
|
||||
if (_currentProximityState == newState) return;
|
||||
if (_indicator == null) return;
|
||||
if (!_isUnlocked) return;
|
||||
|
||||
// Determine state changes and call appropriate methods
|
||||
if (newState == ProximityState.Close)
|
||||
@@ -205,10 +203,12 @@ namespace PuzzleS
|
||||
/// </summary>
|
||||
public void UnlockStep()
|
||||
{
|
||||
if (_isUnlocked) return;
|
||||
|
||||
_isUnlocked = true;
|
||||
Logging.Debug($"[Puzzles] Step unlocked: {stepData?.stepId} on {gameObject.name}");
|
||||
|
||||
// Show indicator if enabled in settings
|
||||
// Show indicator if available
|
||||
if (puzzleIndicator != null)
|
||||
{
|
||||
// Try to get the IPuzzlePrompt component from the spawned indicator
|
||||
@@ -264,6 +264,8 @@ namespace PuzzleS
|
||||
/// </summary>
|
||||
public void LockStep()
|
||||
{
|
||||
if (!_isUnlocked) return;
|
||||
|
||||
_isUnlocked = false;
|
||||
Logging.Debug($"[Puzzles] Step locked: {stepData?.stepId} on {gameObject.name}");
|
||||
|
||||
@@ -297,12 +299,17 @@ namespace PuzzleS
|
||||
private void OnInteractionComplete(bool success)
|
||||
{
|
||||
if (!_isUnlocked) return;
|
||||
if (success)
|
||||
if (success && !_isCompleted)
|
||||
{
|
||||
Logging.Debug($"[Puzzles] Step interacted: {stepData?.stepId} on {gameObject.name}");
|
||||
_isCompleted = true;
|
||||
PuzzleManager.Instance?.MarkPuzzleStepCompleted(stepData);
|
||||
Destroy(puzzleIndicator);
|
||||
|
||||
if (puzzleIndicator != null)
|
||||
{
|
||||
Destroy(puzzleIndicator);
|
||||
_indicator = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -323,7 +330,7 @@ namespace PuzzleS
|
||||
|
||||
// Draw threshold circle
|
||||
Gizmos.color = Color.cyan;
|
||||
Gizmos.DrawWireSphere(transform.position, promptRange / 2f);
|
||||
Gizmos.DrawWireSphere(transform.position, promptRange);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user