diff --git a/Assets/Scripts/Interactable.cs b/Assets/Scripts/Interactable.cs index 920b9ac3..ab510edd 100644 --- a/Assets/Scripts/Interactable.cs +++ b/Assets/Scripts/Interactable.cs @@ -3,7 +3,8 @@ using System; public class Interactable : MonoBehaviour, ITouchInputConsumer { - public event Action Interacted; + public event Action StartedInteraction; + public event Action InteractionComplete; private ObjectiveStepBehaviour stepBehaviour; @@ -15,14 +16,9 @@ public class Interactable : MonoBehaviour, ITouchInputConsumer // Called by InputManager when this interactable is clicked/touched public void OnTouchPress(Vector2 worldPosition) { - if (stepBehaviour != null && !stepBehaviour.IsStepUnlocked()) - { - DebugUIMessage.Show("Item is not unlocked yet"); - Debug.Log("[Puzzles] Tried to interact with locked step: " + gameObject.name); - return; - } + // Defer lock check to follower arrival Debug.Log($"[Interactable] OnTouchPress at {worldPosition} on {gameObject.name}"); - Interacted?.Invoke(); + StartedInteraction?.Invoke(); } public void OnTouchPosition(Vector2 screenPosition) @@ -33,10 +29,18 @@ public class Interactable : MonoBehaviour, ITouchInputConsumer // Called when the follower arrives at this interactable public bool OnFollowerArrived(FollowerController follower) { + // Check if step is locked here + if (stepBehaviour != null && !stepBehaviour.IsStepUnlocked()) + { + DebugUIMessage.Show("Item is not unlocked yet"); + Debug.Log("[Puzzles] Tried to interact with locked step: " + gameObject.name); + InteractionComplete?.Invoke(false); + return false; + } var requirements = GetComponents(); if (requirements.Length == 0) { - // No requirements: allow default pickup + InteractionComplete?.Invoke(true); return true; } bool anySuccess = false; @@ -48,6 +52,7 @@ public class Interactable : MonoBehaviour, ITouchInputConsumer break; } } + InteractionComplete?.Invoke(anySuccess); if (!anySuccess) { Debug.Log($"[Interactable] No interaction requirements succeeded for {gameObject.name}"); diff --git a/Assets/Scripts/LevelSwitch.cs b/Assets/Scripts/LevelSwitch.cs index 6498e779..2e8720a7 100644 --- a/Assets/Scripts/LevelSwitch.cs +++ b/Assets/Scripts/LevelSwitch.cs @@ -12,14 +12,12 @@ public class LevelSwitch : MonoBehaviour void Awake() { _isActive = true; - if (iconRenderer == null) iconRenderer = GetComponent(); - interactable = GetComponent(); if (interactable != null) { - interactable.Interacted += OnInteracted; + interactable.StartedInteraction += OnStartedInteraction; } ApplySwitchData(); } @@ -28,7 +26,7 @@ public class LevelSwitch : MonoBehaviour { if (interactable != null) { - interactable.Interacted -= OnInteracted; + interactable.StartedInteraction -= OnStartedInteraction; } } @@ -52,7 +50,7 @@ public class LevelSwitch : MonoBehaviour } } - private async void OnInteracted() + private async void OnStartedInteraction() { Debug.Log($"LevelSwitch.OnInteracted: Switching to level {switchData?.targetLevelSceneName}"); if (switchData != null && !string.IsNullOrEmpty(switchData.targetLevelSceneName) && _isActive) diff --git a/Assets/Scripts/ObjectiveStepBehaviour.cs b/Assets/Scripts/ObjectiveStepBehaviour.cs index 2c43ddbe..67a10246 100644 --- a/Assets/Scripts/ObjectiveStepBehaviour.cs +++ b/Assets/Scripts/ObjectiveStepBehaviour.cs @@ -17,14 +17,22 @@ public class ObjectiveStepBehaviour : MonoBehaviour if (interactable == null) interactable = GetComponent(); if (interactable != null) - interactable.Interacted += OnInteracted; + { + interactable.StartedInteraction += OnStartedInteraction; + interactable.InteractionComplete += OnInteractionComplete; + // Removed old Interacted subscription + } PuzzleManager.Instance?.RegisterStepBehaviour(this); } void OnDisable() { if (interactable != null) - interactable.Interacted -= OnInteracted; + { + interactable.StartedInteraction -= OnStartedInteraction; + interactable.InteractionComplete -= OnInteractionComplete; + // Removed old Interacted unsubscription + } PuzzleManager.Instance?.UnregisterStepBehaviour(this); } @@ -47,10 +55,18 @@ public class ObjectiveStepBehaviour : MonoBehaviour return isUnlocked; } - private void OnInteracted() + private void OnStartedInteraction() + { + // Optionally handle started interaction (e.g. visual feedback) + } + + private void OnInteractionComplete(bool success) { if (!isUnlocked) return; - Debug.Log($"[Puzzles] Step interacted: {stepData?.stepId} on {gameObject.name}"); - PuzzleManager.Instance?.OnStepCompleted(stepData); + if (success) + { + Debug.Log($"[Puzzles] Step interacted: {stepData?.stepId} on {gameObject.name}"); + PuzzleManager.Instance?.OnStepCompleted(stepData); + } } } diff --git a/Assets/Scripts/Pickup.cs b/Assets/Scripts/Pickup.cs index 11684087..3e219289 100644 --- a/Assets/Scripts/Pickup.cs +++ b/Assets/Scripts/Pickup.cs @@ -16,7 +16,8 @@ public class Pickup : MonoBehaviour interactable = GetComponent(); if (interactable != null) { - interactable.Interacted += OnInteracted; + interactable.StartedInteraction += OnStartedInteraction; + interactable.InteractionComplete += OnInteractionComplete; } ApplyItemData(); } @@ -25,7 +26,8 @@ public class Pickup : MonoBehaviour { if (interactable != null) { - interactable.Interacted -= OnInteracted; + interactable.StartedInteraction -= OnStartedInteraction; + interactable.InteractionComplete -= OnInteractionComplete; } } @@ -67,7 +69,7 @@ public class Pickup : MonoBehaviour } } - private void OnInteracted() + private void OnStartedInteraction() { if (pickupInProgress) return; var playerObj = GameObject.FindGameObjectWithTag("Player"); @@ -84,16 +86,14 @@ public class Pickup : MonoBehaviour Debug.LogWarning("Pickup: PlayerTouchController or FollowerController missing."); return; } - // Use GameManager for playerStopDistance and followerPickupDelay float playerStopDistance = GameManager.Instance.PlayerStopDistance; float followerPickupDelay = GameManager.Instance.FollowerPickupDelay; - // Subscribe to cancellation event cachedPlayerController = playerController; void OnPlayerArrived() { playerController.OnArrivedAtTarget -= OnPlayerArrived; playerController.OnMoveToCancelled -= OnPlayerMoveCancelled; - pickupInProgress = true; // Only lock when follower is about to be dispatched + pickupInProgress = true; StartCoroutine(DispatchFollower()); } void OnPlayerMoveCancelled() @@ -138,4 +138,11 @@ public class Pickup : MonoBehaviour playerController.MoveToAndNotify(stopPoint); } } + + private void OnInteractionComplete(bool success) + { + // Only handle post-pickup logic here (e.g., feedback, item destruction) + if (!success) return; + // Optionally, add logic to disable the pickup or provide feedback + } }