メインコンテンツまでスキップ

すべてを統合する - 専用サーバーの参加可能なセッションを閲覧する - (Unity モジュール)

Last updated on October 23, 2024

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

  1. 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. Modify BrowseMatchSession function as follows:

    private void BrowseMatchSession()
    {
    ResetList();
    browseMatchSessionWrapper_starter.BrowseMatch(OnBrowseMatchSessionFinished);
    ShowLoading("Getting match sessions...", CancelBrowseMatchSession);
    }
  2. 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);
    }
    }
  3. Go to BindEvent() function and add the code below.

    注記

    You need to add the code to the UI Handler script for the module you are currently working on (dedicated servers or peer-to-peer).

    private void BindEvent()
    {
    ...
    matchSessionDSWrapper_starter.BindMatchSessionDSEvents();
    ...
    }
  4. Go to the UnbindEvent() function and add this line to that function.

    備考

    You need to add the code to the UI Handler script for the module you are currently working on (dedicated servers or peer-to-peer).

    private void UnbindEvent()
    {
    ...
    matchSessionDSWrapper_starter.UnbindMatchSessionDSEvents();
    ...
    }

Join match session

  1. Open the BrowseMatchMenuCanvas_Starter.cs file with your code editor. Then, go to the JoinMatch function and implement the code below within the function. This code uses JoinMatchSession from MatchSessionWrapper 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);
    }
  2. To cancel joining a match, update the CancelJoinMatchSession function with the code below:

    private void CancelJoinMatchSession()
    {
    HideLoadingBackToMainPanel();
    MatchSessionWrapper.CancelJoinMatchSession();
    }

Resources