fix popup item menu and refactor ui system

This commit is contained in:
Vova
2023-12-11 16:16:18 +02:00
parent bf088009f6
commit e7f082a774
14 changed files with 131 additions and 63 deletions
+91 -11
View File
@@ -1482,9 +1482,9 @@ RectTransform:
m_Children: [] m_Children: []
m_Father: {fileID: 349281313} m_Father: {fileID: 349281313}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1} m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 1} m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 250, y: -90} m_AnchoredPosition: {x: 250, y: 0}
m_SizeDelta: {x: 480, y: 0} m_SizeDelta: {x: 480, y: 0}
m_Pivot: {x: 0.5, y: 0.5} m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &249161732 --- !u!114 &249161732
@@ -1720,7 +1720,7 @@ GameObject:
- component: {fileID: 311736550} - component: {fileID: 311736550}
- component: {fileID: 311736549} - component: {fileID: 311736549}
m_Layer: 5 m_Layer: 5
m_Name: UICanvas m_Name: UISystem
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
@@ -2371,7 +2371,7 @@ GameObject:
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 1 m_IsActive: 0
--- !u!4 &416748197 --- !u!4 &416748197
Transform: Transform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -2381,7 +2381,7 @@ Transform:
m_GameObject: {fileID: 416748196} m_GameObject: {fileID: 416748196}
serializedVersion: 2 serializedVersion: 2
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 14.62, z: 0} m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 142.77245, y: 142.77245, z: 142.77245} m_LocalScale: {x: 142.77245, y: 142.77245, z: 142.77245}
m_ConstrainProportionsScale: 0 m_ConstrainProportionsScale: 0
m_Children: m_Children:
@@ -2733,6 +2733,7 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
_cameraSystem: {fileID: 1024770365} _cameraSystem: {fileID: 1024770365}
_uiSystem: {fileID: 311736549}
--- !u!1 &499491886 stripped --- !u!1 &499491886 stripped
GameObject: GameObject:
m_CorrespondingSourceObject: {fileID: 919132149155446097, guid: 06629d5387e888e408bfe1c0a360997a, m_CorrespondingSourceObject: {fileID: 919132149155446097, guid: 06629d5387e888e408bfe1c0a360997a,
@@ -3489,7 +3490,7 @@ Transform:
m_GameObject: {fileID: 629452253} m_GameObject: {fileID: 629452253}
serializedVersion: 2 serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 22, z: 0} m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 144.20016, y: 144.20016, z: 144.20016} m_LocalScale: {x: 144.20016, y: 144.20016, z: 144.20016}
m_ConstrainProportionsScale: 0 m_ConstrainProportionsScale: 0
m_Children: m_Children:
@@ -3903,7 +3904,7 @@ PrefabInstance:
- target: {fileID: 1595984948554774838, guid: bb469c3bf9d2c0f45be39b5b5a6ecfad, - target: {fileID: 1595984948554774838, guid: bb469c3bf9d2c0f45be39b5b5a6ecfad,
type: 3} type: 3}
propertyPath: m_LocalPosition.y propertyPath: m_LocalPosition.y
value: 21.7 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 1595984948554774838, guid: bb469c3bf9d2c0f45be39b5b5a6ecfad, - target: {fileID: 1595984948554774838, guid: bb469c3bf9d2c0f45be39b5b5a6ecfad,
type: 3} type: 3}
@@ -3965,6 +3966,11 @@ PrefabInstance:
propertyPath: m_Name propertyPath: m_Name
value: BaseSelectable value: BaseSelectable
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 5577632863133830020, guid: bb469c3bf9d2c0f45be39b5b5a6ecfad,
type: 3}
propertyPath: m_Layer
value: 6
objectReference: {fileID: 0}
- target: {fileID: 7696921292749295874, guid: bb469c3bf9d2c0f45be39b5b5a6ecfad, - target: {fileID: 7696921292749295874, guid: bb469c3bf9d2c0f45be39b5b5a6ecfad,
type: 3} type: 3}
propertyPath: _selectedObject propertyPath: _selectedObject
@@ -3998,7 +4004,7 @@ PrefabInstance:
- target: {fileID: 7908616180235619651, guid: bb469c3bf9d2c0f45be39b5b5a6ecfad, - target: {fileID: 7908616180235619651, guid: bb469c3bf9d2c0f45be39b5b5a6ecfad,
type: 3} type: 3}
propertyPath: m_LocalPosition.z propertyPath: m_LocalPosition.z
value: 15.53 value: -5.78
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 7908616180235619651, guid: bb469c3bf9d2c0f45be39b5b5a6ecfad, - target: {fileID: 7908616180235619651, guid: bb469c3bf9d2c0f45be39b5b5a6ecfad,
type: 3} type: 3}
@@ -4035,6 +4041,11 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z propertyPath: m_LocalEulerAnglesHint.z
value: -90 value: -90
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 8562307062121537200, guid: bb469c3bf9d2c0f45be39b5b5a6ecfad,
type: 3}
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: m_RemovedComponents:
- {fileID: 7696921292749295874, guid: bb469c3bf9d2c0f45be39b5b5a6ecfad, type: 3} - {fileID: 7696921292749295874, guid: bb469c3bf9d2c0f45be39b5b5a6ecfad, type: 3}
m_RemovedGameObjects: [] m_RemovedGameObjects: []
@@ -4170,7 +4181,7 @@ Transform:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 749553635} m_GameObject: {fileID: 749553635}
serializedVersion: 2 serializedVersion: 2
m_LocalRotation: {x: 0.38268346, y: -0.000000022481213, z: 0.000000009312023, w: 0.92387956} m_LocalRotation: {x: 0.38268346, y: 0.000000022481224, z: -0.0000000093120285, w: 0.92387956}
m_LocalPosition: {x: 29.11, y: 5, z: -5} m_LocalPosition: {x: 29.11, y: 5, z: -5}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0 m_ConstrainProportionsScale: 0
@@ -4787,7 +4798,7 @@ Transform:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 835327588} m_GameObject: {fileID: 835327588}
serializedVersion: 2 serializedVersion: 2
m_LocalRotation: {x: 0.38268346, y: -0.000000022481213, z: 0.000000009312023, w: 0.92387956} m_LocalRotation: {x: 0.38268346, y: 0.000000022481224, z: -0.0000000093120285, w: 0.92387956}
m_LocalPosition: {x: 29.11, y: 5, z: -5} m_LocalPosition: {x: 29.11, y: 5, z: -5}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0 m_ConstrainProportionsScale: 0
@@ -6725,6 +6736,74 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
_areaName: Central ave. _areaName: Central ave.
--- !u!1001 &1492983807
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 601545095124417014, guid: 0fafbaeeaa5eb474f92520556cd36c7a,
type: 3}
propertyPath: m_LocalPosition.x
value: 152.2527
objectReference: {fileID: 0}
- target: {fileID: 601545095124417014, guid: 0fafbaeeaa5eb474f92520556cd36c7a,
type: 3}
propertyPath: m_LocalPosition.y
value: 6.4799995
objectReference: {fileID: 0}
- target: {fileID: 601545095124417014, guid: 0fafbaeeaa5eb474f92520556cd36c7a,
type: 3}
propertyPath: m_LocalPosition.z
value: 243.27562
objectReference: {fileID: 0}
- target: {fileID: 601545095124417014, guid: 0fafbaeeaa5eb474f92520556cd36c7a,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 601545095124417014, guid: 0fafbaeeaa5eb474f92520556cd36c7a,
type: 3}
propertyPath: m_LocalRotation.x
value: -0
objectReference: {fileID: 0}
- target: {fileID: 601545095124417014, guid: 0fafbaeeaa5eb474f92520556cd36c7a,
type: 3}
propertyPath: m_LocalRotation.y
value: -0
objectReference: {fileID: 0}
- target: {fileID: 601545095124417014, guid: 0fafbaeeaa5eb474f92520556cd36c7a,
type: 3}
propertyPath: m_LocalRotation.z
value: -0
objectReference: {fileID: 0}
- target: {fileID: 601545095124417014, guid: 0fafbaeeaa5eb474f92520556cd36c7a,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 601545095124417014, guid: 0fafbaeeaa5eb474f92520556cd36c7a,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 601545095124417014, guid: 0fafbaeeaa5eb474f92520556cd36c7a,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2472413404894134240, guid: 0fafbaeeaa5eb474f92520556cd36c7a,
type: 3}
propertyPath: m_Name
value: StoreFrizer
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 0fafbaeeaa5eb474f92520556cd36c7a, type: 3}
--- !u!1 &1498687847 --- !u!1 &1498687847
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -9087,3 +9166,4 @@ SceneRoots:
- {fileID: 1880854723} - {fileID: 1880854723}
- {fileID: 495189437} - {fileID: 495189437}
- {fileID: 1291994925} - {fileID: 1291994925}
- {fileID: 1492983807}
@@ -39,7 +39,7 @@ public abstract class BaseInteractableObject : MonoBehaviour
{ {
case InteractionStatus.None: case InteractionStatus.None:
var filteredActions = _menuActions.Where(x => x.Value.IsEnabled).ToDictionary(i => i.Key, i => i.Value) ; var filteredActions = _menuActions.Where(x => x.Value.IsEnabled).ToDictionary(i => i.Key, i => i.Value) ;
UIManager.Instance.ShowItemsMenu(filteredActions, PopupMenuCallback); GameManager.Instance.UI.ShowItemPopupMenu(filteredActions, PopupMenuCallback);
_currentStatus = InteractionStatus.WaitForChoose; _currentStatus = InteractionStatus.WaitForChoose;
break; break;
case InteractionStatus.Complete: case InteractionStatus.Complete:
+1 -1
View File
@@ -15,7 +15,7 @@ public class Bed : BaseInteractableObject
private void OnAnimationFinished() private void OnAnimationFinished()
{ {
UIManager.Instance.ShowTimeSliderDialog("Go to sleep", "Sleep until", OnCancel, OnConfirm); GameManager.Instance.UI.ShowTimeSliderDialog("Go to sleep", "Sleep until", OnCancel, OnConfirm);
} }
private void OnCancel() private void OnCancel()
{ {
@@ -42,7 +42,7 @@ public class CashierDesk : BaseInteractableObject
BuyItems(); BuyItems();
break; break;
case RadialMenuActions.Work: case RadialMenuActions.Work:
UIManager.Instance.ShowTimeSliderDialog($"Work", $"Work as {_playerJob.Description}", OnCancel, OnConfirm); GameManager.Instance.UI.ShowTimeSliderDialog($"Work", $"Work as {_playerJob.Description}", OnCancel, OnConfirm);
break; break;
default: default:
print("unknown action"); print("unknown action");
@@ -12,7 +12,7 @@ public class OfficeTable : BaseInteractableObject
protected override void InteractAction(RadialMenuActions interactAction) protected override void InteractAction(RadialMenuActions interactAction)
{ {
UIManager.Instance.ShowJobSelectionDialog("Job agency", null, OnConfirm); GameManager.Instance.UI.ShowJobSelectionDialog("Job agency", null, OnConfirm);
} }
private void OnConfirm(JobInfoSO selectedJob) private void OnConfirm(JobInfoSO selectedJob)
@@ -11,13 +11,11 @@ public class SelectedVisual : MonoBehaviour
private void Start() private void Start()
{ {
InGameMouseHandler.OnSelectedObjectChanged += Mouse_OnSelectedObjectChanged; InGameMouseHandler.OnSelectedObjectChanged += Mouse_OnSelectedObjectChanged;
print($"{_selectedObject.name} is subscribed to OnSelectedObjectChanged");
} }
private void OnDestroy() private void OnDestroy()
{ {
InGameMouseHandler.OnSelectedObjectChanged -= Mouse_OnSelectedObjectChanged; InGameMouseHandler.OnSelectedObjectChanged -= Mouse_OnSelectedObjectChanged;
print($"{_selectedObject.name} is Unsubscribed to OnSelectedObjectChanged");
} }
private void Mouse_OnSelectedObjectChanged(object sender, OnSelectedObjectChangedEventArgs e) private void Mouse_OnSelectedObjectChanged(object sender, OnSelectedObjectChangedEventArgs e)
+5
View File
@@ -4,6 +4,9 @@ public class GameManager : MonoBehaviour
{ {
[SerializeField] [SerializeField]
private CameraSystem _cameraSystem; private CameraSystem _cameraSystem;
[SerializeField]
private UISystem _uiSystem;
private bool _isPause; private bool _isPause;
private InputSystem _inputSystem; private InputSystem _inputSystem;
@@ -14,6 +17,8 @@ public class GameManager : MonoBehaviour
public InputSystem Input => _inputSystem; public InputSystem Input => _inputSystem;
public SceneManager Scene => _sceneManager; public SceneManager Scene => _sceneManager;
public TimeSystem Time => _timeSystem; public TimeSystem Time => _timeSystem;
public UISystem UI => _uiSystem;
public static GameManager Instance { get; private set; } public static GameManager Instance { get; private set; }
private void Awake() private void Awake()
+5 -13
View File
@@ -39,6 +39,8 @@ public class InGameMouseHandler : UnityEngine.Object
{ {
if (!EventSystem.current.IsPointerOverGameObject()) if (!EventSystem.current.IsPointerOverGameObject())
{ {
GameManager.Instance.UI.ClosePopupMenu();
if (_selectedObject != null) if (_selectedObject != null)
{ {
_waypointVisual.SetWaypoint(_selectedObject._interactionPoint.position); _waypointVisual.SetWaypoint(_selectedObject._interactionPoint.position);
@@ -58,26 +60,16 @@ public class InGameMouseHandler : UnityEngine.Object
public void Update() public void Update()
{ {
_ray = _camera.ScreenPointToRay(Mouse.current.position.ReadValue()); _ray = _camera.ScreenPointToRay(Mouse.current.position.ReadValue());
//if(EventSystem.current.IsPointerOverGameObject())
//{
// return;
//}
//hide rounded menu
if (Physics.Raycast(_ray, out var mouseRaycastHit, 100f, _selectableLayerMask)) if (Physics.Raycast(_ray, out var mouseRaycastHit, 100f, _selectableLayerMask))
{ {
mouseRaycastHit.transform.TryGetComponent(out _selectedObject); mouseRaycastHit.transform.TryGetComponent(out _selectedObject);
if (_selectedObject != null) if (_selectedObject != null)
{ {
OnSelectedObjectChanged?.Invoke(this, new OnSelectedObjectChangedEventArgs() { SelectedObject = _selectedObject }); OnSelectedObjectChanged?.Invoke(this, new OnSelectedObjectChangedEventArgs() { SelectedObject = _selectedObject });
} return;
else
{
OnSelectedObjectChanged?.Invoke(this, new OnSelectedObjectChangedEventArgs() { SelectedObject = null });
} }
} }
else _selectedObject = null;
{ OnSelectedObjectChanged?.Invoke(this, new OnSelectedObjectChangedEventArgs() { SelectedObject = null });
OnSelectedObjectChanged?.Invoke(this, new OnSelectedObjectChangedEventArgs() { SelectedObject = null });
}
} }
} }
+2 -2
View File
@@ -31,7 +31,7 @@ public class JobSelectorUI : MonoBehaviour
public void ShowJobSelectionDialog(string title, Action onCancel, Action<JobInfoSO> onConfirm) public void ShowJobSelectionDialog(string title, Action onCancel, Action<JobInfoSO> onConfirm)
{ {
UIManager.Instance.Freeze(); GameManager.Instance.UI.Freeze();
gameObject.SetActive(true); gameObject.SetActive(true);
_title.text = title; _title.text = title;
@@ -95,7 +95,7 @@ public class JobSelectorUI : MonoBehaviour
private void CloseDialog() private void CloseDialog()
{ {
UIManager.Instance.Unfreeze(); GameManager.Instance.UI.Unfreeze();
Destroy(this); Destroy(this);
} }
+7 -7
View File
@@ -42,22 +42,22 @@ public class RadialMenuItem : MonoBehaviour
{ {
b.onClick.AddListener(() => b.onClick.AddListener(() =>
{ {
CloseDialog(); Close();
Hide();
_menuButtonClick?.Invoke(_actions.ElementAt(buttonNumber).Key); _menuButtonClick?.Invoke(_actions.ElementAt(buttonNumber).Key);
}); });
} }
private void CloseDialog() public void CancelAndClose()
{ {
UIManager.Instance.Unfreeze(); Close();
Destroy(_popupMenu); _menuButtonClick?.Invoke(RadialMenuActions.Cancel);
Destroy(this);
} }
private void Hide() private void Close()
{ {
GameManager.Instance.UI.Unfreeze();
Destroy(this);
gameObject.SetActive(false); gameObject.SetActive(false);
Destroy(gameObject); Destroy(gameObject);
} }
+2 -2
View File
@@ -22,7 +22,7 @@ public class TimeSliderUI : MonoBehaviour
{ {
GameManager.Instance.Time.OnFastForwardEnd += CloseDialog; GameManager.Instance.Time.OnFastForwardEnd += CloseDialog;
GameManager.Instance.Pause(); GameManager.Instance.Pause();
UIManager.Instance.Freeze(); GameManager.Instance.UI.Freeze();
gameObject.SetActive(true); gameObject.SetActive(true);
_title.text = title; _title.text = title;
@@ -46,7 +46,7 @@ public class TimeSliderUI : MonoBehaviour
private void CloseDialog() private void CloseDialog()
{ {
UIManager.Instance.Unfreeze(); GameManager.Instance.UI.Unfreeze();
Destroy(this); Destroy(this);
} }
@@ -2,7 +2,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
public class UIManager : MonoBehaviour public class UISystem : MonoBehaviour
{ {
[SerializeField] [SerializeField]
private TimeSliderUI _timeSliderPrefab; private TimeSliderUI _timeSliderPrefab;
@@ -13,16 +13,7 @@ public class UIManager : MonoBehaviour
[SerializeField] [SerializeField]
private RadialMenuItem _radialMenuItemPrefab; private RadialMenuItem _radialMenuItemPrefab;
public static UIManager Instance { get; private set; } RadialMenuItem _popupMenu;
private void Awake()
{
if (Instance != null)
{
return;
}
Instance = this;
}
private void Start() private void Start()
{ {
@@ -41,14 +32,21 @@ public class UIManager : MonoBehaviour
jobSelector.ShowJobSelectionDialog(title, onCancel, onConfirm); jobSelector.ShowJobSelectionDialog(title, onCancel, onConfirm);
} }
public void ShowItemsMenu(Dictionary<RadialMenuActions, RadialMenuActionDescription> actions,Action<RadialMenuActions> itemsMenuCallback) public void ShowItemPopupMenu(Dictionary<RadialMenuActions, RadialMenuActionDescription> actions,Action<RadialMenuActions> itemsMenuCallback)
{ {
var popupMenu = Instantiate(_radialMenuItemPrefab); _popupMenu = Instantiate(_radialMenuItemPrefab);
popupMenu.transform.transform.SetParent(transform, false); _popupMenu.transform.transform.SetParent(transform, false);
popupMenu.transform.position = Input.mousePosition; _popupMenu.transform.position = Input.mousePosition;
popupMenu.ShowButtons(popupMenu, actions,itemsMenuCallback); _popupMenu.ShowButtons(_popupMenu, actions,itemsMenuCallback);
} }
public void ClosePopupMenu()
{
if (_popupMenu != null)
{
_popupMenu.CancelAndClose();
}
}
public void Freeze() public void Freeze()
{ {
_blurOverlay.SetActive(true); _blurOverlay.SetActive(true);
@@ -58,9 +56,4 @@ public class UIManager : MonoBehaviour
{ {
_blurOverlay.SetActive(false); _blurOverlay.SetActive(false);
} }
private void OnDisable()
{
}
} }
+1 -1
View File
@@ -43,6 +43,6 @@ Material:
m_Colors: m_Colors:
- Albedo: {r: 0.056247775, g: 0.1509434, b: 0.15094337, a: 1} - Albedo: {r: 0.056247775, g: 0.1509434, b: 0.15094337, a: 1}
- bounds: {r: 10000, g: 500, b: 10000, a: 0} - bounds: {r: 10000, g: 500, b: 10000, a: 0}
- pos: {r: 0, g: -249.93333, b: 0, a: 0} - pos: {r: 0, g: -250, b: 0, a: 0}
m_BuildTextureStacks: [] m_BuildTextureStacks: []
m_AllowLocking: 1 m_AllowLocking: 1