63 lines
1.9 KiB
C#
63 lines
1.9 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
|
|
public class BaseInteractableObject : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
public Transform _interactionPoint;
|
|
[SerializeField]
|
|
public List<RadialMenuActionSO> _menuActions;
|
|
|
|
protected Player _player;
|
|
private InteractionStatus _currentStatus = InteractionStatus.None;
|
|
|
|
public InteractionStatus Interact(Player player)
|
|
{
|
|
_player = player;
|
|
switch (_currentStatus)
|
|
{
|
|
case InteractionStatus.None when _menuActions.Any():
|
|
UIManager.Instance.ShowItemsMenu(_menuActions, PopupMenuCallback);
|
|
_currentStatus = InteractionStatus.WaitForChoose;
|
|
break;
|
|
case InteractionStatus.Complete:
|
|
_currentStatus = InteractionStatus.None;
|
|
return InteractionStatus.Complete;
|
|
default:
|
|
if (_currentStatus != InteractionStatus.WaitForChoose && _currentStatus != InteractionStatus.Complete)
|
|
{
|
|
if (_player.IsPathComplete(_interactionPoint.position))
|
|
{
|
|
InteractAction();
|
|
_currentStatus = InteractionStatus.None;
|
|
return InteractionStatus.Complete;
|
|
}
|
|
else
|
|
{
|
|
_currentStatus = InteractionStatus.FarFromPlayer;
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
return _currentStatus;
|
|
}
|
|
|
|
private void PopupMenuCallback(RadialMenuActionSO action)
|
|
{
|
|
if (action.Action == RadialMenuActions.Cancel)
|
|
{
|
|
_currentStatus = InteractionStatus.Complete;
|
|
}
|
|
else
|
|
{
|
|
_currentStatus = InteractionStatus.InProgress;
|
|
}
|
|
}
|
|
|
|
protected virtual void InteractAction()
|
|
{
|
|
|
|
}
|
|
}
|