Prepare user interface - Quick match with peer-to-peer - (Unity module)
Browsing P2P sessions is not supported in WebGL builds due to the AccelByte Gaming Services (AGS) SDK for Unity lacking the P2P functionality for WebGL.
What's on the menu
You will implement matchmaking using a peer-to-peer (P2P) network in this module.
For matchmaking using a P2P architecture, a Unity user interface (UI) has been prepared for you. It is available in the Resources section and consists of the following files:
- MatchmakingSessionP2PHandler_Starter.cs: A C# script that contains most of the P2P matchmaking implementation. This class connects the UI and the AccelByte Gaming Services (AGS) Game SDK service wrapper class to call its API.
- CS file:
Assets/Resources/Modules/MatchmakingSessionP2P/Scripts/UI/MatchmakingSessionP2PHandler_Starter.cs
- CS file:
- MatchmakingSessionP2P_Starter.prefab: The prefab file that you will use to implement P2P matchmaking. The P2P button is auto-generated and will call
ClickPeerToPeerButton
inMatchmakingSessionP2PHandler_Starter.cs
.- Prefab file:
Assets/Resources/Modules/MatchmakingSessionP2P/Scripts/UI/MatchmakingSessionP2PHandler_Starter.cs
- Prefab file:
Take a look at the UI states in more detail below.
Select game mode state
This UI state will be displayed when the player accesses the Play Online > Quick Play menu from the main menu. It displays buttons to select the game mode before matchmaking. There are two game modes: Elimination and Team Deathmatch.
- MatchmakingSessionHandler.cs: This script is designed to handle UI functions related to selecting a match type for creating a match session. It features a Button UI element and logic to process the selected server type.
- CS file:
Assets/Resources/Modules/MatchmakingSession/MatchmakingSessionHandler.cs
- CS file:
- MatchmakingSessionMenuCanvas.prefab: A GameObject prefab that is created based on the Canvas Panel UI GameObject.
- Prefab file:
Assets/Resources/Modules/MatchmakingSession/MatchmakingSessionMenuCanvas.prefab
- Prefab file:
Select server type state
This state will be displayed after the player selects their preferred game mode. It displays buttons to select a server type for the matchmaking. By default, this state contains an empty container. On runtime, however, the MatchmakingSessionP2P_Starter.prefab
will be automatically generated to show the P2P type button option.
- MatchmakingSessionServerTypeSelection.cs: This script is designed to handle UI functionality related to selecting a server type for creating a match session. It features a Button UI element and logic to process the selected server type.
- CS file:
Assets/Resources/Modules/MatchmakingSession/MatchmakingSessionServerTypeSelection.cs
- CS file:
- MatchmakingSessionServerTypeSelection.prefab: A GameObject prefab that is created based on the Canvas Panel UI GameObject.
- Prefab file:
Assets/Resources/Modules/MatchmakingSession/MatchmakingSessionServerTypeSelection.prefab
- Prefab file:
Ready the UI
You will learn how to implement UI functionality before calling the AGS Game SDK API for P2P matchmaking.
Open
MatchmakingSessionP2PHandler_Starter.cs
. You will implement matchmaking with the Elimination game mode using P2P. Modify theClickPeerToPeerButton
method as shown below.public void ClickPeerToPeerButton()
{
BytewarsLogger.Log("Peer-to-peer matchmaking is not yet implemented.");
}In the Unity Editor, open
Assets/Resources/Modules/MatchmakingSessionP2P/MatchmakingWithP2PAssetConfig.asset
and enable Is Starter Active in the Inspector. This will tell the game to use the files mentioned earlier for the P2P matchmaking.Play the game in the Editor. If your implementation was successful, you will be able to navigate to the server selection panel and see the following log when you click PEER TO PEER:
[MatchmakingSessionP2PHandler_Starter.cs] [ClickPeerToPeerButton] [Log] [linenumber] - Peer to peer matchmaking is not implemented yet
Resources
- The files used in this tutorial section are available in the ByteWars GitHub repository.