File tree Expand file tree Collapse file tree 3 files changed +32
-20
lines changed
Net/UnityServices/Lobbies Expand file tree Collapse file tree 3 files changed +32
-20
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,8 @@ public class UIQuitPanel : MonoBehaviour
13
13
14
14
ApplicationController m_ApplicationController ;
15
15
16
+ private bool m_QuitMode = true ;
17
+
16
18
[ Inject ]
17
19
private void InjectDependencies ( ApplicationController applicationController )
18
20
{
@@ -21,14 +23,21 @@ private void InjectDependencies(ApplicationController applicationController)
21
23
22
24
void OnEnable ( )
23
25
{
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?" ;
27
28
}
28
29
29
30
public void Quit ( )
30
31
{
31
- m_ApplicationController . QuitGame ( ) ;
32
+ if ( m_QuitMode )
33
+ {
34
+ m_ApplicationController . QuitGame ( ) ;
35
+ }
36
+ else
37
+ {
38
+ m_ApplicationController . LeaveSession ( ) ;
39
+ }
40
+
32
41
gameObject . SetActive ( false ) ;
33
42
}
34
43
}
Original file line number Diff line number Diff line change @@ -96,24 +96,26 @@ private bool OnWantToQuit()
96
96
return canQuit ;
97
97
}
98
98
99
- public void QuitGame ( )
99
+ public void LeaveSession ( )
100
100
{
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 )
114
106
{
115
- Application . Quit ( ) ;
107
+ gameNetPortal . RequestDisconnect ( ) ;
116
108
}
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
117
119
}
118
120
}
119
121
}
Original file line number Diff line number Diff line change @@ -115,6 +115,7 @@ void OnSuccess(Lobby lobby)
115
115
CurrentUnityLobby = lobby ;
116
116
m_LocalLobby . ApplyRemoteData ( lobby ) ;
117
117
118
+ // as client, check if host is still in lobby
118
119
if ( ! m_LocalUser . IsHost )
119
120
{
120
121
foreach ( var lobbyUser in m_LocalLobby . LobbyUsers )
@@ -126,7 +127,7 @@ void OnSuccess(Lobby lobby)
126
127
}
127
128
m_UnityServiceErrorMessagePub . Publish ( new UnityServiceErrorMessage ( "Host left the lobby" , "Disconnecting." ) ) ;
128
129
ForceLeaveLobbyAttempt ( ) ;
129
- m_ApplicationController . QuitGame ( ) ;
130
+ // no need to disconnect Netcode, it should already be handled by Netcode's callback to disconnect
130
131
}
131
132
}
132
133
}
You can’t perform that action at this time.
0 commit comments