onConnectionStatusChanged

Event

Event that triggers when the server connection status changes

Returns INetworkingService.OnServerConnectionStatusChangedDelegate

Examples

public Image loadingImage;
public GameObject lobbyArea;
public GameObject gameArea;
public Button joinGameButton;

void OnEnable()
{
SpatialBridge.networkingService.onConnectionStatusChanged += HandleConnectionStatusChanged;

joinGameButton.onClick.AddListener(JoinGame);
}

void OnDisable()
{
SpatialBridge.networkingService.onConnectionStatusChanged -= HandleConnectionStatusChanged;
}

void JoinGame()
{
SpatialBridge.networkingService.TeleportToBestMatchServer(
maxParticipants: 20,
serverProperties: new Dictionary<string, object> { { "isGame", true } }
);
}

private void HandleConnectionStatusChanged(ServerConnectionStatus status)
{
if (status == ServerConnectionStatus.Connected)
{
// Already connected, hide loading image
loadingImage.gameObject.SetActive(false);

// Check if we're on lobby or game server
if (SpatialBridge.networkingService.GetServerProperties().ContainsKey("isGame"))
{
HandleJoinedGameServer();
}
else
{
HandleJoinedLobbyServer();
}

}
else if (status == ServerConnectionStatus.Connecting)
{
loadingImage.gameObject.SetActive(true);
}
}

private void HandleJoinedLobbyServer()
{
lobbyArea.SetActive(true);
gameArea.SetActive(false);
}

private void HandleJoinedGameServer()
{
lobbyArea.SetActive(false);
gameArea.SetActive(true);

// Add additional game area setup here
}
public Image loadingImage;
public GameObject lobbyArea;
public GameObject gameArea;
public Button joinGameButton;

void OnEnable()
{
SpatialBridge.networkingService.onConnectionStatusChanged += HandleConnectionStatusChanged;

joinGameButton.onClick.AddListener(JoinGame);
}

void OnDisable()
{
SpatialBridge.networkingService.onConnectionStatusChanged -= HandleConnectionStatusChanged;
}

void JoinGame()
{
SpatialBridge.networkingService.TeleportToBestMatchServer(
maxParticipants: 20,
serverProperties: new Dictionary<string, object> { { "isGame", true } }
);
}

private void HandleConnectionStatusChanged(ServerConnectionStatus status)
{
if (status == ServerConnectionStatus.Connected)
{
// Already connected, hide loading image
loadingImage.gameObject.SetActive(false);

// Check if we're on lobby or game server
if (SpatialBridge.networkingService.GetServerProperties().ContainsKey("isGame"))
{
HandleJoinedGameServer();
}
else
{
HandleJoinedLobbyServer();
}

}
else if (status == ServerConnectionStatus.Connecting)
{
loadingImage.gameObject.SetActive(true);
}
}

private void HandleJoinedLobbyServer()
{
lobbyArea.SetActive(true);
gameArea.SetActive(false);
}

private void HandleJoinedGameServer()
{
lobbyArea.SetActive(false);
gameArea.SetActive(true);

// Add additional game area setup here
}