refactor radial menu, every click work as cancel - problem with invoke in radial button add listener

This commit is contained in:
2023-11-17 12:57:32 +02:00
parent e03633616e
commit 6966ab8202
15 changed files with 170 additions and 187 deletions
+12 -30
View File
@@ -9,7 +9,7 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 168138392062545360}
- component: {fileID: 168138392062545363}
- component: {fileID: 6341650359450725483}
m_Layer: 0
m_Name: Selected
m_TagString: Untagged
@@ -24,6 +24,7 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 168138392062545361}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
@@ -31,9 +32,8 @@ Transform:
m_Children:
- {fileID: 199909838302166302}
m_Father: {fileID: 168138393772344589}
m_RootOrder: -1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &168138392062545363
--- !u!114 &6341650359450725483
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
@@ -42,15 +42,12 @@ MonoBehaviour:
m_GameObject: {fileID: 168138392062545361}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c67621cbedb3453428fcc7207806f507, type: 3}
m_Script: {fileID: 11500000, guid: 70ee3205d7b15b4449cdacc7a726e220, type: 3}
m_Name:
m_EditorClassIdentifier:
_selectedObject: {fileID: 5351194727339921736}
visualGameObjectArray:
- {fileID: 199909838302166291}
- {fileID: 199909837917391647}
- {fileID: 199909837306106162}
- {fileID: 199909837468661505}
--- !u!1 &168138393772344594
GameObject:
m_ObjectHideFlags: 0
@@ -76,6 +73,7 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 168138393772344594}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0.7071068, z: 0, w: 0.7071068}
m_LocalPosition: {x: -0, y: 0, z: 8.643}
m_LocalScale: {x: 1, y: 1, z: 1}
@@ -85,7 +83,6 @@ Transform:
- {fileID: 6083021128705139609}
- {fileID: 168138392062545360}
m_Father: {fileID: 0}
m_RootOrder: -1
m_LocalEulerAnglesHint: {x: 0, y: 90, z: 0}
--- !u!65 &168138393772344588
BoxCollider:
@@ -121,6 +118,9 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
_interactionPoint: {fileID: 5360312089705388636}
_menuActions:
- {fileID: 11400000, guid: a45b050119410f149b0a257098cdaec5, type: 2}
- {fileID: 11400000, guid: 37a5860278daf904b976c61632085b3d, type: 2}
--- !u!1 &4960435320984939974
GameObject:
m_ObjectHideFlags: 0
@@ -144,13 +144,13 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4960435320984939974}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0.20000544, y: 0, z: 0.8500352}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 168138393772344589}
m_RootOrder: -1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &3165226905153932186
PrefabInstance:
@@ -261,17 +261,17 @@ PrefabInstance:
m_Modifications:
- target: {fileID: 9189065509065776645, guid: 8af73887c9cd7fa47a2f642969b20378,
type: 3}
propertyPath: m_Materials.Array.data[0]
propertyPath: 'm_Materials.Array.data[0]'
value:
objectReference: {fileID: 2100000, guid: 710613883f6dfb64889bf6134b4b15e3, type: 2}
- target: {fileID: 9189065509477827618, guid: 8af73887c9cd7fa47a2f642969b20378,
type: 3}
propertyPath: m_Materials.Array.data[0]
propertyPath: 'm_Materials.Array.data[0]'
value:
objectReference: {fileID: 2100000, guid: 710613883f6dfb64889bf6134b4b15e3, type: 2}
- target: {fileID: 9189065510491252737, guid: 8af73887c9cd7fa47a2f642969b20378,
type: 3}
propertyPath: m_Materials.Array.data[0]
propertyPath: 'm_Materials.Array.data[0]'
value:
objectReference: {fileID: 2100000, guid: 710613883f6dfb64889bf6134b4b15e3, type: 2}
- target: {fileID: 9189065510491252739, guid: 8af73887c9cd7fa47a2f642969b20378,
@@ -359,24 +359,6 @@ PrefabInstance:
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 8af73887c9cd7fa47a2f642969b20378, type: 3}
--- !u!1 &199909837306106162 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 9189065509477827631, guid: 8af73887c9cd7fa47a2f642969b20378,
type: 3}
m_PrefabInstance: {fileID: 9025256075473245469}
m_PrefabAsset: {fileID: 0}
--- !u!1 &199909837468661505 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 9189065509120254492, guid: 8af73887c9cd7fa47a2f642969b20378,
type: 3}
m_PrefabInstance: {fileID: 9025256075473245469}
m_PrefabAsset: {fileID: 0}
--- !u!1 &199909837917391647 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 9189065509065776642, guid: 8af73887c9cd7fa47a2f642969b20378,
type: 3}
m_PrefabInstance: {fileID: 9025256075473245469}
m_PrefabAsset: {fileID: 0}
--- !u!1 &199909838302166291 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 9189065510491252750, guid: 8af73887c9cd7fa47a2f642969b20378,
@@ -11,7 +11,7 @@ GameObject:
- component: {fileID: 6177286257950370620}
- component: {fileID: 5424962769672562944}
m_Layer: 5
m_Name: PopupItemMenu
m_Name: RadialMenu
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
@@ -45,8 +45,8 @@ MonoBehaviour:
m_GameObject: {fileID: 6105977268906182483}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0dea2e9a092ecf643963bb697b9963ca, type: 3}
m_Script: {fileID: 11500000, guid: 0652e5472d3afcf4f8d99f61ca2dc62e, type: 3}
m_Name:
m_EditorClassIdentifier:
_popupMenuItemButtonPrefab: {fileID: 8504314472782682815, guid: 07f2894d03b374a4092012178c7bb823,
_radialMenuItemPrefab: {fileID: 8504314472782682815, guid: 07f2894d03b374a4092012178c7bb823,
type: 3}
@@ -13,7 +13,7 @@ GameObject:
- component: {fileID: 6614086836352695636}
- component: {fileID: 8504314472782682815}
m_Layer: 0
m_Name: PopupMenuItemButton
m_Name: RadialMenuItem
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
+70 -86
View File
@@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.1727681, g: 0.21589208, b: 0.29782575, a: 1}
m_IndirectSpecularColor: {r: 0.17276844, g: 0.21589246, b: 0.2978263, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
@@ -238,6 +238,74 @@ Transform:
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &346725577
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 168138393772344589, guid: 910e671451e1bf94e9bba00c3809c94a,
type: 3}
propertyPath: m_LocalPosition.x
value: 3.35
objectReference: {fileID: 0}
- target: {fileID: 168138393772344589, guid: 910e671451e1bf94e9bba00c3809c94a,
type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 168138393772344589, guid: 910e671451e1bf94e9bba00c3809c94a,
type: 3}
propertyPath: m_LocalPosition.z
value: 4.34
objectReference: {fileID: 0}
- target: {fileID: 168138393772344589, guid: 910e671451e1bf94e9bba00c3809c94a,
type: 3}
propertyPath: m_LocalRotation.w
value: 0
objectReference: {fileID: 0}
- target: {fileID: 168138393772344589, guid: 910e671451e1bf94e9bba00c3809c94a,
type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 168138393772344589, guid: 910e671451e1bf94e9bba00c3809c94a,
type: 3}
propertyPath: m_LocalRotation.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 168138393772344589, guid: 910e671451e1bf94e9bba00c3809c94a,
type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 168138393772344589, guid: 910e671451e1bf94e9bba00c3809c94a,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 168138393772344589, guid: 910e671451e1bf94e9bba00c3809c94a,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 180
objectReference: {fileID: 0}
- target: {fileID: 168138393772344589, guid: 910e671451e1bf94e9bba00c3809c94a,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 168138393772344594, guid: 910e671451e1bf94e9bba00c3809c94a,
type: 3}
propertyPath: m_Name
value: Bed
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 910e671451e1bf94e9bba00c3809c94a, type: 3}
--- !u!114 &382878798
MonoBehaviour:
m_ObjectHideFlags: 0
@@ -8841,90 +8909,6 @@ ParticleSystem:
m_PostInfinity: 2
m_RotationOrder: 4
vectorLabel1_3: W
--- !u!1001 &639017915411924059
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 450881187641886026, guid: d6715af7517ca9f4297f69a69682ec47,
type: 3}
propertyPath: _menuActions.Array.size
value: 1
objectReference: {fileID: 0}
- target: {fileID: 450881187641886026, guid: d6715af7517ca9f4297f69a69682ec47,
type: 3}
propertyPath: '_menuActions.Array.data[0]'
value:
objectReference: {fileID: 11400000, guid: a45b050119410f149b0a257098cdaec5,
type: 2}
- target: {fileID: 2275578565027080912, guid: d6715af7517ca9f4297f69a69682ec47,
type: 3}
propertyPath: m_LocalPosition.x
value: 2.5483677
objectReference: {fileID: 0}
- target: {fileID: 2275578565027080912, guid: d6715af7517ca9f4297f69a69682ec47,
type: 3}
propertyPath: m_LocalPosition.y
value: -0.0017060019
objectReference: {fileID: 0}
- target: {fileID: 2275578565027080912, guid: d6715af7517ca9f4297f69a69682ec47,
type: 3}
propertyPath: m_LocalPosition.z
value: 3.8295152
objectReference: {fileID: 0}
- target: {fileID: 2275578565027080912, guid: d6715af7517ca9f4297f69a69682ec47,
type: 3}
propertyPath: m_LocalRotation.w
value: 0.7071068
objectReference: {fileID: 0}
- target: {fileID: 2275578565027080912, guid: d6715af7517ca9f4297f69a69682ec47,
type: 3}
propertyPath: m_LocalRotation.x
value: -0
objectReference: {fileID: 0}
- target: {fileID: 2275578565027080912, guid: d6715af7517ca9f4297f69a69682ec47,
type: 3}
propertyPath: m_LocalRotation.y
value: 0.7071068
objectReference: {fileID: 0}
- target: {fileID: 2275578565027080912, guid: d6715af7517ca9f4297f69a69682ec47,
type: 3}
propertyPath: m_LocalRotation.z
value: -0
objectReference: {fileID: 0}
- target: {fileID: 2275578565027080912, guid: d6715af7517ca9f4297f69a69682ec47,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2275578565027080912, guid: d6715af7517ca9f4297f69a69682ec47,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2275578565027080912, guid: d6715af7517ca9f4297f69a69682ec47,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5383733106295975035, guid: d6715af7517ca9f4297f69a69682ec47,
type: 3}
propertyPath: m_Name
value: Bed
objectReference: {fileID: 0}
- target: {fileID: 6200516510657557490, guid: d6715af7517ca9f4297f69a69682ec47,
type: 3}
propertyPath: m_Name
value: Bed_VisualSelected
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: d6715af7517ca9f4297f69a69682ec47, type: 3}
--- !u!1 &711676371307236306
GameObject:
m_ObjectHideFlags: 0
@@ -11459,6 +11443,6 @@ SceneRoots:
- {fileID: 343793322}
- {fileID: 2106647848}
- {fileID: 4029620109630900202}
- {fileID: 639017915411924059}
- {fileID: 1808427170}
- {fileID: 346725577}
- {fileID: 1468538260}
+2 -2
View File
@@ -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,5 +1,5 @@
fileFormatVersion: 2
guid: 0dea2e9a092ecf643963bb697b9963ca
guid: 0652e5472d3afcf4f8d99f61ca2dc62e
MonoImporter:
externalObjects: {}
serializedVersion: 2
+3 -3
View File
@@ -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);