radial menu work
This commit is contained in:
@@ -2,23 +2,44 @@
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
public class BaseInteractableObject : MonoBehaviour
|
||||
public abstract class BaseInteractableObject : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
public Transform _interactionPoint;
|
||||
[SerializeField]
|
||||
public List<RadialMenuActionSO> _menuActions;
|
||||
|
||||
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 when _menuActions.Any():
|
||||
UIManager.Instance.ShowItemsMenu(_menuActions, PopupMenuCallback);
|
||||
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:
|
||||
@@ -29,7 +50,7 @@ public class BaseInteractableObject : MonoBehaviour
|
||||
{
|
||||
if (_player.IsPathComplete(_interactionPoint.position))
|
||||
{
|
||||
InteractAction();
|
||||
InteractAction(_selectedAction);
|
||||
_currentStatus = InteractionStatus.None;
|
||||
return InteractionStatus.Complete;
|
||||
}
|
||||
@@ -43,20 +64,20 @@ public class BaseInteractableObject : MonoBehaviour
|
||||
return _currentStatus;
|
||||
}
|
||||
|
||||
private void PopupMenuCallback(RadialMenuActionSO action)
|
||||
private void PopupMenuCallback(RadialMenuActions action)
|
||||
{
|
||||
if (action.Action == RadialMenuActions.Cancel)
|
||||
if (action == RadialMenuActions.Cancel)
|
||||
{
|
||||
_currentStatus = InteractionStatus.Complete;
|
||||
}
|
||||
else
|
||||
{
|
||||
_selectedAction= action;
|
||||
_currentStatus = InteractionStatus.InProgress;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void InteractAction()
|
||||
{
|
||||
protected abstract void InteractAction(RadialMenuActions interactAction);
|
||||
|
||||
}
|
||||
protected abstract void PrepareMenuActions();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user