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

SDK を使用してフレンドリストのクエリを実行する - フレンドリストを表示する - (Unity モジュール)

Last updated on December 13, 2024

What's in the Starter Pack

This tutorial module shows how to use the AccelByte Gaming Services (AGS) Game SDK to query the friend list.

You will use the FriendsEssentialsWrapper_Starter class to query the friend list and listen to the unfriend event.

  • FriendsEssentialsWrapper_Starter file: /Assets/Resources/Modules/FriendsEssentials/Scripts/FriendsEssentialsWrapper_Starter.cs

The following are the events and variables that you will use:

  • Delegate to handle the friend accepted event. This the event that you have used to integrate AGS Game SDK callback in the previous module. You will use this delegate in the friends menu later.

    public static event Action<string> OnRequestAccepted = delegate { };
  • Variable to store the list of social-related data that can be listened to by other scripts. This will be used later to update the user presence of the friend list.

    public ObservableList<string> CachedFriendUserIds { get; private set; } = new ObservableList<string>();

Implement getting friend list

  1. Open FriendsEssentialsWrapper_Starter.cs and create a function called GetFriendList. This function retrieves the friend list and store the friend user IDs in the CachedFriendUserIds list.

    public void GetFriendList(ResultCallback<Friends> resultCallback = null)
    {
    lobby.LoadFriendsList(result =>
    {
    if (result.IsError)
    {
    BytewarsLogger.LogWarning("Error loading friends list, " +
    $"Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
    }
    else
    {
    BytewarsLogger.Log("Successfully loaded friends list");
    CachedFriendUserIds.Add(result.Value.friendsId);
    }

    resultCallback?.Invoke(result);
    });
    }

Resources