84 lines
3.4 KiB
C#
84 lines
3.4 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
|
|
public abstract class BaseInteractableObject : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
public Transform _interactionPoint;
|
|
|
|
protected Dictionary<RadialMenuActions, RadialMenuActionDescription> _menuActions = new();
|
|
private RadialMenuActions _selectedAction;
|
|
protected Player _player;
|
|
private InteractionStatus _currentStatus = InteractionStatus.None;
|
|
|
|
private void Start()
|
|
{
|
|
|
|
_menuActions = new Dictionary<RadialMenuActions, RadialMenuActionDescription>
|
|
{
|
|
{ RadialMenuActions.Buy, new RadialMenuActionDescription() { Description = "Buy", IsEnabled = false } },
|
|
{ RadialMenuActions.Sleep, new RadialMenuActionDescription() { Description = "Sleep", IsEnabled = false } },
|
|
{ RadialMenuActions.Talk, new RadialMenuActionDescription() { Description = "Talk", IsEnabled = false } },
|
|
{ RadialMenuActions.Put, new RadialMenuActionDescription() { Description = "Put", IsEnabled = false } },
|
|
{ RadialMenuActions.Take, new RadialMenuActionDescription() { Description = "Take", IsEnabled = false } },
|
|
{ RadialMenuActions.Work, new RadialMenuActionDescription() { Description = "Work", IsEnabled = false } },
|
|
{ RadialMenuActions.Eat, new RadialMenuActionDescription() { Description = "Eat", IsEnabled = false } },
|
|
{ RadialMenuActions.Open, new RadialMenuActionDescription() { Description = "Open", IsEnabled = false } },
|
|
{ RadialMenuActions.Cancel, new RadialMenuActionDescription() { Description = "Cancel", IsEnabled = true } },
|
|
};
|
|
}
|
|
|
|
public InteractionStatus Interact(Player player)
|
|
{
|
|
_player = player;
|
|
|
|
PrepareMenuActions();
|
|
|
|
switch (_currentStatus)
|
|
{
|
|
case InteractionStatus.None:
|
|
var filteredActions = _menuActions.Where(x => x.Value.IsEnabled).ToDictionary(i => i.Key, i => i.Value) ;
|
|
UIManager.Instance.ShowItemsMenu(filteredActions, 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(_selectedAction);
|
|
_currentStatus = InteractionStatus.None;
|
|
return InteractionStatus.Complete;
|
|
}
|
|
else
|
|
{
|
|
_currentStatus = InteractionStatus.FarFromPlayer;
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
return _currentStatus;
|
|
}
|
|
|
|
private void PopupMenuCallback(RadialMenuActions action)
|
|
{
|
|
if (action == RadialMenuActions.Cancel)
|
|
{
|
|
_currentStatus = InteractionStatus.Complete;
|
|
}
|
|
else
|
|
{
|
|
_selectedAction= action;
|
|
_currentStatus = InteractionStatus.InProgress;
|
|
}
|
|
}
|
|
|
|
protected abstract void InteractAction(RadialMenuActions interactAction);
|
|
|
|
protected abstract void PrepareMenuActions();
|
|
}
|