メインコンテンツまでスキップ

Match creation UI - Create joinable sessions with peer-to-peer - (Unity module)

Last updated on October 23, 2024

What's on the menu

備考

In this module, you will use the same UI that was implemented in the prerequisite module. If you have not yet completed it, please complete both modules and then continue to this module.

A Unity user interface (UI) prefab for creating a match session has been prepared for you. In this tutorial, you will implement the ability to create match sessions by coding it into the provided prefab. The prefab is available in the Resources section and consists of the following files:

  • MatchSessionHandler.cs: This script is designed to handle UI functionality 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/MatchSession/Scripts/MatchSessionHandler.cs
  • MatchSessionHandler.prefab: A GameObject prefab that is created based on the Canvas Panel UI GameObject.

    • Prefab file: Assets/Resources/Modules/MatchSession/Prefabs/MatchSessionHandler.prefab
  • MatchSessionServerTypeSelection.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/MatchSession/Scripts/MatchSessionServerTypeSelection.cs
  • MatchSessionServerTypeSelection.prefab: A GameObject prefab that is created based on the Canvas Panel UI GameObject.

    • Prefab file: Assets/Resources/Modules/MatchSession/Prefabs/MatchSessionServerTypeSelection.prefab
  • MatchmakingSessionP2PHandler_Starter.cs: A C# script that contains most of the match session implementation. This class connects UI and the AccelByte Gaming Services (AGS) Game SDK service wrapper class to call its API.

    • CS file: Assets/Resources/Modules/MatchSessionP2P/Scripts/UI/CreateMatchSessionP2PHandler_Starter.cs
  • CreateMatchSessionP2PHandler_Starter.prefab: A GameObject prefab that acts as a container for CreateMatchSessionDSHandler_Starter.cs.

    • Prefab file: Assets/Resources/Modules/MatchSessionP2P/Prefabs/CreateMatchSessionP2PHandler_Starter.prefab

Create match session canvas

You use the MatchSessionHandler.prefab as a menu for game mode options and the MatchSessionServerTypeSelection.prefab for network type options. Both menus will display UI elements with these options, holding values for the game mode and network type, which are later passed to CreateMatchSessionP2PHandler_Starter.cs as the UI handler.

Select game mode state

This state is where the player can select one of the offered game modes: Elimination or Team Deathmatch.

Preview of the select game mode state Unity Byte Wars joinable sessions peer to peer

Select network type state

This state is where the player can select which network type the session will use. In this tutorial, you will implement the dedicated server network type.

Preview of the select network type state Unity Byte Wars joinable sessions peer to peer

Ready the UI

You need to implement the UI functionality before calling the AGS Game SDK API to create match sessions. Follow these steps to do this:

  1. Open the CreateMatchSessionP2PHandler_Starter.cs. You will implement creating a match session with the Elimination game mode using the dedicated server. Modify the CreateMatchSessionP2PHandler_Starter.cs.ClickPeerToPeerButton method as shown below.

    public void ClickPeerToPeerButton()
    {
    BytewarsLogger.Log("Create Match with P2P is not implemented");
    }
  2. In Unity, go to Assets/Resources/Modules/MatchSessionP2P/MatchSessionWithP2PAssetConfig.asset. There, you will find an asset config called MatchSessionWithP2PAssetConfig.asset. Open it and enable Is Starter Active. This will activate the starter UI, allowing you to navigate through it when you play the game.

    Is Starter Active option selected in the Unity Inspector in the MatchSessionWithP2PAssetConfig file Unity Byte Wars joinable sessions peer-to-peer

  3. Play the game in the editor. If your implementation was successful, you will be able to navigate to the server selection panel from Create Match > Create Elimination and see the following log when you click P2P:

    [CreateMatchSessionP2PHandler_Starter.cs] [ClickPeerToPeerButton] [Log] [linenumber] - Create Match with P2P is not implemented

Resources