Somewhat working indicators
This commit is contained in:
@@ -8,6 +8,16 @@ namespace PuzzleS
|
||||
/// </summary>
|
||||
public interface IPuzzlePrompt
|
||||
{
|
||||
/// <summary>
|
||||
/// Called when the prompt should be initially shown (e.g., when step is unlocked)
|
||||
/// </summary>
|
||||
void OnShow();
|
||||
|
||||
/// <summary>
|
||||
/// Called when the prompt should be hidden (e.g., when step is locked)
|
||||
/// </summary>
|
||||
void OnHide();
|
||||
|
||||
/// <summary>
|
||||
/// Called when the player enters the outer range of the prompt.
|
||||
/// </summary>
|
||||
|
||||
@@ -3,6 +3,7 @@ using Interactions;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using AppleHills.Core.Settings;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
namespace PuzzleS
|
||||
{
|
||||
@@ -18,12 +19,11 @@ namespace PuzzleS
|
||||
public PuzzleStepSO stepData;
|
||||
|
||||
[Header("Indicator Settings")]
|
||||
[SerializeField] private GameObject indicatorPrefab;
|
||||
[SerializeField] private GameObject puzzleIndicator;
|
||||
[SerializeField] private bool drawPromptRangeGizmo = true;
|
||||
|
||||
private Interactable _interactable;
|
||||
private bool _isUnlocked = false;
|
||||
private GameObject _spawnedIndicator;
|
||||
private IPuzzlePrompt _indicator;
|
||||
|
||||
// Current proximity state tracked by PuzzleManager
|
||||
@@ -62,14 +62,6 @@ namespace PuzzleS
|
||||
_interactable.interactionComplete.RemoveListener(OnInteractionComplete);
|
||||
}
|
||||
PuzzleManager.Instance?.UnregisterStepBehaviour(this);
|
||||
|
||||
// Clean up indicator
|
||||
if (_spawnedIndicator != null)
|
||||
{
|
||||
Destroy(_spawnedIndicator);
|
||||
_spawnedIndicator = null;
|
||||
_indicator = null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -97,11 +89,46 @@ namespace PuzzleS
|
||||
|
||||
// IPuzzlePrompt interface implementation - delegates to indicator if available
|
||||
|
||||
/// <summary>
|
||||
/// Called when the prompt should be initially shown (e.g., when step is unlocked)
|
||||
/// </summary>
|
||||
public virtual void OnShow()
|
||||
{
|
||||
// Delegate to indicator if available
|
||||
if (_indicator != null)
|
||||
{
|
||||
_indicator.OnShow();
|
||||
return;
|
||||
}
|
||||
|
||||
// Default fallback behavior
|
||||
Debug.Log($"[Puzzles] Prompt shown for {stepData?.stepId} on {gameObject.name}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the prompt should be hidden (e.g., when step is locked)
|
||||
/// </summary>
|
||||
public virtual void OnHide()
|
||||
{
|
||||
// Delegate to indicator if available
|
||||
if (_indicator != null)
|
||||
{
|
||||
_indicator.OnHide();
|
||||
return;
|
||||
}
|
||||
|
||||
// Default fallback behavior
|
||||
Debug.Log($"[Puzzles] Prompt hidden for {stepData?.stepId} on {gameObject.name}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when player enters the far range
|
||||
/// </summary>
|
||||
public virtual void ShowFar()
|
||||
{
|
||||
// Only show if step is unlocked
|
||||
if (!_isUnlocked) return;
|
||||
|
||||
// Delegate to indicator if available
|
||||
if (_indicator != null)
|
||||
{
|
||||
@@ -118,6 +145,9 @@ namespace PuzzleS
|
||||
/// </summary>
|
||||
public virtual void ShowClose()
|
||||
{
|
||||
// Only show if step is unlocked
|
||||
if (!_isUnlocked) return;
|
||||
|
||||
// Delegate to indicator if available
|
||||
if (_indicator != null)
|
||||
{
|
||||
@@ -134,6 +164,9 @@ namespace PuzzleS
|
||||
/// </summary>
|
||||
public virtual void HideClose()
|
||||
{
|
||||
// Only respond if step is unlocked
|
||||
if (!_isUnlocked) return;
|
||||
|
||||
// Delegate to indicator if available
|
||||
if (_indicator != null)
|
||||
{
|
||||
@@ -150,6 +183,9 @@ namespace PuzzleS
|
||||
/// </summary>
|
||||
public virtual void HideFar()
|
||||
{
|
||||
// Only respond if step is unlocked
|
||||
if (!_isUnlocked) return;
|
||||
|
||||
// Delegate to indicator if available
|
||||
if (_indicator != null)
|
||||
{
|
||||
@@ -170,16 +206,15 @@ namespace PuzzleS
|
||||
Debug.Log($"[Puzzles] Step unlocked: {stepData?.stepId} on {gameObject.name}");
|
||||
|
||||
// Show indicator if enabled in settings
|
||||
if (stepData?.ShowIndicator == true && indicatorPrefab != null && _spawnedIndicator == null)
|
||||
if (puzzleIndicator != null)
|
||||
{
|
||||
_spawnedIndicator = Instantiate(indicatorPrefab, transform);
|
||||
// Try to get the IPuzzlePrompt component from the spawned indicator
|
||||
_indicator = _spawnedIndicator.GetComponent<IPuzzlePrompt>();
|
||||
_indicator = puzzleIndicator.GetComponent<IPuzzlePrompt>();
|
||||
|
||||
if (_indicator == null)
|
||||
{
|
||||
// Try to find it in children if not on the root
|
||||
_indicator = _spawnedIndicator.GetComponentInChildren<IPuzzlePrompt>();
|
||||
_indicator = puzzleIndicator.GetComponentInChildren<IPuzzlePrompt>();
|
||||
}
|
||||
|
||||
if (_indicator == null)
|
||||
@@ -188,7 +223,10 @@ namespace PuzzleS
|
||||
}
|
||||
else
|
||||
{
|
||||
// Immediately set the correct state based on current player distance
|
||||
// First show the indicator
|
||||
_indicator.OnShow();
|
||||
|
||||
// Then set the correct state based on current player distance
|
||||
Transform playerTransform = GameObject.FindGameObjectWithTag("Player")?.transform;
|
||||
if (playerTransform != null)
|
||||
{
|
||||
@@ -227,11 +265,9 @@ namespace PuzzleS
|
||||
Debug.Log($"[Puzzles] Step locked: {stepData?.stepId} on {gameObject.name}");
|
||||
|
||||
// Hide indicator
|
||||
if (_spawnedIndicator != null)
|
||||
if (_indicator != null)
|
||||
{
|
||||
Destroy(_spawnedIndicator);
|
||||
_spawnedIndicator = null;
|
||||
_indicator = null;
|
||||
_indicator.OnHide();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,16 @@ public class TestIndicator : MonoBehaviour, PuzzleS.IPuzzlePrompt
|
||||
|
||||
}
|
||||
|
||||
public void OnShow()
|
||||
{
|
||||
gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
public void OnHide()
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
public void ShowFar()
|
||||
{
|
||||
gameObject.SetActive(true);
|
||||
|
||||
Reference in New Issue
Block a user