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

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

Last updated on November 25, 2024
備考

Browsing P2P sessions is not supported in WebGL builds due to the AGS SDK for Unity lacking the P2P functionality for WebGL. As a result, some code snippets include the UNITY_WEBGL preprocessor to handle this limitation.

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;
private MatchSessionDSWrapper_Starter matchSessionDSWrapper;
private MatchSessionP2PWrapper_Starter matchSessionP2PWrapper;
private void Start()
{
browseMatchSessionWrapper = TutorialModuleManager.Instance.GetModuleClass<BrowseMatchSessionWrapper_Starter>();
matchSessionWrapper = TutorialModuleManager.Instance.GetModuleClass<MatchSessionWrapper>();
matchSessionDSWrapper = TutorialModuleManager.Instance.GetModuleClass<MatchSessionDSWrapper_Starter>();
#if !UNITY_WEBGL
matchSessionP2PWrapper = TutorialModuleManager.Instance.GetModuleClass<MatchSessionP2PWrapper_Starter>();
#endif
...
}

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.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.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.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.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