すべてを統合する - 専用サーバーでのクイックマッチ - (Unity モジュール)
Connect the UI to start, cancel, and display the matchmaking status
In this tutorial, you will call the dedicated server (DS) matchmaking function in the MatchmakingSessionDSWrapper_Starter
class from the MatchmakingSessionDSHandler_Starter
class.
Open
MatchmakingSessionDSHandler_Starter
. AddMatchmakingSessionDSWrapper_Starter
as a field that you will use to call the API.private MatchmakingSessionDSWrapper_Starter matchmakingSessionDSWrapper_Starter;
Modify
ClickDedicatedServerButton
as shown below. This code will prepare the AccelByte Gaming Services (AGS) Game SDK service wrapper and start matchmaking based on the match pool name.public void ClickDedicatedServerButton()
{
MenuCanvas menu = MenuManager.Instance.GetCurrentMenu();
if (menu is MatchmakingSessionServerTypeSelection serverTypeSelection)
{
InitWrapper();
selectedGameMode = serverTypeSelection.SelectedGameMode;
}
else
{
BytewarsLogger.LogWarning("Current menu is not server type selection menu while try to matchmaking with DS");
return;
}
switch (selectedGameMode)
{
case InGameMode.OnlineDeathMatchGameMode:
matchmakingSessionDSWrapper_Starter.StartDSMatchmaking(InGameMode.OnlineDeathMatchGameMode);
ShowLoading("Start Team Death Match (Dedicated Server)...",
"Start Team Death Match (Dedicated Server) is timed out",
matchmakingTimeoutSec);
break;
case InGameMode.OnlineEliminationGameMode:
matchmakingSessionDSWrapper_Starter.StartDSMatchmaking(InGameMode.OnlineEliminationGameMode);
ShowLoading("Start Elimination Match (Dedicated Server)...",
"Start Elimination Match (Dedicated Server) is timed out",
matchmakingTimeoutSec);
break;
default:
string errorMsg = $"No Dedicated Server Match Pool for {selectedGameMode}";
BytewarsLogger.LogWarning(errorMsg);
ShowError(errorMsg);
break;
}
}Go to
InitWrapper
and update the function using the code below:private void InitWrapper()
{
if (matchmakingSessionDSWrapper_Starter == null)
{
matchmakingSessionDSWrapper_Starter = TutorialModuleManager.Instance.GetModuleClass<MatchmakingSessionDSWrapper_Starter>();
}
BindMatchmakingEvent();
MatchmakingSessionServerTypeSelection.OnBackButtonCalled -= OnBackButtonFromServerSelection;
MatchmakingSessionServerTypeSelection.OnBackButtonCalled += OnBackButtonFromServerSelection;
}Now, set up your event binding in the
BindMatchmakingEvent
function, along with the unbinding inUnbindMatchmakingEvents
.private void BindMatchmakingEvent()
{
if (matchmakingSessionDSWrapper_Starter == null)
{
return;
}
matchmakingSessionDSWrapper_Starter.BindMatchmakingEvent();
matchmakingSessionDSWrapper_Starter.OnMatchTicketDSCreated += OnMatchTicketDSCreated;
matchmakingSessionDSWrapper_Starter.OnMatchmakingWithDSMatchFound += OnMatchmakingWithDSMatchFound;
matchmakingSessionDSWrapper_Starter.OnMatchmakingWithDSTicketExpired += OnMatchmakingWithDSTicketExpired;
matchmakingSessionDSWrapper_Starter.OnMatchmakingWithDSJoinSessionStarted += OnMatchmakingWithDSJoinSessionStarted;
matchmakingSessionDSWrapper_Starter.OnMatchmakingWithDSJoinSessionCompleted += OnMatchmakingWithDSJoinSessionCompleted;
matchmakingSessionDSWrapper_Starter.OnMatchmakingWithDSCanceled += OnMatchmakingWithDSCanceled;
matchmakingSessionDSWrapper_Starter.OnMatchmakingWithDSError += ErrorPanel;
matchmakingSessionDSWrapper_Starter.OnMatchmakingError += ErrorPanel;
matchmakingSessionDSWrapper_Starter.OnDSError += ErrorPanel;
matchmakingSessionDSWrapper_Starter.OnIntentionallyLeaveSession += Reset;
matchmakingSessionDSWrapper_Starter.OnDSAvailable += Traveling;
}private void UnbindMatchmakingEvents()
{
if (matchmakingSessionDSWrapper_Starter == null)
{
return;
}
matchmakingSessionDSWrapper_Starter.UnbindMatchmakingEvent();
matchmakingSessionDSWrapper_Starter.OnMatchTicketDSCreated -= OnMatchTicketDSCreated;
matchmakingSessionDSWrapper_Starter.OnMatchmakingWithDSMatchFound -= OnMatchmakingWithDSMatchFound;
matchmakingSessionDSWrapper_Starter.OnMatchmakingWithDSTicketExpired -= OnMatchmakingWithDSTicketExpired;
matchmakingSessionDSWrapper_Starter.OnMatchmakingWithDSJoinSessionStarted -= OnMatchmakingWithDSJoinSessionStarted;
matchmakingSessionDSWrapper_Starter.OnMatchmakingWithDSJoinSessionCompleted -= OnMatchmakingWithDSJoinSessionCompleted;
matchmakingSessionDSWrapper_Starter.OnMatchmakingWithDSCanceled -= OnMatchmakingWithDSCanceled;
matchmakingSessionDSWrapper_Starter.OnMatchmakingWithDSError -= ErrorPanel;
matchmakingSessionDSWrapper_Starter.OnMatchmakingError -= ErrorPanel;
matchmakingSessionDSWrapper_Starter.OnDSError -= ErrorPanel;
matchmakingSessionDSWrapper_Starter.OnIntentionallyLeaveSession -= Reset;
matchmakingSessionDSWrapper_Starter.OnDSAvailable -= Traveling;
}You have
OnMatchTicketDSCreated
that is responsible for updating the loading and showing of the cancel button. This button usesCancelDSMatchmaking
as a callback. To be able to cancel matchmaking, update theCancelDSMatchmaking
function with the code below.private void CancelDSMatchmaking()
{
matchmakingSessionDSWrapper_Starter.CancelDSMatchmaking();
ShowLoading("Cancelling Match", "Cancelling match is timed out", cancelMatchmakingTimeoutSec);
}You should leave a session whenever the loading has timed out. Go to
OnDSTimeOut
and update it with the code below. This code will let player leave the current session.private void OnDSTimeOut()
{
matchmakingSessionDSWrapper_Starter.LeaveCurrentSession();
Reset();
}
Now, when you quick play using the Elimination game mode using a dedicated server, the game will start dedicated server matchmaking via the MatchmakingSessionDSWrapper_Starter
class.
Resources
- The files used in this tutorial section is available in the ByteWars GitHub repository.