Skip to content

Commit 821c8a3

Browse files
feat: simpler quitting flow (#579)
* Removed SettingsPanelCanvas from DDOL and added it to each scene * Now specifies that it should only quit the game on the prefab inside the MainMenu scene, otherwise always calls LeaveSession() * Moved injection in QuitPanel to GameStateBehaviour
1 parent 8cb5a6d commit 821c8a3

File tree

12 files changed

+86
-91
lines changed

12 files changed

+86
-91
lines changed

Assets/BossRoom/Prefabs/UI/SettingsPanelCanvas.prefab

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,7 +1568,7 @@ GameObject:
15681568
m_Icon: {fileID: 0}
15691569
m_NavMeshLayer: 0
15701570
m_StaticEditorFlags: 0
1571-
m_IsActive: 1
1571+
m_IsActive: 0
15721572
--- !u!224 &7464515512587493124
15731573
RectTransform:
15741574
m_ObjectHideFlags: 0
@@ -1641,7 +1641,7 @@ MonoBehaviour:
16411641
m_Script: {fileID: 11500000, guid: 063abc7eeacd3df4db23e185d26aab43, type: 3}
16421642
m_Name:
16431643
m_EditorClassIdentifier:
1644-
m_QuitButtonText: {fileID: 1810020744250180940}
1644+
m_QuitMode: 0
16451645
--- !u!1 &7139291127274050927
16461646
GameObject:
16471647
m_ObjectHideFlags: 0
@@ -2025,7 +2025,7 @@ MonoBehaviour:
20252025
m_HorizontalOverflow: 0
20262026
m_VerticalOverflow: 0
20272027
m_LineSpacing: 1
2028-
m_Text: 'Exit Game?
2028+
m_Text: 'Return to Menu?
20292029
20302030
'
20312031
--- !u!1 &8177924889016445002
@@ -2693,6 +2693,17 @@ PrefabInstance:
26932693
objectReference: {fileID: 0}
26942694
m_RemovedComponents: []
26952695
m_SourcePrefab: {fileID: 100100000, guid: addf3685293c35d48a673397c748f116, type: 3}
2696+
--- !u!114 &3993040222486159765 stripped
2697+
MonoBehaviour:
2698+
m_CorrespondingSourceObject: {fileID: 7721113380232533813, guid: addf3685293c35d48a673397c748f116, type: 3}
2699+
m_PrefabInstance: {fileID: 6650909944053036704}
2700+
m_PrefabAsset: {fileID: 0}
2701+
m_GameObject: {fileID: 0}
2702+
m_Enabled: 1
2703+
m_EditorHideFlags: 0
2704+
m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3}
2705+
m_Name:
2706+
m_EditorClassIdentifier:
26962707
--- !u!224 &3993040222838124397 stripped
26972708
RectTransform:
26982709
m_CorrespondingSourceObject: {fileID: 7721113380319664589, guid: addf3685293c35d48a673397c748f116, type: 3}
@@ -2715,4 +2726,4 @@ MonoBehaviour:
27152726
m_Script: {fileID: 11500000, guid: 1106bff381881f94187fe4be82e21554, type: 3}
27162727
m_Name:
27172728
m_EditorClassIdentifier:
2718-
m_QualityBtnText: {fileID: 0}
2729+
m_QualityBtnText: {fileID: 3993040222486159765}

Assets/BossRoom/Scenes/BossRoom.unity

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:a201b5fab7c70e1141de41d77fad6fbf1432a417078e671cdf98c8f179eba8a1
3-
size 492844
2+
oid sha256:f5587f5d1e82bfa08774734c89fe180eff94391a5fc08ba3fa8c01f474e9df3d
3+
size 497738
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:c567c2c519ab8d6b12d7c9759ec8d228451cc2280d37c3501a24b681773a25eb
3-
size 36967
2+
oid sha256:e8179f271b4ccb6536d6e4f017a591759d3e80ca2809667684c907300c1c5f92
3+
size 40830

Assets/BossRoom/Scenes/MainMenu.unity

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:6902954da5d6368d430ea4373fc5a42c9be98deaebbe313c3d279b0dbece098d
3-
size 78856
2+
oid sha256:ae6cf7edc25f198a59ea3e6076a6bc8c8ce631b4201b26fcfc3703b523977d8e
3+
size 83887

Assets/BossRoom/Scenes/PostGame.unity

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:c963f5f975ac11e6707da820f1daa60300e87323a7e81cc3a527f3c9b1fef827
3-
size 51516
2+
oid sha256:4c11f84c175b1dd9496d25f84bd4e0c29ca64c90df9346d1f26578dfef5523f6
3+
size 56409

