Skip to main content

Match creation UI - Create joinable sessions with dedicated servers - (Unity module)

Last updated on June 12, 2024

What's on the menu

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

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

Create match session canvas

The prefab you will use to implement creating match sessions is CreateMatchMenuCanvas_Starter.prefab. The buttons and panels are already referenced in CreateMatchSessionHandler_Starter.cs. In the CreateMatchSessionHandler_Starter class Start function will look like the code below. This code is for UI setup, setting the buttons callback, and hiding the server selection panel.

private void Start()
{
createEliminationBtn.onClick.AddListener(OnCreateEliminationBtnClicked);
createTeamDeathMatchBtn.onClick.AddListener(OnTeamDeathMatchBtnClicked);
backBtn.onClick.AddListener(MenuManager.Instance.OnBackPressed);
dsBtn.onClick.AddListener(OnDSBtnClicked);
backFromServerTypeBtn.onClick.AddListener(OnBackFromServerTypeBtnClicked);
selectServerPanel.HideRight();
}

This prefab has the following states:

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 dedicated server

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 dedicated server

Ready the UI

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

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

    private void OnCreateEliminationBtnClicked()
    {
    gameMode = InGameMode.CreateMatchEliminationGameMode;
    //show server selection panel
    shownRectTransform = SlideShowLeft(createMatchPanel, selectServerPanel);
    }
  2. After successfully moving to the server selection panel, modify the CreateMatchSessionHandler_Starter.OnDSBtnClicked as shown below.

    private void OnDSBtnClicked()
    {
    dsBtn.interactable = false;
    selectedSessionServerType = TutorialModuleManager.Instance.IsModuleActive(TutorialType.MultiplayerDSEssentials)
    ? MatchSessionServerType.DedicatedServerAMS
    : MatchSessionServerType.DedicatedServer;
    CreateMatchSession();
    }
  3. In the Unity Editor, select Assets/Resources/Modules/MatchSessionDS/MatchSessionWithDSAssetConfig and tick the Is Starter Active checkbox. This will switch the script that handles the UI from the CreateMatchSessionHandler class to CreateMatchSessionHandler_Starter class.

  4. Play the game in the Editor. If your implementation was successful, you will be able to navigate to the server selection panel. When the DEDICATED SERVER button is clicked, you will see this log:

    [CreateMatchSessionHandler_Starter] Create Match Session not yet implemented

Resources