Skip to main content

Asynchronous multiplayer: Lobby - project setup

Creating queues

Log in to your Elympics account at console.elympics.ai, choose your game and create 3 new solo queues: telegram, eth, and training.

CTZ

Preparing the Unity project

In Unity, go to “Elympics>Select or create config” and turn on the “Use HTTPS/WebRTC” check.

CTZ

warning

There is a bug, that when building to WebGL this checkbox is set automatically, but it doesn’t really work. In such case you have to check it when using another build target, be sure to save, upload new server build and only then you can proceed with building on WebGL. You will see in a version control tool if the change occured properly.

In our GameManager script, in the Elympics.EndGame() method, pass in the player's final score.

private void EndGame()
{
if (Elympics.IsServer)
Elympics.EndGame(new ResultMatchPlayerDatas(new List<ResultMatchPlayerData> { new ResultMatchPlayerData { MatchmakerData = new float[1] { score.Value } } }));
displayManager.ShowGameOver(score.Value);
}

In Unity go to Window > Package Manager and add 2 new packages by clicking the plus icon in the upper left corner and choosing the Add package from git URL option.

First add the Newtonsoft Json package from com.unity.nuget.newtonsoft-json

Then add the Elympics lobby package from https://github.com/Elympics/unity-lobby.git

Creating the menu scene

Start by creating a new MenuScene.

Add ElympicsLobbyClient by right clicking on the hierarchy and choosing Elympics > ElympicsLobby.

From the folder Packages > ElympicsExternalCommunicator > Runtime > Prefabs, take the ExternalCommunicator prefab and put it in your scene.

In ElympicsLobbyClient object in the ElympicsEthSigner field, reference the ExternalCommunicator and set AuthenticateOnAwake to None.

CTZ

From Packages > ElympicsExternalCommunicator > Runtime > Scripts > Configs, copy SmartContractServiceConfig and StandaloneBrowserJsCommunicator into your asset folder for proper version control behaviour.

Put them in the ExternalCommunicator prefab as references.

CTZ

Create script PersistentLobbyManager and add it to the ExternalCommunicator object.

Create LobbyUIManager script and add it to an empty object on the scene. This is the object that will be managing all of our UI elements, based on the application state and authentication method used.

The UI elements that we will need on our scene are the following:

  • Play button - a button that will transfer player to the gameplay part using the correct queue
  • ConnectToWallet button - which will show up when the option to authenticate using a web3wallet is available
  • Leaderboard with 5 slots - for displaying top competitors
  • Authentication screen block - to block UI input while authentication is taking place
  • Matchmaking screen block - to block UI input during matchmaking
  • Error screen - to display error messages
  • Player avatar, player nickname and player wallet id - activated when player is authenticated
  • Player avatar (as above) - a button that when clicked, will show account information from the PlayPad