[Interaction] Zip up edge cases, base for interactions is now done

This commit is contained in:
Michal Pikulski
2025-09-04 15:01:28 +02:00
parent 05a8a5445f
commit 4215d4b437
4 changed files with 51 additions and 25 deletions

View File

@@ -3,7 +3,8 @@ using System;
public class Interactable : MonoBehaviour, ITouchInputConsumer
{
public event Action Interacted;
public event Action StartedInteraction;
public event Action<bool> 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<InteractionRequirementBase>();
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}");