Skip to content

Multiplayer

Some immersive applications are built to allow multiple Participants to interact in a shared world. When multiple sessions have the same LobbyId, it allows our system to logically group these sessions together with minimal client side effort.

Networking Structure

The CognitiveVR SDK is not designed to record multiple sessions from a centralized server. It is designed to run on a client.

Lobby Id

A LobbyId connects multiple participant sessions together to display a multiplayer experience. Please get in contact to discuss your implementation details.

Example

An example implementation is as follows:

Server Requests unique LobbyId from Cognitive3D API:

class LobbyResponse
{
    public string id;
}

//SERVER
IEnumerator GetLobbyId(string APIKey)
{
    LobbyResponse lobbyResponse;
    // Post to Lobbies API
    using (UnityWebRequest www = UnityWebRequest.Post("https://data.cognitive3d.com/v0/lobbies",""))
    {
        // Add Project APIKey to header
        www.SetRequestHeader("Authorization", "APIKEY:DATA " + APIKey);
        yield return www.SendWebRequest();

        // Get response
        lobbyResponse = JsonUtility.FromJson<LobbyResponse>(www.downloadHandler.text);
    }

    //send to all players
    Network.RPC("SetLobbyId",RPCTarget.All,lobbyResponse.id);
}

//CLIENT
//called on each client to set matching lobby id
[RPC]
void SetLobbyId(string lobbyId)
{
    CognitiveVR_Manager.SetLobbyId(lobbyid);
}