Skip to content

Commit

Permalink
Fixed bug with order of registering new panels
Browse files Browse the repository at this point in the history
  • Loading branch information
saschaledermann committed Mar 4, 2024
1 parent a83419a commit 4271a20
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 14 additions & 1 deletion Scripts/UI/HandMenu/HandMenuController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class HandMenuController : MonoBehaviour

[HideInInspector] public bool openLastPanel;
MenuPanel m_lastPanel = null;
bool m_initialized = false;
EventTrigger.Entry m_hover;
EventTrigger.Entry m_click;
EventTrigger.Entry m_deselect;
Expand Down Expand Up @@ -92,7 +93,9 @@ public void OpenMainPanel()

public void RegisterPanel(MenuPanel panel)
{
if (panel.TryGetComponent<MainPanel>(out var _)) return;
// if (panel.TryGetComponent<MainPanel>(out var _)) return;
if (!m_initialized)
InitializeMainPanel();

panel.transform.SetParent(transform);
panel.transform.SetPositionAndRotation(_panels.First().transform.position, _panels.First().transform.rotation);
Expand Down Expand Up @@ -130,6 +133,16 @@ public void UnregisterDynamicPanels()
}
}

void InitializeMainPanel()
{
if (_panels.First().TryGetComponent<MainPanel>(out var mainPanel))
{
m_initialized = true;
RegisterPanel(_panels.First());
mainPanel.SetHandMenuController(this);
}
}

void CloseAllPanels()
{
foreach (var panel in _panels) panel.gameObject.SetActive(false);
Expand Down
2 changes: 2 additions & 0 deletions Scripts/UI/HandMenu/MainPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,6 @@ public void RemovePanelButton(MenuPanel panel)
m_menuButtonDictionary.Remove(panel);
Destroy(button.gameObject);
}

public void SetHandMenuController(HandMenuController controller) => handMenuController = controller;
}

0 comments on commit 4271a20

Please sign in to comment.