From 6966ab82024d96f71df09f40a69c55035f1ebf39 Mon Sep 17 00:00:00 2001 From: Valdimir Date: Fri, 17 Nov 2023 12:57:32 +0200 Subject: [PATCH] refactor radial menu, every click work as cancel - problem with invoke in radial button add listener --- Assets/Prefabs/House/Bed.prefab | 42 ++--- ...PopupItemMenu.prefab => RadialMenu.prefab} | 6 +- ...enu.prefab.meta => RadialMenu.prefab.meta} | 0 ...temButton.prefab => RadialMenuItem.prefab} | 2 +- ...prefab.meta => RadialMenuItem.prefab.meta} | 0 Assets/Scenes/House.unity | 156 ++++++++---------- Assets/Scripts/Helpers/Enums.cs | 4 +- .../BaseInteractableObject.cs | 32 ++-- .../ScriptableObjects/ItemsMenuActionSO.cs | 8 - .../ScriptableObjects/RadialMenuActionSO.cs | 8 + ...nSO.cs.meta => RadialMenuActionSO.cs.meta} | 0 Assets/Scripts/UIElements/PopupItemMenu.cs | 43 ----- Assets/Scripts/UIElements/RadialMenuItem.cs | 48 ++++++ ...temMenu.cs.meta => RadialMenuItem.cs.meta} | 2 +- Assets/Scripts/UIElements/UIManager.cs | 6 +- 15 files changed, 170 insertions(+), 187 deletions(-) rename Assets/Prefabs/UI/{PopupItemMenu.prefab => RadialMenu.prefab} (87%) rename Assets/Prefabs/UI/{PopupItemMenu.prefab.meta => RadialMenu.prefab.meta} (100%) rename Assets/Prefabs/UI/{PopupMenuItemButton.prefab => RadialMenuItem.prefab} (99%) rename Assets/Prefabs/UI/{PopupMenuItemButton.prefab.meta => RadialMenuItem.prefab.meta} (100%) delete mode 100644 Assets/Scripts/ScriptableObjects/ItemsMenuActionSO.cs create mode 100644 Assets/Scripts/ScriptableObjects/RadialMenuActionSO.cs rename Assets/Scripts/ScriptableObjects/{ItemsMenuActionSO.cs.meta => RadialMenuActionSO.cs.meta} (100%) delete mode 100644 Assets/Scripts/UIElements/PopupItemMenu.cs create mode 100644 Assets/Scripts/UIElements/RadialMenuItem.cs rename Assets/Scripts/UIElements/{PopupItemMenu.cs.meta => RadialMenuItem.cs.meta} (83%) diff --git a/Assets/Prefabs/House/Bed.prefab b/Assets/Prefabs/House/Bed.prefab index d8271ef1..410c642c 100644 --- a/Assets/Prefabs/House/Bed.prefab +++ b/Assets/Prefabs/House/Bed.prefab @@ -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, diff --git a/Assets/Prefabs/UI/PopupItemMenu.prefab b/Assets/Prefabs/UI/RadialMenu.prefab similarity index 87% rename from Assets/Prefabs/UI/PopupItemMenu.prefab rename to Assets/Prefabs/UI/RadialMenu.prefab index acd4b1fd..e255966e 100644 --- a/Assets/Prefabs/UI/PopupItemMenu.prefab +++ b/Assets/Prefabs/UI/RadialMenu.prefab @@ -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} diff --git a/Assets/Prefabs/UI/PopupItemMenu.prefab.meta b/Assets/Prefabs/UI/RadialMenu.prefab.meta similarity index 100% rename from Assets/Prefabs/UI/PopupItemMenu.prefab.meta rename to Assets/Prefabs/UI/RadialMenu.prefab.meta diff --git a/Assets/Prefabs/UI/PopupMenuItemButton.prefab b/Assets/Prefabs/UI/RadialMenuItem.prefab similarity index 99% rename from Assets/Prefabs/UI/PopupMenuItemButton.prefab rename to Assets/Prefabs/UI/RadialMenuItem.prefab index 664b3ebf..c168b799 100644 --- a/Assets/Prefabs/UI/PopupMenuItemButton.prefab +++ b/Assets/Prefabs/UI/RadialMenuItem.prefab @@ -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 diff --git a/Assets/Prefabs/UI/PopupMenuItemButton.prefab.meta b/Assets/Prefabs/UI/RadialMenuItem.prefab.meta similarity index 100% rename from Assets/Prefabs/UI/PopupMenuItemButton.prefab.meta rename to Assets/Prefabs/UI/RadialMenuItem.prefab.meta diff --git a/Assets/Scenes/House.unity b/Assets/Scenes/House.unity index 4c87e71c..5b70d290 100644 --- a/Assets/Scenes/House.unity +++ b/Assets/Scenes/House.unity @@ -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} diff --git a/Assets/Scripts/Helpers/Enums.cs b/Assets/Scripts/Helpers/Enums.cs index aa775c6e..5c888c35 100644 --- a/Assets/Scripts/Helpers/Enums.cs +++ b/Assets/Scripts/Helpers/Enums.cs @@ -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")] diff --git a/Assets/Scripts/InteractableObjects/BaseInteractableObject.cs b/Assets/Scripts/InteractableObjects/BaseInteractableObject.cs index 69a89001..247e571f 100644 --- a/Assets/Scripts/InteractableObjects/BaseInteractableObject.cs +++ b/Assets/Scripts/InteractableObjects/BaseInteractableObject.cs @@ -7,20 +7,25 @@ public class BaseInteractableObject : MonoBehaviour [SerializeField] public Transform _interactionPoint; [SerializeField] - public List _menuActions; + public List _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() { - } + } } diff --git a/Assets/Scripts/ScriptableObjects/ItemsMenuActionSO.cs b/Assets/Scripts/ScriptableObjects/ItemsMenuActionSO.cs deleted file mode 100644 index af00e6b9..00000000 --- a/Assets/Scripts/ScriptableObjects/ItemsMenuActionSO.cs +++ /dev/null @@ -1,8 +0,0 @@ -using UnityEngine; - -[CreateAssetMenu()] -public class ItemsMenuActionSO : ScriptableObject -{ - public string ActionName; - public ItemsMenuActions Action; -} diff --git a/Assets/Scripts/ScriptableObjects/RadialMenuActionSO.cs b/Assets/Scripts/ScriptableObjects/RadialMenuActionSO.cs new file mode 100644 index 00000000..4025aa5a --- /dev/null +++ b/Assets/Scripts/ScriptableObjects/RadialMenuActionSO.cs @@ -0,0 +1,8 @@ +using UnityEngine; + +[CreateAssetMenu()] +public class RadialMenuActionSO : ScriptableObject +{ + public string ActionName; + public RadialMenuActions Action; +} diff --git a/Assets/Scripts/ScriptableObjects/ItemsMenuActionSO.cs.meta b/Assets/Scripts/ScriptableObjects/RadialMenuActionSO.cs.meta similarity index 100% rename from Assets/Scripts/ScriptableObjects/ItemsMenuActionSO.cs.meta rename to Assets/Scripts/ScriptableObjects/RadialMenuActionSO.cs.meta diff --git a/Assets/Scripts/UIElements/PopupItemMenu.cs b/Assets/Scripts/UIElements/PopupItemMenu.cs deleted file mode 100644 index 95e6b378..00000000 --- a/Assets/Scripts/UIElements/PopupItemMenu.cs +++ /dev/null @@ -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 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(); - 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); - } -} diff --git a/Assets/Scripts/UIElements/RadialMenuItem.cs b/Assets/Scripts/UIElements/RadialMenuItem.cs new file mode 100644 index 00000000..36ceca3d --- /dev/null +++ b/Assets/Scripts/UIElements/RadialMenuItem.cs @@ -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 actions, Action 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(); + 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); + } +} diff --git a/Assets/Scripts/UIElements/PopupItemMenu.cs.meta b/Assets/Scripts/UIElements/RadialMenuItem.cs.meta similarity index 83% rename from Assets/Scripts/UIElements/PopupItemMenu.cs.meta rename to Assets/Scripts/UIElements/RadialMenuItem.cs.meta index 4508f022..42f17558 100644 --- a/Assets/Scripts/UIElements/PopupItemMenu.cs.meta +++ b/Assets/Scripts/UIElements/RadialMenuItem.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 0dea2e9a092ecf643963bb697b9963ca +guid: 0652e5472d3afcf4f8d99f61ca2dc62e MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/Scripts/UIElements/UIManager.cs b/Assets/Scripts/UIElements/UIManager.cs index 0aa0a6f5..cf3d43bb 100644 --- a/Assets/Scripts/UIElements/UIManager.cs +++ b/Assets/Scripts/UIElements/UIManager.cs @@ -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 actions,Action itemsMenuCallback) + public void ShowItemsMenu(List actions,Action 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);