45 lines
1.1 KiB
C#
45 lines
1.1 KiB
C#
using KitsuneCafe.System;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
|
|
namespace KitsuneCafe.Interaction
|
|
{
|
|
public class Interactable : MonoBehaviour, IInteractable
|
|
{
|
|
[SerializeField]
|
|
private bool oneTimeUse = false;
|
|
|
|
[SerializeField]
|
|
private UnityEvent<IInteractor> onTarget = default;
|
|
|
|
[SerializeField]
|
|
private UnityEvent<IInteractor> onInteracted = default;
|
|
|
|
private bool isInteractable = true;
|
|
|
|
public bool IsInteractable => isInteractable;
|
|
|
|
|
|
void IInteractable.Target(IInteractor interactor)
|
|
{
|
|
onTarget.Invoke(interactor);
|
|
}
|
|
|
|
public IResult<Unit, InteractionError> Interact(IInteractor interactor)
|
|
{
|
|
onInteracted.Invoke(interactor);
|
|
|
|
if (oneTimeUse)
|
|
{
|
|
isInteractable = false;
|
|
}
|
|
|
|
return Result.Ok<Unit, InteractionError>(default);
|
|
}
|
|
|
|
public void SetInteractable(bool interactable = true)
|
|
{
|
|
isInteractable = interactable;
|
|
}
|
|
}
|
|
}
|