Skip to main content

Prepare user interface - Quick match with peer-to-peer - (Unity module)

Last updated on November 25, 2024
info

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 AGS Game SDK service wrapper class to call its API.
    • CS file: Assets/Resources/Modules/MatchmakingSessionP2P/Scripts/UI/MatchmakingSessionP2PHandler_Starter.cs
  • MatchmakingSessionP2P_Starter.prefab: The prefab file that you will use to implement P2P matchmaking. The P2P button is auto-generated and will call ClickPeerToPeerButton in MatchmakingSessionP2PHandler_Starter.cs.
    • Prefab file: Assets/Resources/Modules/MatchmakingSessionP2P/Scripts/UI/MatchmakingSessionP2PHandler_Starter.cs

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
  • MatchmakingSessionMenuCanvas.prefab: A GameObject prefab that is created based on the Canvas Panel UI GameObject.
    • Prefab file: Assets/Resources/Modules/MatchmakingSession/MatchmakingSessionMenuCanvas.prefab

Unity Byte Wars: P2P Quick Match - Game Mode Preview

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
  • MatchmakingSessionServerTypeSelection.prefab: A GameObject prefab that is created based on the Canvas Panel UI GameObject.
    • Prefab file: Assets/Resources/Modules/MatchmakingSession/MatchmakingSessionServerTypeSelection.prefab

Unity Byte Wars: P2P Quick Match - Server Type State Preview

Ready the UI

You will learn how to implement UI functionality before calling the AGS Game SDK API for P2P matchmaking.

  1. Open MatchmakingSessionP2PHandler_Starter.cs. You will implement matchmaking with the Elimination game mode using P2P. Modify the ClickPeerToPeerButton method as shown below.

    public void ClickPeerToPeerButton()
    {
    BytewarsLogger.Log("Peer-to-peer matchmaking is not yet implemented.");
    }
  2. 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.

  3. 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