Fix issues with the indicator null checks
This commit is contained in:
@@ -25,6 +25,7 @@ namespace PuzzleS
|
|||||||
|
|
||||||
private Interactable _interactable;
|
private Interactable _interactable;
|
||||||
private bool _isUnlocked = false;
|
private bool _isUnlocked = false;
|
||||||
|
private bool _isCompleted = false;
|
||||||
private IPuzzlePrompt _indicator;
|
private IPuzzlePrompt _indicator;
|
||||||
|
|
||||||
// Current proximity state tracked by PuzzleManager
|
// Current proximity state tracked by PuzzleManager
|
||||||
@@ -72,6 +73,7 @@ namespace PuzzleS
|
|||||||
public void UpdateProximityState(ProximityState newState)
|
public void UpdateProximityState(ProximityState newState)
|
||||||
{
|
{
|
||||||
if (_currentProximityState == newState) return;
|
if (_currentProximityState == newState) return;
|
||||||
|
if (_indicator == null) return;
|
||||||
|
|
||||||
// Determine state changes and call appropriate methods
|
// Determine state changes and call appropriate methods
|
||||||
if (newState == ProximityState.Close)
|
if (newState == ProximityState.Close)
|
||||||
@@ -96,7 +98,7 @@ namespace PuzzleS
|
|||||||
public virtual void OnShow()
|
public virtual void OnShow()
|
||||||
{
|
{
|
||||||
// Delegate to indicator if available
|
// Delegate to indicator if available
|
||||||
if (_indicator != null)
|
if (IsIndicatorValid())
|
||||||
{
|
{
|
||||||
_indicator.OnShow();
|
_indicator.OnShow();
|
||||||
return;
|
return;
|
||||||
@@ -112,7 +114,7 @@ namespace PuzzleS
|
|||||||
public virtual void OnHide()
|
public virtual void OnHide()
|
||||||
{
|
{
|
||||||
// Delegate to indicator if available
|
// Delegate to indicator if available
|
||||||
if (_indicator != null)
|
if (IsIndicatorValid())
|
||||||
{
|
{
|
||||||
_indicator.OnHide();
|
_indicator.OnHide();
|
||||||
return;
|
return;
|
||||||
@@ -131,7 +133,7 @@ namespace PuzzleS
|
|||||||
if (!_isUnlocked) return;
|
if (!_isUnlocked) return;
|
||||||
|
|
||||||
// Delegate to indicator if available
|
// Delegate to indicator if available
|
||||||
if (_indicator != null)
|
if (IsIndicatorValid())
|
||||||
{
|
{
|
||||||
_indicator.ShowFar();
|
_indicator.ShowFar();
|
||||||
return;
|
return;
|
||||||
@@ -150,7 +152,7 @@ namespace PuzzleS
|
|||||||
if (!_isUnlocked) return;
|
if (!_isUnlocked) return;
|
||||||
|
|
||||||
// Delegate to indicator if available
|
// Delegate to indicator if available
|
||||||
if (_indicator != null)
|
if (IsIndicatorValid())
|
||||||
{
|
{
|
||||||
_indicator.ShowClose();
|
_indicator.ShowClose();
|
||||||
return;
|
return;
|
||||||
@@ -169,7 +171,7 @@ namespace PuzzleS
|
|||||||
if (!_isUnlocked) return;
|
if (!_isUnlocked) return;
|
||||||
|
|
||||||
// Delegate to indicator if available
|
// Delegate to indicator if available
|
||||||
if (_indicator != null)
|
if (IsIndicatorValid())
|
||||||
{
|
{
|
||||||
_indicator.HideClose();
|
_indicator.HideClose();
|
||||||
return;
|
return;
|
||||||
@@ -188,7 +190,7 @@ namespace PuzzleS
|
|||||||
if (!_isUnlocked) return;
|
if (!_isUnlocked) return;
|
||||||
|
|
||||||
// Delegate to indicator if available
|
// Delegate to indicator if available
|
||||||
if (_indicator != null)
|
if (IsIndicatorValid())
|
||||||
{
|
{
|
||||||
_indicator.HideFar();
|
_indicator.HideFar();
|
||||||
return;
|
return;
|
||||||
@@ -266,7 +268,7 @@ namespace PuzzleS
|
|||||||
Logging.Debug($"[Puzzles] Step locked: {stepData?.stepId} on {gameObject.name}");
|
Logging.Debug($"[Puzzles] Step locked: {stepData?.stepId} on {gameObject.name}");
|
||||||
|
|
||||||
// Hide indicator
|
// Hide indicator
|
||||||
if (_indicator != null)
|
if (IsIndicatorValid())
|
||||||
{
|
{
|
||||||
_indicator.OnHide();
|
_indicator.OnHide();
|
||||||
}
|
}
|
||||||
@@ -298,11 +300,17 @@ namespace PuzzleS
|
|||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
Logging.Debug($"[Puzzles] Step interacted: {stepData?.stepId} on {gameObject.name}");
|
Logging.Debug($"[Puzzles] Step interacted: {stepData?.stepId} on {gameObject.name}");
|
||||||
Destroy(puzzleIndicator);
|
_isCompleted = true;
|
||||||
PuzzleManager.Instance?.MarkPuzzleStepCompleted(stepData);
|
PuzzleManager.Instance?.MarkPuzzleStepCompleted(stepData);
|
||||||
|
Destroy(puzzleIndicator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool IsIndicatorValid()
|
||||||
|
{
|
||||||
|
return _indicator != null && puzzleIndicator != null && !_isCompleted;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Visualizes the puzzle prompt ranges in the editor.
|
/// Visualizes the puzzle prompt ranges in the editor.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -29,19 +29,4 @@ public class PuzzleStepSO : ScriptableObject
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[Header("Unlocks")]
|
[Header("Unlocks")]
|
||||||
public List<PuzzleStepSO> unlocks = new List<PuzzleStepSO>();
|
public List<PuzzleStepSO> unlocks = new List<PuzzleStepSO>();
|
||||||
|
|
||||||
[Header("Interaction Settings")]
|
|
||||||
[Tooltip("Whether to show an indicator when this step is unlocked")]
|
|
||||||
[SerializeField] private bool showIndicator = false;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Whether to show an indicator when this step is unlocked.
|
|
||||||
/// </summary>
|
|
||||||
public bool ShowIndicator => showIndicator;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets whether to show an indicator.
|
|
||||||
/// </summary>
|
|
||||||
public bool GetShowIndicator() => showIndicator;
|
|
||||||
public void SetShowIndicator(bool value) => showIndicator = value;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user