From c0f141f5ac1d1d52cbdcb5635f47307978e35585 Mon Sep 17 00:00:00 2001 From: Michal Pikulski Date: Wed, 15 Oct 2025 14:02:12 +0200 Subject: [PATCH] Fix issues with the indicator null checks --- .../Scripts/PuzzleS/ObjectiveStepBehaviour.cs | 24 ++++++++++++------- Assets/Scripts/PuzzleS/PuzzleStepSO.cs | 15 ------------ 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/Assets/Scripts/PuzzleS/ObjectiveStepBehaviour.cs b/Assets/Scripts/PuzzleS/ObjectiveStepBehaviour.cs index 9d1a60de..e11e168d 100644 --- a/Assets/Scripts/PuzzleS/ObjectiveStepBehaviour.cs +++ b/Assets/Scripts/PuzzleS/ObjectiveStepBehaviour.cs @@ -25,6 +25,7 @@ namespace PuzzleS private Interactable _interactable; private bool _isUnlocked = false; + private bool _isCompleted = false; private IPuzzlePrompt _indicator; // Current proximity state tracked by PuzzleManager @@ -72,6 +73,7 @@ namespace PuzzleS public void UpdateProximityState(ProximityState newState) { if (_currentProximityState == newState) return; + if (_indicator == null) return; // Determine state changes and call appropriate methods if (newState == ProximityState.Close) @@ -96,7 +98,7 @@ namespace PuzzleS public virtual void OnShow() { // Delegate to indicator if available - if (_indicator != null) + if (IsIndicatorValid()) { _indicator.OnShow(); return; @@ -112,7 +114,7 @@ namespace PuzzleS public virtual void OnHide() { // Delegate to indicator if available - if (_indicator != null) + if (IsIndicatorValid()) { _indicator.OnHide(); return; @@ -131,7 +133,7 @@ namespace PuzzleS if (!_isUnlocked) return; // Delegate to indicator if available - if (_indicator != null) + if (IsIndicatorValid()) { _indicator.ShowFar(); return; @@ -150,7 +152,7 @@ namespace PuzzleS if (!_isUnlocked) return; // Delegate to indicator if available - if (_indicator != null) + if (IsIndicatorValid()) { _indicator.ShowClose(); return; @@ -169,7 +171,7 @@ namespace PuzzleS if (!_isUnlocked) return; // Delegate to indicator if available - if (_indicator != null) + if (IsIndicatorValid()) { _indicator.HideClose(); return; @@ -188,7 +190,7 @@ namespace PuzzleS if (!_isUnlocked) return; // Delegate to indicator if available - if (_indicator != null) + if (IsIndicatorValid()) { _indicator.HideFar(); return; @@ -266,7 +268,7 @@ namespace PuzzleS Logging.Debug($"[Puzzles] Step locked: {stepData?.stepId} on {gameObject.name}"); // Hide indicator - if (_indicator != null) + if (IsIndicatorValid()) { _indicator.OnHide(); } @@ -298,11 +300,17 @@ namespace PuzzleS if (success) { Logging.Debug($"[Puzzles] Step interacted: {stepData?.stepId} on {gameObject.name}"); - Destroy(puzzleIndicator); + _isCompleted = true; PuzzleManager.Instance?.MarkPuzzleStepCompleted(stepData); + Destroy(puzzleIndicator); } } + private bool IsIndicatorValid() + { + return _indicator != null && puzzleIndicator != null && !_isCompleted; + } + /// /// Visualizes the puzzle prompt ranges in the editor. /// diff --git a/Assets/Scripts/PuzzleS/PuzzleStepSO.cs b/Assets/Scripts/PuzzleS/PuzzleStepSO.cs index b0844507..7a2bd299 100644 --- a/Assets/Scripts/PuzzleS/PuzzleStepSO.cs +++ b/Assets/Scripts/PuzzleS/PuzzleStepSO.cs @@ -29,19 +29,4 @@ public class PuzzleStepSO : ScriptableObject /// [Header("Unlocks")] public List unlocks = new List(); - - [Header("Interaction Settings")] - [Tooltip("Whether to show an indicator when this step is unlocked")] - [SerializeField] private bool showIndicator = false; - - /// - /// Whether to show an indicator when this step is unlocked. - /// - public bool ShowIndicator => showIndicator; - - /// - /// Gets or sets whether to show an indicator. - /// - public bool GetShowIndicator() => showIndicator; - public void SetShowIndicator(bool value) => showIndicator = value; }