Skip to content

Commit d1c55fa

Browse files
committed
lobby fix: Removing quit when lobby detects host left. (#505)
* Removing quit when lobby detects host left. This should already be handled by NGO side callback (on disconnect) Adding in-editor quit, to have the same behaviour * clearer quit vs leave * word fix in comment
1 parent b83d7b4 commit d1c55fa

File tree

3 files changed

+32
-20
lines changed

3 files changed

+32
-20
lines changed

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ public class UIQuitPanel : MonoBehaviour
1313

1414
ApplicationController m_ApplicationController;
1515

16+
private bool m_QuitMode = true;
17+
1618
[Inject]
1719
private void InjectDependencies(ApplicationController applicationController)
1820
{
@@ -21,14 +23,21 @@ private void InjectDependencies(ApplicationController applicationController)
2123

2224
void OnEnable()
2325
{
24-
m_QuitButtonText.text = NetworkManager.Singleton != null && NetworkManager.Singleton.IsListening ?
25-
"Leave session?" :
26-
"Exit Game?";
26+
m_QuitMode = NetworkManager.Singleton == null || !NetworkManager.Singleton.IsListening;
27+
m_QuitButtonText.text = m_QuitMode ? "Exit Game?" : "Leave session?";
2728
}
2829

2930
public void Quit()
3031
{
31-
m_ApplicationController.QuitGame();
32+
if (m_QuitMode)
33+
{
34+
m_ApplicationController.QuitGame();
35+
}
36+
else
37+
{
38+
m_ApplicationController.LeaveSession();
39+
}
40+
3241
gameObject.SetActive(false);
3342
}
3443
}

Assets/BossRoom/Scripts/Shared/ApplicationController.cs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -96,24 +96,26 @@ private bool OnWantToQuit()
9696
return canQuit;
9797
}
9898

99-
public void QuitGame()
99+
public void LeaveSession()
100100
{
101-
if (NetworkManager.Singleton.IsListening)
102-
{
103-
m_LobbyServiceFacade.ForceLeaveLobbyAttempt();
104-
105-
// first disconnect then return to menu
106-
var gameNetPortal = GameNetPortal.Instance;
107-
if (gameNetPortal != null)
108-
{
109-
gameNetPortal.RequestDisconnect();
110-
}
111-
SceneManager.LoadScene("MainMenu");
112-
}
113-
else
101+
m_LobbyServiceFacade.ForceLeaveLobbyAttempt();
102+
103+
// first disconnect then return to menu
104+
var gameNetPortal = GameNetPortal.Instance;
105+
if (gameNetPortal != null)
114106
{
115-
Application.Quit();
107+
gameNetPortal.RequestDisconnect();
116108
}
109+
SceneManager.LoadScene("MainMenu");
110+
}
111+
112+
public void QuitGame()
113+
{
114+
#if UNITY_EDITOR
115+
UnityEditor.EditorApplication.isPlaying = false;
116+
#else
117+
Application.Quit();
118+
#endif
117119
}
118120
}
119121
}

Assets/BossRoom/Scripts/Shared/Net/UnityServices/Lobbies/LobbyServiceFacade.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ void OnSuccess(Lobby lobby)
115115
CurrentUnityLobby = lobby;
116116
m_LocalLobby.ApplyRemoteData(lobby);
117117

118+
// as client, check if host is still in lobby
118119
if (!m_LocalUser.IsHost)
119120
{
120121
foreach (var lobbyUser in m_LocalLobby.LobbyUsers)
@@ -126,7 +127,7 @@ void OnSuccess(Lobby lobby)
126127
}
127128
m_UnityServiceErrorMessagePub.Publish(new UnityServiceErrorMessage("Host left the lobby","Disconnecting."));
128129
ForceLeaveLobbyAttempt();
129-
m_ApplicationController.QuitGame();
130+
// no need to disconnect Netcode, it should already be handled by Netcode's callback to disconnect
130131
}
131132
}
132133
}

0 commit comments

Comments
 (0)