Make session panel Disconnect button an Exit in Main scene
In Main (no active session) the context-sensitive button now reads "Exit" and quits the application (stops play mode in the editor), so the player can leave the build without Alt+F4. Connected behaviour is unchanged: "Disconnect" leaves the session, "Back to Lobby" ends the match for the map authority. The button is now interactable whenever idle. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
da3938d089
commit
96bcf84b1e
1 file changed
+32
-7
@@ -20,10 +20,12 @@ using UnityEngine.InputSystem;
|
||||
///
|
||||
/// Overlay behaviour: the panel is always shown in Main (not connected). Once a connection is up it hides;
|
||||
/// in the lobby/map Esc toggles it back as a modal pause overlay (cursor freed, local gameplay suspended via
|
||||
/// <see cref="GameModeManager.SetPaused"/>). On the map the Disconnect button becomes "Back to Lobby" for the
|
||||
/// match authority (ends the match), while everyone else (in the lobby, or a non-authority client on the map)
|
||||
/// gets a plain disconnect. Only the visual <see cref="panelRoot"/> is toggled - this binder stays alive on
|
||||
/// its (always-active) canvas so it keeps reading Esc while the panel is hidden.
|
||||
/// <see cref="GameModeManager.SetPaused"/>). The Disconnect button is context-sensitive: in Main (not
|
||||
/// connected) it is an application "Exit" (quits the build, or stops play mode in the editor) so the player
|
||||
/// can leave without Alt+F4; on the map it becomes "Back to Lobby" for the match authority (ends the match);
|
||||
/// everyone else (in the lobby, or a non-authority client on the map) gets a plain disconnect. Only the
|
||||
/// visual <see cref="panelRoot"/> is toggled - this binder stays alive on its (always-active) canvas so it
|
||||
/// keeps reading Esc while the panel is hidden.
|
||||
/// </summary>
|
||||
public class OnlineSessionBrowserUI : MonoBehaviour
|
||||
{
|
||||
@@ -142,6 +144,14 @@ public class OnlineSessionBrowserUI : MonoBehaviour
|
||||
{
|
||||
if (!manager) return;
|
||||
|
||||
// In Main (no session) the button is an application Exit, so the player can quit the build
|
||||
// without Alt+F4.
|
||||
if (!manager.IsConnected)
|
||||
{
|
||||
QuitApplication();
|
||||
return;
|
||||
}
|
||||
|
||||
// On the map, the match AUTHORITY's button means "Back to Lobby" (end the match for everyone)
|
||||
// rather than leaving the session. Everyone else - in the lobby, or a non-authority client on the
|
||||
// map - does a plain disconnect.
|
||||
@@ -155,6 +165,15 @@ public class OnlineSessionBrowserUI : MonoBehaviour
|
||||
manager.Disconnect();
|
||||
}
|
||||
|
||||
private static void QuitApplication()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
UnityEditor.EditorApplication.isPlaying = false;
|
||||
#else
|
||||
Application.Quit();
|
||||
#endif
|
||||
}
|
||||
|
||||
private void OnManagerChanged()
|
||||
{
|
||||
if (!manager) return;
|
||||
@@ -192,8 +211,13 @@ public class OnlineSessionBrowserUI : MonoBehaviour
|
||||
private void RefreshDisconnectLabel()
|
||||
{
|
||||
if (!_disconnectLabel) return;
|
||||
bool backToLobby = _match && _match.IsLocalSceneMap && _match.IsLocalMatchAuthority;
|
||||
string text = backToLobby ? "Back to Lobby" : "Disconnect";
|
||||
string text;
|
||||
if (!(manager && manager.IsConnected))
|
||||
text = "Exit"; // Main: quit the application
|
||||
else if (_match && _match.IsLocalSceneMap && _match.IsLocalMatchAuthority)
|
||||
text = "Back to Lobby";
|
||||
else
|
||||
text = "Disconnect";
|
||||
if (text != _disconnectText)
|
||||
{
|
||||
_disconnectText = text;
|
||||
@@ -211,7 +235,8 @@ public class OnlineSessionBrowserUI : MonoBehaviour
|
||||
if (hostButton) hostButton.interactable = !busy && !connected;
|
||||
if (refreshButton) refreshButton.interactable = !busy && !connected;
|
||||
if (joinButton) joinButton.interactable = !busy && !connected && hasSelection;
|
||||
if (disconnectButton) disconnectButton.interactable = !busy && connected;
|
||||
// Usable whenever idle: connected -> Disconnect / Back to Lobby; in Main -> Exit.
|
||||
if (disconnectButton) disconnectButton.interactable = !busy;
|
||||
}
|
||||
|
||||
private void RebuildList()
|
||||
|
||||
Reference in new issue
Block a user