2
2
using System . Collections . Generic ;
3
3
using System . Threading . Tasks ;
4
4
using Unity . Collections ;
5
- using Unity . Multiplayer . Samples . BossRoom . ApplicationLifecycle . Messages ;
6
5
using Unity . Multiplayer . Samples . BossRoom . Client ;
7
- using Unity . Multiplayer . Samples . BossRoom . Shared ;
8
6
using Unity . Multiplayer . Samples . BossRoom . Shared . Infrastructure ;
9
- using Unity . Multiplayer . Samples . BossRoom . Shared . Net . UnityServices . Lobbies ;
10
7
using Unity . Netcode ;
11
8
using UnityEngine ;
12
9
@@ -39,31 +36,9 @@ public class ConnectionManager : MonoBehaviour
39
36
NetworkObject m_GameState ;
40
37
public NetworkObject GameState => m_GameState ;
41
38
42
- ProfileManager m_ProfileManager ;
43
- LobbyServiceFacade m_LobbyServiceFacade ;
44
- LocalLobby m_LocalLobby ;
45
- IPublisher < ConnectionEventMessage > m_ConnectionEventPublisher ;
46
- IPublisher < QuitGameSessionMessage > m_QuitGameSessionPublisher ;
47
- IPublisher < ConnectStatus > m_ConnectStatusPublisher ;
48
- IPublisher < ReconnectMessage > m_ReconnectMessagePublisher ;
49
-
50
39
DisconnectReason m_DisconnectReason = new DisconnectReason ( ) ;
51
40
public DisconnectReason DisconnectReason => m_DisconnectReason ;
52
41
53
- [ Inject ]
54
- void InjectDependencies ( ProfileManager profileManager , LobbyServiceFacade lobbyServiceFacade , LocalLobby localLobby ,
55
- IPublisher < ConnectionEventMessage > connectionEventPublisher , IPublisher < QuitGameSessionMessage > quitGameSessionPublisher ,
56
- IPublisher < ConnectStatus > connectStatusPublisher , IPublisher < ReconnectMessage > reconnectMessagePublisher )
57
- {
58
- m_ProfileManager = profileManager ;
59
- m_LobbyServiceFacade = lobbyServiceFacade ;
60
- m_LocalLobby = localLobby ;
61
- m_ConnectionEventPublisher = connectionEventPublisher ;
62
- m_QuitGameSessionPublisher = quitGameSessionPublisher ;
63
- m_ConnectStatusPublisher = connectStatusPublisher ;
64
- m_ReconnectMessagePublisher = reconnectMessagePublisher ;
65
- }
66
-
67
42
void Awake ( )
68
43
{
69
44
DontDestroyOnLoad ( gameObject ) ;
@@ -73,14 +48,20 @@ void Start()
73
48
{
74
49
m_Logics = new Dictionary < ConnectionStateType , ConnectionState > ( )
75
50
{
76
- [ ConnectionStateType . Offline ] = new OfflineConnectionState ( this , m_LobbyServiceFacade , m_LocalLobby , m_ProfileManager ) ,
77
- [ ConnectionStateType . Connecting ] = new ConnectingConnectionState ( this , m_QuitGameSessionPublisher , m_ConnectStatusPublisher ) ,
78
- [ ConnectionStateType . Connected ] = new ConnectedConnectionState ( this , m_QuitGameSessionPublisher , m_ConnectStatusPublisher ) ,
79
- [ ConnectionStateType . Reconnecting ] = new ReconnectingConnectionState ( this , m_LobbyServiceFacade , m_LocalLobby , m_ReconnectMessagePublisher , m_ProfileManager ) ,
80
- [ ConnectionStateType . Hosting ] = new HostingConnectionState ( this , m_LobbyServiceFacade , m_ConnectionEventPublisher )
51
+ [ ConnectionStateType . Offline ] = new OfflineConnectionState ( this ) ,
52
+ [ ConnectionStateType . Connecting ] = new ConnectingConnectionState ( this ) ,
53
+ [ ConnectionStateType . Connected ] = new ConnectedConnectionState ( this ) ,
54
+ [ ConnectionStateType . Reconnecting ] = new ReconnectingConnectionState ( this ) ,
55
+ [ ConnectionStateType . Hosting ] = new HostingConnectionState ( this )
81
56
} ;
82
57
m_CurrentState = ConnectionStateType . Offline ;
83
58
59
+ var scope = DIScope . RootScope ;
60
+ foreach ( var connectionState in m_Logics . Values )
61
+ {
62
+ scope . InjectIn ( connectionState ) ;
63
+ }
64
+
84
65
NetworkManager . OnClientConnectedCallback += OnClientConnectedCallback ;
85
66
NetworkManager . OnClientDisconnectCallback += OnClientDisconnectCallback ;
86
67
NetworkManager . ConnectionApprovalCallback += ApprovalCheck ;
@@ -95,7 +76,7 @@ void OnDestroy()
95
76
96
77
public void ChangeState ( ConnectionStateType newState )
97
78
{
98
- Debug . Log ( newState ) ;
79
+ Debug . Log ( $ "Changed connection sate from { m_CurrentState } to { newState } ." ) ;
99
80
m_Logics [ m_CurrentState ] . Exit ( ) ;
100
81
m_CurrentState = newState ;
101
82
m_Logics [ m_CurrentState ] . Enter ( ) ;
0 commit comments