Assets/BossRoom/Scenes/Startup.unity

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:b72ef30fe5939bc280416c3707afd0c6945d0ba5126d43f82a59f284dffe19d3
3-
size 35886
2+
oid sha256:4b25a7b1afa55c020e06da49b3dfa5a499af97a24052e58da5c1aad428597c28
3+
size 27108

Assets/BossRoom/Scripts/Client/Game/State/ClientCharSelectState.cs

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,9 @@ enum LobbyMode
101101

102102
Dictionary<LobbyMode, List<GameObject>> m_LobbyUIElementsByMode;
103103

104-
[SerializeField] GameObject[] m_GameObjectsThatWillBeInjectedAutomatically;
105-
DIScope m_Scope;
106-
107-
void Awake()
104+
protected override void Awake()
108105
{
109-
//creating a child scope just to have manual control over the lifetime of the things
110-
//that shouldn't live past the current scene existence
111-
m_Scope = new DIScope(DIScope.RootScope);
112-
113-
m_Scope.FinalizeScopeConstruction();
106+
base.Awake();
114107

115108
Instance = this;
116109
CharSelectData = GetComponent<CharSelectData>();
@@ -121,16 +114,6 @@ void Awake()
121114
{ LobbyMode.LobbyEnding, m_UIElementsForLobbyEnding },
122115
{ LobbyMode.FatalError, m_UIElementsForFatalError },
123116
};
124-
125-
foreach (var autoInjectedGameObject in m_GameObjectsThatWillBeInjectedAutomatically)
126-
{
127-
m_Scope.InjectIn(autoInjectedGameObject);
128-
}
129-
}
130-
131-
public override void OnDestroy()
132-
{
133-
m_Scope.Dispose();
134117
}
135118

136119
protected override void Start()

