Skip to content

Commit a135e20

Browse files
committed
moving service ui logic to its own class
1 parent edbf384 commit a135e20

File tree

4 files changed

+62
-26
lines changed

4 files changed

+62
-26
lines changed

Assets/BossRoom/Scenes/Startup.unity

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:7b2c33d4681d53ec62b32b7ff2c81123b4457d8dcd8d0b6d643097e74ae36856
3-
size 35006
2+
oid sha256:22939a0b19a2e47d1c43cf76d229f2a99bcc8511f03020367645a163b6ab2fba
3+
size 35402

Assets/BossRoom/Scripts/Client/UI/Lobby/LobbyUIMediator.cs

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,15 @@ public class LobbyUIMediator : MonoBehaviour
2626
NameGenerationData m_NameGenerationData;
2727
GameNetPortal m_GameNetPortal;
2828
ClientGameNetPortal m_ClientNetPortal;
29-
private IDisposable m_Subscriptions;
3029

3130
[Inject]
3231
void InjectDependenciesAndInitialize(
3332
LobbyServiceFacade lobbyServiceFacade,
34-
IPublisher<UnityServiceErrorMessage> unityServiceErrorMessagePublisher,
3533
LocalLobbyUser localUser,
3634
LocalLobby localLobby,
3735
NameGenerationData nameGenerationData,
3836
GameNetPortal gameNetPortal,
39-
ClientGameNetPortal clientGameNetPortal,
40-
ISubscriber<UnityServiceErrorMessage> serviceError
37+
ClientGameNetPortal clientGameNetPortal
4138
)
4239
{
4340
m_NameGenerationData = nameGenerationData;
@@ -50,24 +47,6 @@ ISubscriber<UnityServiceErrorMessage> serviceError
5047
RegenerateName();
5148

5249
m_ClientNetPortal.NetworkTimedOut += OnNetworkTimeout;
53-
m_Subscriptions = serviceError.Subscribe(ServiceErrorHandler);
54-
}
55-
56-
private void ServiceErrorHandler(UnityServiceErrorMessage error)
57-
{
58-
var errorMessage = error.Message;
59-
if (error.AffectedService == UnityServiceErrorMessage.Service.Lobby)
60-
{
61-
if ((error.OriginalException as LobbyServiceException).Reason == LobbyExceptionReason.LobbyConflict)
62-
{
63-
// LobbyConflict can have multiple causes. Let's add other solutions here if there's other situations that arise for this.
64-
errorMessage += "\nSee logs for possible causes and solution.";
65-
Debug.LogError($"Got service error {error.Message} with LobbyConflict. Possible conflict cause: Trying to play with two builds on the " +
66-
$"same machine. Please use command line arg '{ClientMainMenuState.AuthProfileCommandLineArg} someName' to set a different auth profile.\n");
67-
}
68-
}
69-
70-
PopupPanel.ShowPopupPanel("Service error", errorMessage);
7150
}
7251

7352
void OnDestroy()
@@ -76,8 +55,6 @@ void OnDestroy()
7655
{
7756
m_ClientNetPortal.NetworkTimedOut -= OnNetworkTimeout;
7857
}
79-
80-
m_Subscriptions.Dispose();
8158
}
8259

8360
//Lobby and Relay calls done from UI
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using Unity.Multiplayer.Samples.BossRoom;
5+
using Unity.Multiplayer.Samples.BossRoom.Client;
6+
using Unity.Multiplayer.Samples.BossRoom.Shared.Infrastructure;
7+
using Unity.Multiplayer.Samples.BossRoom.Shared.Net.UnityServices.Infrastructure;
8+
using Unity.Multiplayer.Samples.BossRoom.Visual;
9+
using Unity.Services.Lobbies;
10+
using UnityEngine;
11+
12+
public class UIServices : MonoBehaviour
13+
{
14+
private IDisposable m_Subscriptions;
15+
16+
void Awake()
17+
{
18+
DontDestroyOnLoad(gameObject);
19+
}
20+
21+
[Inject]
22+
void Initialize(ISubscriber<UnityServiceErrorMessage> serviceError)
23+
{
24+
m_Subscriptions = serviceError.Subscribe(ServiceErrorHandler);
25+
}
26+
27+
private void ServiceErrorHandler(UnityServiceErrorMessage error)
28+
{
29+
var errorMessage = error.Message;
30+
if (error.AffectedService == UnityServiceErrorMessage.Service.Lobby)
31+
{
32+
if ((error.OriginalException as LobbyServiceException).Reason == LobbyExceptionReason.LobbyConflict)
33+
{
34+
// LobbyConflict can have multiple causes. Let's add other solutions here if there's other situations that arise for this.
35+
errorMessage += "\nSee logs for possible causes and solution.";
36+
Debug.LogError($"Got service error {error.Message} with LobbyConflict. Possible conflict cause: Trying to play with two builds on the " +
37+
$"same machine. Please use command line arg '{ClientMainMenuState.AuthProfileCommandLineArg} someName' to set a different auth profile.\n");
38+
}
39+
}
40+
41+
PopupPanel.ShowPopupPanel("Service error", errorMessage);
42+
}
43+
44+
private void OnDestroy()
45+
{
46+
m_Subscriptions.Dispose();
47+
}
48+
}

Assets/BossRoom/Scripts/Client/UI/UIServices.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)