Skip to content

Commit da2468b

Browse files
adding back addition of user to local session
1 parent 279e348 commit da2468b

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

Assets/Scripts/Gameplay/GameState/ClientMainMenuState.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ protected override void Configure(IContainerBuilder builder)
7171
builder.RegisterComponent(m_IPUIMediator);
7272
}
7373

74-
private async void TrySignIn()
74+
async void TrySignIn()
7575
{
7676
try
7777
{
@@ -88,16 +88,21 @@ private async void TrySignIn()
8888
}
8989
}
9090

91-
private void OnAuthSignIn()
91+
void OnAuthSignIn()
9292
{
9393
m_SessionButton.interactable = true;
9494
m_UGSSetupTooltipDetector.enabled = false;
9595
m_SignInSpinner.SetActive(false);
9696

9797
Debug.Log($"Signed in. Unity Player ID {AuthenticationService.Instance.PlayerId}");
98+
99+
m_LocalUser.ID = AuthenticationService.Instance.PlayerId;
100+
101+
// The local LobbyUser object will be hooked into UI before the LocalSession is populated during session join, so the LocalSession must know about it already when that happens.
102+
m_LocalSession.AddUser(m_LocalUser);
98103
}
99104

100-
private void OnSignInFailed()
105+
void OnSignInFailed()
101106
{
102107
if (m_SessionButton)
103108
{
@@ -113,7 +118,11 @@ private void OnSignInFailed()
113118

114119
protected override void OnDestroy()
115120
{
116-
m_ProfileManager.onProfileChanged -= OnProfileChanged;
121+
if (m_ProfileManager != null)
122+
{
123+
m_ProfileManager.onProfileChanged -= OnProfileChanged;
124+
}
125+
117126
base.OnDestroy();
118127
}
119128

Assets/Scripts/UnityServices/Sessions/LocalSession.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,10 @@ public void ApplyRemoteData(ISession session)
213213
CopyDataFrom(info, localSessionUsers);
214214
}
215215

216-
public void Reset()
216+
public void Reset(LocalSessionUser localUser)
217217
{
218218
CopyDataFrom(new SessionData(), new Dictionary<string, LocalSessionUser>());
219+
AddUser(localUser);
219220
}
220221
}
221222
}

Assets/Scripts/UnityServices/Sessions/MultiplayerServicesFacade.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Threading.Tasks;
33
using Unity.BossRoom.Infrastructure;
4-
using Unity.Services.Authentication;
54
using Unity.Services.Multiplayer;
65
using UnityEngine;
76
using VContainer;
@@ -168,27 +167,27 @@ public void EndTracking()
168167
}
169168

170169
/// <summary>
171-
/// Attempt to join an existing session by name.
170+
/// Attempt to join an existing session by ID.
172171
/// </summary>
173-
public async Task<(bool Success, ISession Session)> TryJoinSessionByNameAsync(string sessionName)
172+
public async Task<(bool Success, ISession Session)> TryJoinSessionByIdAsync(string sessionId)
174173
{
175174
if (!m_RateLimitJoin.CanCall)
176175
{
177176
Debug.LogWarning("Join Session hit the rate limit.");
178177
return (false, null);
179178
}
180179

181-
if (string.IsNullOrEmpty(sessionName))
180+
if (string.IsNullOrEmpty(sessionId))
182181
{
183-
Debug.LogWarning("Cannot join a Session without a session name.");
182+
Debug.LogWarning("Cannot join a Session without a session ID.");
184183
return (false, null);
185184
}
186185

187-
Debug.Log($"Joining session with name {sessionName}");
186+
Debug.Log($"Joining session with ID {sessionId}");
188187

189188
try
190189
{
191-
var session = await m_MultiplayerServicesInterface.JoinSessionById(sessionName, m_LocalUser.GetDataForUnityServices());
190+
var session = await m_MultiplayerServicesInterface.JoinSessionById(sessionId, m_LocalUser.GetDataForUnityServices());
192191
return (true, session);
193192
}
194193
catch (Exception e)
@@ -227,7 +226,7 @@ void ResetSession()
227226
{
228227
CurrentUnitySession = null;
229228
m_LocalUser?.ResetState();
230-
m_LocalSession?.Reset();
229+
m_LocalSession?.Reset(m_LocalUser);
231230

232231
// no need to disconnect Netcode, it should already be handled by Netcode's callback to disconnect
233232
}

0 commit comments

Comments
 (0)