Skip to content

Commit 9cbfc39

Browse files
committed
Using GameState to determine if we quit or return to menu
1 parent 99610a6 commit 9cbfc39

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

Assets/BossRoom/Scripts/Client/UI/UIQuitPanel.cs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using Unity.Multiplayer.Samples.BossRoom.Shared;
23
using Unity.Multiplayer.Samples.BossRoom.Shared.Infrastructure;
34
using UnityEngine;
@@ -13,18 +14,31 @@ public class UIQuitPanel : MonoBehaviour
1314

1415
ApplicationController m_ApplicationController;
1516

16-
private bool m_QuitMode = true;
17+
bool m_QuitMode = true;
1718

1819
[Inject]
19-
private void InjectDependencies(ApplicationController applicationController)
20+
void InjectDependencies(ApplicationController applicationController)
2021
{
2122
m_ApplicationController = applicationController;
2223
}
2324

24-
void OnEnable()
25+
void Awake()
2526
{
26-
m_QuitMode = SceneManager.GetActiveScene().name == "MainMenu";
27-
m_QuitButtonText.text = m_QuitMode ? "Exit Game?" : "Return to menu?";
27+
SceneManager.sceneLoaded += SceneManagerOnsceneLoaded;
28+
}
29+
30+
void SceneManagerOnsceneLoaded(Scene scene, LoadSceneMode loadSceneMode)
31+
{
32+
var currentGameState = FindObjectOfType<GameStateBehaviour>();
33+
if (currentGameState != null)
34+
{
35+
m_QuitMode = (currentGameState.ActiveState == GameState.MainMenu);
36+
m_QuitButtonText.text = m_QuitMode ? "Exit Game?" : "Return to menu?";
37+
}
38+
else
39+
{
40+
Debug.LogError($"Scene {scene.name} does not contain a GameStateBehavior");
41+
}
2842
}
2943

3044
public void Quit()

0 commit comments

Comments
 (0)