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_Starter.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.
As mentioned above, MatchSessionDSWrapper_Starter.cs
is a subclass of the MatchSessionWrapper.cs
class that already implements several functions for browsing and joining a match session.
A function called JoinMatchSession
has already been created. In this function, the leave session event is bound and calls the JoinSession
function to join a game session.
protected internal void JoinMatchSession(string sessionId, InGameMode gameMode)
{
GameManager.Instance.OnClientLeaveSession += LeaveCurrentGameSession;
GameManager.OnDisconnectedInMainMenu += DisconnectFromServer;
lobby.SessionV2GameSessionMemberChanged += OnV2GameSessionMemberChanged;
SelectedGameMode = gameMode;
JoinSession(sessionId);
}
The BrowseMatchSession
function uses the QueryGameSession
method (defined in the Introduction to Session module) to search for game sessions based on specified parameters.
protected internal void BrowseMatchSession(Dictionary<string, object> request)
{
QueryGameSession(request);
}
What's in the Starter Pack
The BrowseMatchSessionWrapper_Starter
is a subclass of MatchSessionWrapper
, which has all the functions from its parent. The BrowseMatchSessionWrapper_Starter
class has several features related to session management.
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 isBrowseMatchSession
which inherited fromMatchSessionWrapper.cs
protected internal void BrowseMatch(Action<BrowseMatchResult> onSessionRetrieved)
{
nextPage = string.Empty;
isBrowseMatchSessionsCanceled = false;
onQueryMatchSessionFinished = onSessionRetrieved;
BrowseMatchSession(CreateMatchConfig.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));
}
}
}
Resources
GitHub links to the files in the Unity Byte Wars repository: