refactor radial menu, every click work as cancel - problem with invoke in radial button add listener
This commit is contained in:
@@ -2,12 +2,12 @@
|
||||
|
||||
public enum JobPositions { Unemployed, Cashier, Clerk, ManagerAssistaint, Manager };
|
||||
public enum EducationSkill { NotEducated, School, HightSchool, University };
|
||||
public enum ItemsMenuActions { Cancel, Sleep, Eat, Put, Take }
|
||||
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 };
|
||||
public enum TaskStatus { Waiting, InProgress, Complete };
|
||||
public enum InteractionStatus { Complete, WaitForChoose, InProgress, FarFromPlayer };
|
||||
public enum InteractionStatus { None,Complete, WaitForChoose, InProgress, FarFromPlayer };
|
||||
public enum AnimationStates
|
||||
{
|
||||
[EnumMember(Value = "Idle")]
|
||||
|
||||
@@ -7,20 +7,25 @@ public class BaseInteractableObject : MonoBehaviour
|
||||
[SerializeField]
|
||||
public Transform _interactionPoint;
|
||||
[SerializeField]
|
||||
public List<ItemsMenuActionSO> _menuActions;
|
||||
public List<RadialMenuActionSO> _menuActions;
|
||||
|
||||
protected Player _player;
|
||||
private InteractionStatus _currentStatus=InteractionStatus.Complete;
|
||||
|
||||
private InteractionStatus _currentStatus = InteractionStatus.None;
|
||||
|
||||
public InteractionStatus Interact(Player player)
|
||||
{
|
||||
_player=player;
|
||||
if (_currentStatus == InteractionStatus.Complete && _menuActions.Any())
|
||||
_player = player;
|
||||
if (_currentStatus == InteractionStatus.None && _menuActions.Any())
|
||||
{
|
||||
UIManager.Instance.ShowItemsMenu(_menuActions,PopupMenuCallback);
|
||||
UIManager.Instance.ShowItemsMenu(_menuActions, PopupMenuCallback);
|
||||
_currentStatus = InteractionStatus.WaitForChoose;
|
||||
}
|
||||
else if(_currentStatus!=InteractionStatus.WaitForChoose)
|
||||
else if (_currentStatus == InteractionStatus.Complete)
|
||||
{
|
||||
_currentStatus = InteractionStatus.None;
|
||||
return InteractionStatus.Complete;
|
||||
}
|
||||
else if (_currentStatus != InteractionStatus.WaitForChoose && _currentStatus != InteractionStatus.Complete)
|
||||
{
|
||||
if (_player.IsPathComplete(_interactionPoint.position))
|
||||
{
|
||||
@@ -35,13 +40,20 @@ public class BaseInteractableObject : MonoBehaviour
|
||||
return _currentStatus;
|
||||
}
|
||||
|
||||
private void PopupMenuCallback()
|
||||
private void PopupMenuCallback(RadialMenuActionSO action)
|
||||
{
|
||||
_currentStatus = InteractionStatus.InProgress;
|
||||
if (action.Action == RadialMenuActions.Cancel)
|
||||
{
|
||||
_currentStatus = InteractionStatus.Complete;
|
||||
}
|
||||
else
|
||||
{
|
||||
_currentStatus = InteractionStatus.InProgress;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void InteractAction()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
[CreateAssetMenu()]
|
||||
public class ItemsMenuActionSO : ScriptableObject
|
||||
{
|
||||
public string ActionName;
|
||||
public ItemsMenuActions Action;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
using UnityEngine;
|
||||
|
||||
[CreateAssetMenu()]
|
||||
public class RadialMenuActionSO : ScriptableObject
|
||||
{
|
||||
public string ActionName;
|
||||
public RadialMenuActions Action;
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class PopupItemMenu : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private Button _popupMenuItemButtonPrefab;
|
||||
|
||||
public void ShowButtons(List<ItemsMenuActionSO> actions, Action menuButtonClick)
|
||||
{
|
||||
var button = Instantiate(_popupMenuItemButtonPrefab) as Button;
|
||||
button.transform.SetParent(transform, false);
|
||||
button.transform.localPosition = new Vector3(0, 100f, 0);
|
||||
|
||||
var textMeshPro = button.GetComponent<TextMeshPro>();
|
||||
if (textMeshPro != null)
|
||||
{
|
||||
textMeshPro.text = actions[0].ActionName;
|
||||
}
|
||||
|
||||
|
||||
button.onClick.AddListener(() =>
|
||||
{
|
||||
menuButtonClick?.Invoke();
|
||||
Hide();
|
||||
CloseDialog();
|
||||
});
|
||||
}
|
||||
private void CloseDialog()
|
||||
{
|
||||
UIManager.Instance.Unfreeze();
|
||||
Destroy(this);
|
||||
}
|
||||
|
||||
private void Hide()
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class RadialMenuItem : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private Button _radialMenuItemPrefab;
|
||||
|
||||
public void ShowButtons(List<RadialMenuActionSO> actions, Action<RadialMenuActionSO> menuButtonClick)
|
||||
{
|
||||
for (int buttonsCount = 0; buttonsCount < actions.Count; buttonsCount++)
|
||||
{
|
||||
var button = Instantiate(_radialMenuItemPrefab);
|
||||
button.transform.SetParent(transform, false);
|
||||
|
||||
float theta = (2 * Mathf.PI / actions.Count) * buttonsCount;
|
||||
float posX=Mathf.Sin(theta);
|
||||
float posY=Mathf.Cos(theta);
|
||||
|
||||
button.transform.localPosition = new Vector3(posX, posY, 0)*100f;
|
||||
var textMeshPro = button.GetComponentInChildren<TextMeshProUGUI>();
|
||||
if (textMeshPro != null)
|
||||
{
|
||||
textMeshPro.text = actions[buttonsCount].ActionName;
|
||||
}
|
||||
|
||||
button.onClick.AddListener(() =>
|
||||
{
|
||||
Hide();
|
||||
CloseDialog();
|
||||
menuButtonClick?.Invoke(actions[1]);
|
||||
});
|
||||
}
|
||||
}
|
||||
private void CloseDialog()
|
||||
{
|
||||
UIManager.Instance.Unfreeze();
|
||||
Destroy(this);
|
||||
}
|
||||
|
||||
private void Hide()
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0dea2e9a092ecf643963bb697b9963ca
|
||||
guid: 0652e5472d3afcf4f8d99f61ca2dc62e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -11,7 +11,7 @@ public class UIManager : MonoBehaviour
|
||||
[SerializeField]
|
||||
private GameObject _blurOverlay;
|
||||
[SerializeField]
|
||||
private PopupItemMenu _itemPopupMenuPrefab;
|
||||
private RadialMenuItem _radialMenuItemPrefab;
|
||||
|
||||
public static UIManager Instance { get; private set; }
|
||||
|
||||
@@ -41,9 +41,9 @@ public class UIManager : MonoBehaviour
|
||||
jobSelector.ShowJobSelectionDialog(title, onCancel, onConfirm);
|
||||
}
|
||||
|
||||
public void ShowItemsMenu(List<ItemsMenuActionSO> actions,Action itemsMenuCallback)
|
||||
public void ShowItemsMenu(List<RadialMenuActionSO> actions,Action<RadialMenuActionSO> itemsMenuCallback)
|
||||
{
|
||||
var popupMenu = Instantiate(_itemPopupMenuPrefab) as PopupItemMenu;
|
||||
var popupMenu = Instantiate(_radialMenuItemPrefab);
|
||||
popupMenu.transform.transform.SetParent(transform, false);
|
||||
popupMenu.transform.position = Input.mousePosition;
|
||||
popupMenu.ShowButtons(actions,itemsMenuCallback);
|
||||
|
||||
Reference in New Issue
Block a user