From 9416fb2e528e0fc7fe6c25de5f727736d843be88 Mon Sep 17 00:00:00 2001 From: Fabian Stoll Date: Fri, 25 Oct 2024 11:22:49 +0200 Subject: [PATCH] fix: create session logic --- .../Gameplay/UI/Lobby/LobbyUIMediator.cs | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/Assets/Scripts/Gameplay/UI/Lobby/LobbyUIMediator.cs b/Assets/Scripts/Gameplay/UI/Lobby/LobbyUIMediator.cs index fb5889fad..14f7c4d45 100644 --- a/Assets/Scripts/Gameplay/UI/Lobby/LobbyUIMediator.cs +++ b/Assets/Scripts/Gameplay/UI/Lobby/LobbyUIMediator.cs @@ -33,6 +33,7 @@ public class LobbyUIMediator : MonoBehaviour ISubscriber m_ConnectStatusSubscriber; const string k_DefaultSessionName = "no-name"; + const int k_MaxPlayers = 8; ISession m_Session; @@ -93,6 +94,10 @@ public async void CreateSessionRequest(string sessionName, bool isPrivate) m_ConnectionManager.StartHostSession(m_LocalUser.DisplayName); + var result = await m_MultiplayerServicesFacade.TryCreateSessionAsync(sessionName, k_MaxPlayers, isPrivate); + + HandleSessionJoinResult(result); + UnblockUIAfterLoadingIsComplete(); } @@ -140,14 +145,7 @@ public async void JoinSessionWithCodeRequest(string sessionCode) var result = await m_MultiplayerServicesFacade.TryJoinSessionAsync(sessionCode, null); - if (result.Success) - { - OnJoinedSession(result.Session); - } - else - { - UnblockUIAfterLoadingIsComplete(); - } + HandleSessionJoinResult(result); } public async void JoinSessionRequest(ISessionInfo sessionInfo) @@ -166,14 +164,7 @@ public async void JoinSessionRequest(ISessionInfo sessionInfo) var result = await m_MultiplayerServicesFacade.TryJoinSessionAsync(null, sessionInfo.Id); - if (result.Success) - { - OnJoinedSession(result.Session); - } - else - { - UnblockUIAfterLoadingIsComplete(); - } + HandleSessionJoinResult(result); } public async void QuickJoinRequest() @@ -192,6 +183,11 @@ public async void QuickJoinRequest() var result = await m_MultiplayerServicesFacade.TryQuickJoinSessionAsync(); + HandleSessionJoinResult(result); + } + + void HandleSessionJoinResult((bool Success, ISession Session) result) + { if (result.Success) { OnJoinedSession(result.Session);