Match creation UI - Create joinable sessions with peer-to-peer - (Unity module)
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
- CS file:
MatchSessionHandler.prefab: A GameObject prefab that is created based on the Canvas Panel UI GameObject.
- Prefab file:
Assets/Resources/Modules/MatchSession/Prefabs/MatchSessionHandler.prefab
- Prefab file:
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
- CS file:
MatchSessionServerTypeSelection.prefab: A GameObject prefab that is created based on the Canvas Panel UI GameObject.
- Prefab file:
Assets/Resources/Modules/MatchSession/Prefabs/MatchSessionServerTypeSelection.prefab
- Prefab file:
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
- CS file:
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
- Prefab file:
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.
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.
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:
Open the
CreateMatchSessionP2PHandler_Starter.cs
. You will implement creating a match session with the Elimination game mode using the dedicated server. Modify theCreateMatchSessionP2PHandler_Starter.cs.ClickPeerToPeerButton
method as shown below.public void ClickPeerToPeerButton()
{
BytewarsLogger.Log("Create Match with P2P is not implemented");
}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.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
The files used in this tutorial section are available in the ByteWars GitHub repository.