@@ -17,8 +17,6 @@ public class ClientGameNetPortal : MonoBehaviour
17
17
public static ClientGameNetPortal Instance ;
18
18
private GameNetPortal m_Portal ;
19
19
20
- string m_JoinCode ;
21
-
22
20
/// <summary>
23
21
/// If a disconnect occurred this will be populated with any contextual information that was available to explain why.
24
22
/// </summary>
@@ -178,42 +176,38 @@ public void StartClient(string ipaddress, int port)
178
176
throw new ArgumentOutOfRangeException ( nameof ( chosenTransport ) ) ;
179
177
}
180
178
181
- ConnectClient ( null ) ;
179
+ ConnectClient ( ) ;
182
180
}
183
181
184
- public void StartClientUnityRelayModeAsync ( string joinCode , Action < string > onFailure )
182
+ public async void StartClientUnityRelayModeAsync ( string joinCode , Action < string > onFailure )
185
183
{
186
184
m_Portal . OnlineMode = OnlineMode . UnityRelay ;
187
- m_JoinCode = joinCode ;
188
- var utp = NetworkManager . Singleton . gameObject . GetComponent < TransportPicker > ( ) . UnityRelayTransport ;
185
+ var utp = ( UnityTransport ) NetworkManager . Singleton . gameObject . GetComponent < TransportPicker > ( ) . UnityRelayTransport ;
189
186
NetworkManager . Singleton . NetworkConfig . NetworkTransport = utp ;
190
187
191
188
Debug . Log ( $ "Setting Unity Relay client with join code { joinCode } ") ;
192
189
193
- ConnectClient ( onFailure ) ;
194
- }
190
+ try
191
+ {
192
+ var clientRelayUtilityTask = UnityRelayUtilities . JoinRelayServerFromJoinCode ( joinCode ) ;
193
+ await clientRelayUtilityTask ;
194
+ var ( ipv4Address , port , allocationIdBytes , connectionData , hostConnectionData , key ) = clientRelayUtilityTask . Result ;
195
195
196
- async void ConnectClient ( Action < string > onFailure )
197
- {
198
- if ( m_Portal . OnlineMode == OnlineMode . UnityRelay )
196
+ m_LobbyServiceFacade . UpdatePlayerRelayInfoAsync ( allocationIdBytes . ToString ( ) , joinCode , null , null ) ;
197
+ utp . SetClientRelayData ( ipv4Address , port , allocationIdBytes , key , connectionData , hostConnectionData , isSecure : true ) ;
198
+ }
199
+ catch ( Exception e )
199
200
{
200
- try
201
- {
202
- var clientRelayUtilityTask = UnityRelayUtilities . JoinRelayServerFromJoinCode ( m_JoinCode ) ;
203
- await clientRelayUtilityTask ;
204
- var ( ipv4Address , port , allocationIdBytes , connectionData , hostConnectionData , key ) = clientRelayUtilityTask . Result ;
201
+ onFailure ? . Invoke ( e . Message ) ;
202
+ return ; //not re-throwing, but still not allowing to connect
203
+ }
205
204
206
- m_LobbyServiceFacade . UpdatePlayerRelayInfoAsync ( allocationIdBytes . ToString ( ) , m_JoinCode , null , null ) ;
207
- var utp = ( UnityTransport ) NetworkManager . Singleton . NetworkConfig . NetworkTransport ;
208
- utp . SetClientRelayData ( ipv4Address , port , allocationIdBytes , key , connectionData , hostConnectionData , isSecure : true ) ;
209
- }
210
- catch ( Exception e )
211
- {
212
- onFailure ? . Invoke ( e . Message ) ;
213
- return ; //not re-throwing, but still not allowing to connect
214
- }
215
205
216
- }
206
+ ConnectClient ( ) ;
207
+ }
208
+
209
+ void ConnectClient ( )
210
+ {
217
211
218
212
var payload = JsonUtility . ToJson ( new ConnectionPayload ( )
219
213
{
0 commit comments