Assets/BossRoom/Scripts/Client/Game/State/ClientMainMenuState.cs

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,30 @@ public class ClientMainMenuState : GameStateBehaviour
2121
{
2222
public override GameState ActiveState { get { return GameState.MainMenu; } }
2323

24-
[SerializeField] GameObject[] m_GameObjectsThatWillBeInjectedAutomatically;
25-
DIScope m_Scope;
26-
2724
[SerializeField] NameGenerationData m_NameGenerationData;
2825
[SerializeField] LobbyUIMediator m_LobbyUIMediator;
2926
[SerializeField] IPUIMediator m_IPUIMediator;
3027

3128
[SerializeField] CanvasGroup m_MainMenuButtonsCanvasGroup;
3229
[SerializeField] GameObject m_SignInSpinner;
3330

34-
void Awake()
31+
protected override void Awake()
3532
{
3633
m_MainMenuButtonsCanvasGroup.interactable = false;
3734
m_LobbyUIMediator.Hide();
38-
DIScope.RootScope.InjectIn(this);
35+
base.Awake();
36+
}
37+
38+
protected override void InitializeScope()
39+
{
40+
Scope.BindInstanceAsSingle(m_NameGenerationData);
41+
Scope.BindInstanceAsSingle(m_LobbyUIMediator);
42+
Scope.BindInstanceAsSingle(m_IPUIMediator);
3943
}
4044

4145
[Inject]
4246
void InjectDependenciesAndInitialize(AuthenticationServiceFacade authServiceFacade, LocalLobbyUser localUser, LocalLobby localLobby)
4347
{
44-
m_Scope = new DIScope(DIScope.RootScope);
45-
46-
m_Scope.BindInstanceAsSingle(m_NameGenerationData);
47-
m_Scope.BindInstanceAsSingle(m_LobbyUIMediator);
48-
m_Scope.BindInstanceAsSingle(m_IPUIMediator);
49-
5048
var unityAuthenticationInitOptions = new InitializationOptions();
5149
var profile = ProfileManager.Profile;
5250
if (profile.Length > 0)
@@ -56,13 +54,6 @@ void InjectDependenciesAndInitialize(AuthenticationServiceFacade authServiceFaca
5654

5755
authServiceFacade.DoSignInAsync(OnAuthSignIn, OnSignInFailed, unityAuthenticationInitOptions);
5856

59-
m_Scope.FinalizeScopeConstruction();
60-
61-
foreach (var autoInjectedGameObject in m_GameObjectsThatWillBeInjectedAutomatically)
62-
{
63-
m_Scope.InjectIn(autoInjectedGameObject);
64-
}
65-
6657
void OnAuthSignIn()
6758
{
6859
m_MainMenuButtonsCanvasGroup.interactable = true;
@@ -81,11 +72,6 @@ void OnSignInFailed()
8172
}
8273
}
8374

84-
public override void OnDestroy()
85-
{
86-
m_Scope?.Dispose();
87-
}
88-
8975
public void OnStartClicked()
9076
{
9177
m_LobbyUIMediator.ToggleJoinLobbyUI();

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

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,42 @@
1+
using System;
12
using Unity.Multiplayer.Samples.BossRoom.Shared;
23
using Unity.Multiplayer.Samples.BossRoom.Shared.Infrastructure;
3-
using Unity.Netcode;
44
using UnityEngine;
5-
using UnityEngine.UI;
65

76
namespace Unity.Multiplayer.Samples.BossRoom.Client
87
{
98
public class UIQuitPanel : MonoBehaviour
109
{
10+
enum QuitMode
11+
{
12+
ReturnToMenu,
13+
QuitApplication
14+
}
15+
1116
[SerializeField]
12-
Text m_QuitButtonText;
17+
QuitMode m_QuitMode = QuitMode.ReturnToMenu;
1318

1419
ApplicationController m_ApplicationController;
1520

16-
private bool m_QuitMode = true;
1721

1822
[Inject]
19-
private void InjectDependencies(ApplicationController applicationController)
23+
void InjectDependencies(ApplicationController applicationController)
2024
{
2125
m_ApplicationController = applicationController;
2226
}
2327

24-
void OnEnable()
25-
{
26-
m_QuitMode = NetworkManager.Singleton == null || !NetworkManager.Singleton.IsListening;
27-
m_QuitButtonText.text = m_QuitMode ? "Exit Game?" : "Leave session?";
28-
}
29-
3028
public void Quit()
3129
{
32-
if (m_QuitMode)
33-
{
34-
m_ApplicationController.QuitGame();
35-
}
36-
else
30+
switch (m_QuitMode)
3731
{
38-
m_ApplicationController.LeaveSession();
32+
case QuitMode.ReturnToMenu:
33+
m_ApplicationController.LeaveSession();
34+
break;
35+
case QuitMode.QuitApplication:
36+
m_ApplicationController.QuitGame();
37+
break;
38+
default:
39+
throw new ArgumentOutOfRangeException();
3940
}
4041

4142
gameObject.SetActive(false);

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

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,8 @@ public class UISettingsCanvas : MonoBehaviour
1818

1919
void Awake()
2020
{
21-
// the settings canvas should exist in all scenes!
22-
DontDestroyOnLoad(gameObject);
23-
2421
// hide the settings window at startup (this is just to handle the common case where an artist forgets to disable the window in the prefab)
2522
DisablePanels();
26-
SceneManager.sceneLoaded += OnSceneLoaded;
27-
}
28-
29-
void OnDestroy()
30-
{
31-
SceneManager.sceneLoaded -= OnSceneLoaded;
32-
}
33-
34-
void OnSceneLoaded(Scene scene, LoadSceneMode loadSceneMode)
35-
{
36-
if (loadSceneMode == LoadSceneMode.Single)
37-
{
38-
DisablePanels();
39-
}
4023
}
4124

4225
void DisablePanels()

Assets/BossRoom/Scripts/Server/Game/State/ServerCharSelectState.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ public class ServerCharSelectState : GameStateBehaviour
1717

1818
Coroutine m_WaitToEndLobbyCoroutine;
1919

20-
void Awake()
20+
protected override void Awake()
2121
{
22+
base.Awake();
2223
CharSelectData = GetComponent<CharSelectData>();
2324
}
2425

Assets/BossRoom/Scripts/Shared/Game/State/GameStateBehaviour.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System;
2+
using Unity.Multiplayer.Samples.BossRoom.Shared.Infrastructure;
13
using Unity.Netcode;
24
using UnityEngine;
35

@@ -53,6 +55,29 @@ public virtual bool Persists
5355
/// </summary>
5456
private static GameObject s_ActiveStateGO;
5557

58+
public DIScope Scope
59+
{
60+
get => m_Scope;
61+
private set => m_Scope = value;
62+
}
63+
64+
DIScope m_Scope;
65+
66+
[SerializeField]
67+
GameObject[] m_GameObjectsThatWillBeInjectedAutomatically;
68+
69+
protected virtual void Awake()
70+
{
71+
DIScope.RootScope.InjectIn(this);
72+
Scope = new DIScope(DIScope.RootScope);
73+
InitializeScope();
74+
Scope.FinalizeScopeConstruction();
75+
foreach (var autoInjectedGameObject in m_GameObjectsThatWillBeInjectedAutomatically)
76+
{
77+
Scope.InjectIn(autoInjectedGameObject);
78+
}
79+
}
80+
5681
// Start is called before the first frame update
5782
protected virtual void Start()
5883
{
@@ -87,8 +112,13 @@ protected virtual void Start()
87112
}
88113
}
89114

115+
protected virtual void InitializeScope()
116+
{
117+
}
118+
90119
public override void OnDestroy()
91120
{
121+
Scope?.Dispose();
92122
base.OnDestroy();
93123
if (!Persists)
94124
{

0 commit comments

Comments
 (0)