GetServerProperties

Method

Get the current server properties. Server properties persist with the server instance until the server is closed, which happens when the last actor disconnects from the server. This only works if actively connected to the server. Check for isConnected before calling this.

Remarks

Supported types: string, int, bool

Definition

IReadOnlyDictionary<string, object> GetServerProperties()
IReadOnlyDictionary<string, object> GetServerProperties()

Returns IReadOnlyDictionary<string, object>

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
}