using Input; using Interactions; using UnityEngine; namespace PuzzleS { /// /// Manages the state and interactions for a single puzzle step, including unlock/lock logic and event handling. /// [RequireComponent(typeof(Interactable))] public class ObjectiveStepBehaviour : MonoBehaviour { /// /// The data object representing this puzzle step. /// public PuzzleStepSO stepData; private Interactable _interactable; private bool _isUnlocked = false; void Awake() { _interactable = GetComponent(); } void OnEnable() { if (_interactable == null) _interactable = GetComponent(); if (_interactable != null) { _interactable.interactionStarted.AddListener(OnInteractionStarted); _interactable.interactionComplete.AddListener(OnInteractionComplete); } PuzzleManager.Instance?.RegisterStepBehaviour(this); } void OnDestroy() { if (_interactable != null) { _interactable.interactionStarted.RemoveListener(OnInteractionStarted); _interactable.interactionComplete.RemoveListener(OnInteractionComplete); } PuzzleManager.Instance?.UnregisterStepBehaviour(this); } /// /// Unlocks this puzzle step, allowing interaction. /// public void UnlockStep() { _isUnlocked = true; Debug.Log($"[Puzzles] Step unlocked: {stepData?.stepId} on {gameObject.name}"); // Optionally, show visual feedback for unlocked state } /// /// Locks this puzzle step, preventing interaction. /// public void LockStep() { _isUnlocked = false; Debug.Log($"[Puzzles] Step locked: {stepData?.stepId} on {gameObject.name}"); // Optionally, show visual feedback for locked state } /// /// Returns whether this step is currently unlocked. /// public bool IsStepUnlocked() { return _isUnlocked; } /// /// Handles the start of an interaction (can be used for visual feedback). /// private void OnInteractionStarted(PlayerTouchController playerRef, FollowerController followerRef) { // Optionally handle started interaction (e.g. visual feedback) } /// /// Handles completion of the interaction, notifies PuzzleManager if successful and unlocked. /// /// Whether the interaction was successful. private void OnInteractionComplete(bool success) { if (!_isUnlocked) return; if (success) { Debug.Log($"[Puzzles] Step interacted: {stepData?.stepId} on {gameObject.name}"); PuzzleManager.Instance?.OnStepCompleted(stepData); } } } }