2025-09-03 15:43:47 +02:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
|
|
[RequireComponent(typeof(Interactable))]
|
|
|
|
|
|
public class ObjectiveStepBehaviour : MonoBehaviour
|
|
|
|
|
|
{
|
|
|
|
|
|
public PuzzleStepSO stepData;
|
|
|
|
|
|
private Interactable interactable;
|
|
|
|
|
|
private bool isUnlocked = false;
|
|
|
|
|
|
|
|
|
|
|
|
void Awake()
|
|
|
|
|
|
{
|
|
|
|
|
|
interactable = GetComponent<Interactable>();
|
2025-09-03 16:55:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void OnEnable()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (interactable == null)
|
|
|
|
|
|
interactable = GetComponent<Interactable>();
|
2025-09-03 15:43:47 +02:00
|
|
|
|
if (interactable != null)
|
2025-09-04 15:01:28 +02:00
|
|
|
|
{
|
|
|
|
|
|
interactable.StartedInteraction += OnStartedInteraction;
|
|
|
|
|
|
interactable.InteractionComplete += OnInteractionComplete;
|
|
|
|
|
|
// Removed old Interacted subscription
|
|
|
|
|
|
}
|
2025-09-03 15:43:47 +02:00
|
|
|
|
PuzzleManager.Instance?.RegisterStepBehaviour(this);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-03 16:55:21 +02:00
|
|
|
|
void OnDisable()
|
2025-09-03 15:43:47 +02:00
|
|
|
|
{
|
|
|
|
|
|
if (interactable != null)
|
2025-09-04 15:01:28 +02:00
|
|
|
|
{
|
|
|
|
|
|
interactable.StartedInteraction -= OnStartedInteraction;
|
|
|
|
|
|
interactable.InteractionComplete -= OnInteractionComplete;
|
|
|
|
|
|
// Removed old Interacted unsubscription
|
|
|
|
|
|
}
|
2025-09-03 15:43:47 +02:00
|
|
|
|
PuzzleManager.Instance?.UnregisterStepBehaviour(this);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void UnlockStep()
|
|
|
|
|
|
{
|
|
|
|
|
|
isUnlocked = true;
|
|
|
|
|
|
Debug.Log($"[Puzzles] Step unlocked: {stepData?.stepId} on {gameObject.name}");
|
|
|
|
|
|
// Optionally, show visual feedback for unlocked state
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void LockStep()
|
|
|
|
|
|
{
|
|
|
|
|
|
isUnlocked = false;
|
|
|
|
|
|
Debug.Log($"[Puzzles] Step locked: {stepData?.stepId} on {gameObject.name}");
|
|
|
|
|
|
// Optionally, show visual feedback for locked state
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool IsStepUnlocked()
|
|
|
|
|
|
{
|
|
|
|
|
|
return isUnlocked;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-04 15:01:28 +02:00
|
|
|
|
private void OnStartedInteraction()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Optionally handle started interaction (e.g. visual feedback)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnInteractionComplete(bool success)
|
2025-09-03 15:43:47 +02:00
|
|
|
|
{
|
|
|
|
|
|
if (!isUnlocked) return;
|
2025-09-04 15:01:28 +02:00
|
|
|
|
if (success)
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.Log($"[Puzzles] Step interacted: {stepData?.stepId} on {gameObject.name}");
|
|
|
|
|
|
PuzzleManager.Instance?.OnStepCompleted(stepData);
|
|
|
|
|
|
}
|
2025-09-03 15:43:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|