Browse match sessions with the SDK - Browse dedicated server joinable sessions - (Unity module)
Unwrap the wrapper
In this tutorial, you will learn how to browse match sessions using the AccelByte Gaming Services (AGS) Game SDK. In the Byte Wars, project there is already an SDK wrapper created named BrowseMatchSessionWrapper.cs
. This class will call the AGS Game SDK API to browse match sessions. In this tutorial, you will use a starter version of the wrapper called BrowseMatchSessionWrapper_Starter
to follow along from scratch.
What's in the Starter Pack
The BrowseMatchSessionWrapper_Starter
is similar to MatchSessionDSWrapper_Starter.cs
. It is a subclass of MatchSessionWrapper
, which has all the functionalities from its parent. The BrowseMatchSessionWrapper_Starter
class has several features related to session management. you can get more information from the MatchSessionWrapper.cs file on GitHub.
Implement browse match session
In this section, you will implement the AGS Game SDK API call to browse match sessions.
Open
BrowseMatchSessionWrapper_Starter.cs
. Modify theBrowseMatch
function as shown below. The AGS Game SDK API call for browsing game sessions isBrowseCustomMatchSession
which inherited fromMatchSessionWrapper.cs
protected internal void BrowseMatch(Action<BrowseMatchResult> onSessionRetrieved)
{
nextPage = "";
isBrowseMatchSessionsCanceled = false;
onQueryMatchSessionFinished = onSessionRetrieved;
BrowseCustomMatchSession(MatchSessionConfig.CreatedMatchSessionAttribute);
}Modify the
OnBrowseMatchSessionsComplete
function as shown below. The function will handle the results for browsing game sessions.private void OnBrowseMatchSessionsComplete(Result<PaginatedResponse<SessionV2GameSession>> result)
{
if (!result.IsError)
{
if (!isBrowseMatchSessionsCanceled)
onQueryMatchSessionFinished?.Invoke(new BrowseMatchResult(result.Value.data));
nextPage = result.Value.paging.next;
}
else
{
if (!isBrowseMatchSessionsCanceled)
onQueryMatchSessionFinished?.Invoke(new BrowseMatchResult(null, result.Error.Message));
}
}Add the code below to
Start()
.private void Start()
{
OnBrowseMatchSessionCompleteEvent += OnBrowseMatchSessionsComplete;
}
Resources
GitHub links to the files in the Unity Byte Wars repository: