2025-09-01 16:14:21 +02:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
|
|
public class Interactable : MonoBehaviour, ITouchInputConsumer
|
|
|
|
|
|
{
|
2025-09-04 15:01:28 +02:00
|
|
|
|
public event Action StartedInteraction;
|
|
|
|
|
|
public event Action<bool> InteractionComplete;
|
2025-09-01 16:14:21 +02:00
|
|
|
|
|
2025-09-03 15:43:47 +02:00
|
|
|
|
private ObjectiveStepBehaviour stepBehaviour;
|
|
|
|
|
|
|
|
|
|
|
|
void Awake()
|
|
|
|
|
|
{
|
|
|
|
|
|
stepBehaviour = GetComponent<ObjectiveStepBehaviour>();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-01 16:14:21 +02:00
|
|
|
|
// Called by InputManager when this interactable is clicked/touched
|
|
|
|
|
|
public void OnTouchPress(Vector2 worldPosition)
|
|
|
|
|
|
{
|
2025-09-04 15:01:28 +02:00
|
|
|
|
// Defer lock check to follower arrival
|
2025-09-03 15:43:47 +02:00
|
|
|
|
Debug.Log($"[Interactable] OnTouchPress at {worldPosition} on {gameObject.name}");
|
2025-09-04 15:01:28 +02:00
|
|
|
|
StartedInteraction?.Invoke();
|
2025-09-01 16:14:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void OnTouchPosition(Vector2 screenPosition)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Optionally handle drag/move here
|
|
|
|
|
|
}
|
2025-09-04 13:08:14 +02:00
|
|
|
|
|
|
|
|
|
|
// Called when the follower arrives at this interactable
|
|
|
|
|
|
public bool OnFollowerArrived(FollowerController follower)
|
|
|
|
|
|
{
|
2025-09-04 15:01:28 +02:00
|
|
|
|
// 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;
|
|
|
|
|
|
}
|
2025-09-04 13:08:14 +02:00
|
|
|
|
var requirements = GetComponents<InteractionRequirementBase>();
|
|
|
|
|
|
if (requirements.Length == 0)
|
|
|
|
|
|
{
|
2025-09-04 15:01:28 +02:00
|
|
|
|
InteractionComplete?.Invoke(true);
|
2025-09-04 13:08:14 +02:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
bool anySuccess = false;
|
|
|
|
|
|
foreach (var req in requirements)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (req.TryInteract(follower))
|
|
|
|
|
|
{
|
|
|
|
|
|
anySuccess = true;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-09-04 15:01:28 +02:00
|
|
|
|
InteractionComplete?.Invoke(anySuccess);
|
2025-09-04 13:08:14 +02:00
|
|
|
|
if (!anySuccess)
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.Log($"[Interactable] No interaction requirements succeeded for {gameObject.name}");
|
|
|
|
|
|
// Optionally trigger a default failure event or feedback here
|
|
|
|
|
|
}
|
|
|
|
|
|
return anySuccess;
|
|
|
|
|
|
}
|
2025-09-01 16:14:21 +02:00
|
|
|
|
}
|