Put it all together - Browse dedicated server joinable sessions - (Unity module)
Hook up the session UI
A C# file has been provided called BrowseMatchMenuCanvas_Starter.cs
to show the UI for the browse match session. Inside it, you will see the starter wrappers already defined as variables.
private MatchSessionWrapper matchSessionWrapper;
private BrowseMatchSessionWrapper_Starter browseMatchSessionWrapper_starter;
private MatchSessionDSWrapper_Starter matchSessionDSWrapper_starter;
private MatchSessionP2PWrapper_Starter matchSessionP2PWrapper_starter;
private void Start()
{
browseMatchSessionWrapper_starter = TutorialModuleManager.Instance.GetModuleClass<BrowseMatchSessionWrapper_Starter>();
matchSessionWrapper = TutorialModuleManager.Instance.GetModuleClass<MatchSessionWrapper>();
matchSessionDSWrapper_starter = TutorialModuleManager.Instance.GetModuleClass<MatchSessionDSWrapper_Starter>();
matchSessionP2PWrapper_starter = TutorialModuleManager.Instance.GetModuleClass<MatchSessionP2PWrapper_Starter>();
...
}
Browse joinable match session
Open
BrowseMatchMenuCanvas_Starter.cs
file with your code editor. You will call the AccelByte Gaming Services (AGS) Game SDK API to browse match sessions via the wrapper class. ModifyBrowseMatchSession
function as follows:private void BrowseMatchSession()
{
ResetList();
browseMatchSessionWrapper_starter.BrowseMatch(OnBrowseMatchSessionFinished);
ShowLoading("Getting match sessions...", CancelBrowseMatchSession);
}To handle pagination received from the AGS Game SDK API, modify the
OnScrollValueChanged
function to call the starter wrapper class as shown below.private void OnScrollValueChanged(Vector2 scrollPos)
{
//scroll reach bottom
if (scrollPos.y <= 0)
{
browseMatchSessionWrapper_starter.QueryNextMatchSessions(OnNextPageMatchSessionsRetrieved);
}
}Go to
BindEvent()
function and add the code below.noteYou need to add the code to the UI Handler script for the module you are currently working on (dedicated servers or peer-to-peer).
- MatchSession With DS
- MatchSession With P2P
private void BindEvent()
{
...
matchSessionDSWrapper_starter.BindMatchSessionDSEvents();
...
}private void BindEvent()
{
...
matchSessionP2PWrapper_starter.BindMatchSessionP2PEvents();
...
}Go to the
UnbindEvent()
function and add this line to that function.infoYou need to add the code to the UI Handler script for the module you are currently working on (dedicated servers or peer-to-peer).
- MatchSession With DS
- MatchSession With P2P
private void UnbindEvent()
{
...
matchSessionDSWrapper_starter.UnbindMatchSessionDSEvents();
...
}private void UnbindEvent()
{
...
matchSessionP2PWrapper_starter.UnbindMatchSessionP2PEvents();
...
}
Join match session
Open the
BrowseMatchMenuCanvas_Starter.cs
file with your code editor. Then, go to theJoinMatch
function and implement the code below within the function. This code usesJoinMatchSession
fromMatchSessionWrapper
that was explained in the previous tutorial. This function is used from parent class because this module will handle joining to a game session for dedicated servers and peer-to-peer.private void JoinMatch(JoinMatchSessionRequest request)
{
ShowLoading("Joining Match Session...", CancelJoinMatchSession);
MatchSessionWrapper.JoinMatchSession(request.MatchSessionId, request.GameMode);
}To cancel joining a match, update the
CancelJoinMatchSession
function with the code below:private void CancelJoinMatchSession()
{
HideLoadingBackToMainPanel();
MatchSessionWrapper.CancelJoinMatchSession();
}
Resources
- The file used in this tutorial section is available in the Unity Byte Wars GitHub repository: