radial menu work
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
|
||||
public enum JobPositions { Unemployed, Cashier, Clerk, ManagerAssistaint, Manager };
|
||||
public enum EducationSkill { NotEducated, School, HightSchool, University };
|
||||
public enum RadialMenuActions { Cancel, Sleep, Eat, Put, Take }
|
||||
public enum PlayerStates { Awake, Sleeping, Eating, Working }
|
||||
public enum StatsId { Money, RentAccount, Food, Energy, BankAccount, Job, }
|
||||
public enum Tasks { Move, Interact, Rotate };
|
||||
@@ -22,4 +21,16 @@ public enum AnimationStates
|
||||
[EnumMember(Value = "SitToStand")]
|
||||
[BlockingAnimation]
|
||||
Standing
|
||||
};
|
||||
};
|
||||
|
||||
public enum RadialMenuActions {
|
||||
Cancel,
|
||||
Sleep,
|
||||
Eat,
|
||||
Put,
|
||||
Take,
|
||||
Work,
|
||||
Talk,
|
||||
Buy ,
|
||||
Open
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -1,13 +1,18 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
public class Bed : BaseInteractableObject
|
||||
{
|
||||
|
||||
protected override void InteractAction()
|
||||
protected override void PrepareMenuActions()
|
||||
{
|
||||
_menuActions[RadialMenuActions.Sleep].IsEnabled = true;
|
||||
}
|
||||
|
||||
protected override void InteractAction(RadialMenuActions interactAction)
|
||||
{
|
||||
_player.SetPlayerAnimation(AnimationStates.Sitting, OnAnimationFinished);
|
||||
}
|
||||
|
||||
private void OnAnimationFinished()
|
||||
{
|
||||
UIManager.Instance.ShowTimeSliderDialog("Go to sleep", "Sleep until", OnCancel, OnConfirm);
|
||||
|
||||
@@ -11,26 +11,43 @@ public class CashierDesk : BaseInteractableObject
|
||||
private List<JobInfoSO> _jobsInfoList;
|
||||
private JobInfoSO _playerJob;
|
||||
|
||||
protected override void InteractAction()
|
||||
private bool CheckIfPlayerHaveItems()
|
||||
{
|
||||
if (_player.IsHoldContainerItem())
|
||||
{
|
||||
BuyItems();
|
||||
var playerContainer = _player.GetContainerItem();
|
||||
if (playerContainer.IsSalebleItems())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_playerJob = _jobsInfoList.Where(x => x.JobPosition == _player.JobPosition).FirstOrDefault();
|
||||
print($"playerJob is {_playerJob}");
|
||||
if (_playerJob != null)
|
||||
{
|
||||
UIManager.Instance.ShowTimeSliderDialog($"Work", $"Work as {_playerJob.Description}", OnCancel, OnConfirm);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
print("You don't work here");
|
||||
}
|
||||
}
|
||||
protected override void PrepareMenuActions()
|
||||
{
|
||||
_playerJob = _jobsInfoList.Where(x => x.JobPosition == _player.JobPosition).FirstOrDefault();
|
||||
if (_playerJob != null)
|
||||
_menuActions[RadialMenuActions.Work].IsEnabled = true;
|
||||
|
||||
_menuActions[RadialMenuActions.Buy].IsEnabled = CheckIfPlayerHaveItems();
|
||||
|
||||
}
|
||||
|
||||
protected override void InteractAction(RadialMenuActions interactAction)
|
||||
{
|
||||
switch (interactAction)
|
||||
{
|
||||
case RadialMenuActions.Buy:
|
||||
BuyItems();
|
||||
break;
|
||||
case RadialMenuActions.Work:
|
||||
UIManager.Instance.ShowTimeSliderDialog($"Work", $"Work as {_playerJob.Description}", OnCancel, OnConfirm);
|
||||
break;
|
||||
default:
|
||||
print("unknown action");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void BuyItems()
|
||||
|
||||
@@ -17,7 +17,12 @@ public class Door : BaseInteractableObject
|
||||
|
||||
}
|
||||
|
||||
protected override void InteractAction()
|
||||
protected override void PrepareMenuActions()
|
||||
{
|
||||
_menuActions[RadialMenuActions.Open].IsEnabled = true;
|
||||
}
|
||||
|
||||
protected override void InteractAction(RadialMenuActions interactAction)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_exitName))
|
||||
{
|
||||
|
||||
@@ -7,18 +7,34 @@ public class Fridge : BaseInteractableObject
|
||||
{
|
||||
[SerializeField]
|
||||
private ContainerSO _containerSO;
|
||||
[SerializeField]
|
||||
//private ItemActionsUI _actionsMenu;
|
||||
|
||||
|
||||
private List<FoodItemSO> _foodObjects = new List<FoodItemSO>();
|
||||
|
||||
protected override void InteractAction()
|
||||
{
|
||||
private bool CheckIfPlayerHaveItems()
|
||||
{
|
||||
if (_player.IsHoldContainerItem())
|
||||
{
|
||||
var playerContainer = _player.GetContainerItem();
|
||||
if (!playerContainer.IsSalebleItems())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected override void PrepareMenuActions()
|
||||
{
|
||||
_menuActions[RadialMenuActions.Put].IsEnabled = CheckIfPlayerHaveItems();
|
||||
_menuActions[RadialMenuActions.Eat].IsEnabled = _foodObjects.Count > 0;
|
||||
}
|
||||
|
||||
protected override void InteractAction(RadialMenuActions interactAction)
|
||||
{
|
||||
switch (interactAction)
|
||||
{
|
||||
case RadialMenuActions.Put:
|
||||
var playerContainer = _player.GetContainerItem();
|
||||
if (_foodObjects.Count + playerContainer.GetItems().Count <= _containerSO.MaxCapacity)
|
||||
{
|
||||
foreach (FoodItemSO item in playerContainer.GetItems())
|
||||
@@ -31,19 +47,13 @@ public class Fridge : BaseInteractableObject
|
||||
}
|
||||
else
|
||||
Debug.Log($"Fridge is full");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//Eat menu
|
||||
if (_foodObjects.Count > 0)
|
||||
{
|
||||
break;
|
||||
case RadialMenuActions.Eat:
|
||||
var hunger = _player.Stats[StatsId.Food].MaxValue - _player.Stats[StatsId.Food].Value;
|
||||
var eatingItems = _foodObjects.Count < (hunger / 10) ? _foodObjects.Count : (hunger / 10);
|
||||
StartCoroutine(EatRoutine(eatingItems));
|
||||
_foodObjects.RemoveRange(0, (int)eatingItems);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using static UnityEditor.Experimental.GraphView.GraphView;
|
||||
|
||||
public class OfficeTable : BaseInteractableObject
|
||||
{
|
||||
[SerializeField]
|
||||
private JobsListSO _jobPositionsSO;
|
||||
|
||||
protected override void InteractAction()
|
||||
protected override void PrepareMenuActions()
|
||||
{
|
||||
_menuActions[RadialMenuActions.Talk].IsEnabled = true;
|
||||
}
|
||||
|
||||
protected override void InteractAction(RadialMenuActions interactAction)
|
||||
{
|
||||
UIManager.Instance.ShowJobSelectionDialog("Job agency", null, OnConfirm);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
public class RadialMenuActionDescription
|
||||
{
|
||||
public bool IsEnabled { get; set; }
|
||||
public string Description { get; set; }
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 844a7de838b26b349aac023a7c8057d6
|
||||
guid: c6bfbb59bd3f3234e947cc44069cfe7d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -4,21 +4,22 @@ public class ShopingContainer : BaseInteractableObject
|
||||
{
|
||||
[SerializeField]
|
||||
private ContainerSO _containerSO;
|
||||
[SerializeField]
|
||||
//private ItemActionsUI _actionsMenu;
|
||||
|
||||
protected override void InteractAction()
|
||||
protected override void PrepareMenuActions()
|
||||
{
|
||||
if (!_player.IsHoldContainerItem())
|
||||
_menuActions[RadialMenuActions.Take].IsEnabled = true;
|
||||
}
|
||||
|
||||
protected override void InteractAction(RadialMenuActions interactAction)
|
||||
{
|
||||
var transform = Instantiate(_containerSO.prefab, _interactionPoint);
|
||||
var containerItem = transform.GetComponent<ContainerItem>();
|
||||
if (containerItem == null)
|
||||
{
|
||||
var transform = Instantiate(_containerSO.prefab, _interactionPoint);
|
||||
var containerItem = transform.GetComponent<ContainerItem>();
|
||||
if (containerItem == null)
|
||||
{
|
||||
Debug.LogError("Container Item is null");
|
||||
return;
|
||||
}
|
||||
_player.SetContainerItem(containerItem);
|
||||
Debug.LogError("Container Item is null");
|
||||
return;
|
||||
}
|
||||
_player.SetContainerItem(containerItem);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,14 +6,16 @@ public class StoreContainer : BaseInteractableObject
|
||||
[SerializeField]
|
||||
private SellableItemSO _sellableItemSO;
|
||||
|
||||
protected override void InteractAction()
|
||||
protected override void PrepareMenuActions()
|
||||
{
|
||||
if (_player.IsHoldContainerItem())
|
||||
{
|
||||
var clone = Instantiate(_sellableItemSO);
|
||||
_menuActions[RadialMenuActions.Take].IsEnabled = _player.IsHoldContainerItem();
|
||||
}
|
||||
|
||||
var container = _player.GetContainerItem();
|
||||
container.AddItem(clone);
|
||||
}
|
||||
protected override void InteractAction(RadialMenuActions interactAction)
|
||||
{
|
||||
var clone = Instantiate(_sellableItemSO);
|
||||
|
||||
var container = _player.GetContainerItem();
|
||||
container.AddItem(clone);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,4 +10,12 @@ public class WaypointVisual : BaseInteractableObject
|
||||
_interactionPoint.position = position;
|
||||
_particleSystem.Play();
|
||||
}
|
||||
|
||||
protected override void InteractAction(RadialMenuActions interactAction)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void PrepareMenuActions()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
[CreateAssetMenu()]
|
||||
public class RadialMenuActionSO : ScriptableObject
|
||||
{
|
||||
public string ActionName;
|
||||
public RadialMenuActions Action;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 844a7de838b26b349aac023a7c8057d6, type: 3}
|
||||
m_Name: Buy
|
||||
m_EditorClassIdentifier:
|
||||
ActionName: Buy
|
||||
Action: 7
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c9ce62334c9d8334d813197661a59227
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,16 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 844a7de838b26b349aac023a7c8057d6, type: 3}
|
||||
m_Name: Talk
|
||||
m_EditorClassIdentifier:
|
||||
ActionName: Talk
|
||||
Action: 6
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 82dbb912f2c862b40b39813703894e50
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,16 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 844a7de838b26b349aac023a7c8057d6, type: 3}
|
||||
m_Name: Work
|
||||
m_EditorClassIdentifier:
|
||||
ActionName: Work
|
||||
Action: 5
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 71be1340ac987bc40bd4b01367b3abf5
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
@@ -8,10 +9,10 @@ public class RadialMenuItem : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private Button _radialMenuItemPrefab;
|
||||
private Action<RadialMenuActionSO> _menuButtonClick=null;
|
||||
List<RadialMenuActionSO> _actions;
|
||||
private Action<RadialMenuActions> _menuButtonClick=null;
|
||||
private Dictionary<RadialMenuActions, RadialMenuActionDescription> _actions;
|
||||
|
||||
public void ShowButtons(List<RadialMenuActionSO> actions, Action<RadialMenuActionSO> menuButtonClick)
|
||||
public void ShowButtons(Dictionary<RadialMenuActions, RadialMenuActionDescription> actions, Action<RadialMenuActions> menuButtonClick)
|
||||
{
|
||||
_actions = actions;
|
||||
_menuButtonClick = menuButtonClick;
|
||||
@@ -28,19 +29,19 @@ public class RadialMenuItem : MonoBehaviour
|
||||
var textMeshPro = button.GetComponentInChildren<TextMeshProUGUI>();
|
||||
if (textMeshPro != null)
|
||||
{
|
||||
textMeshPro.text = actions[buttonsCount].ActionName;
|
||||
textMeshPro.text = actions.ElementAt(buttonsCount).Value.Description;
|
||||
}
|
||||
|
||||
AddEvent(button, buttonsCount);
|
||||
}
|
||||
}
|
||||
|
||||
void AddEvent(Button b, int i)
|
||||
void AddEvent(Button b, int buttonNumber)
|
||||
{
|
||||
b.onClick.AddListener(() =>
|
||||
{
|
||||
Hide();
|
||||
_menuButtonClick?.Invoke(_actions[i]);
|
||||
_menuButtonClick?.Invoke(_actions.ElementAt(buttonNumber).Key);
|
||||
CloseDialog();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ public class UIManager : MonoBehaviour
|
||||
jobSelector.ShowJobSelectionDialog(title, onCancel, onConfirm);
|
||||
}
|
||||
|
||||
public void ShowItemsMenu(List<RadialMenuActionSO> actions,Action<RadialMenuActionSO> itemsMenuCallback)
|
||||
public void ShowItemsMenu(Dictionary<RadialMenuActions, RadialMenuActionDescription> actions,Action<RadialMenuActions> itemsMenuCallback)
|
||||
{
|
||||
var popupMenu = Instantiate(_radialMenuItemPrefab);
|
||||
popupMenu.transform.transform.SetParent(transform, false);
|
||||
|
||||
Reference in New Issue
Block a user