SDK を使用してフレンドリストのクエリを実行する - フレンドリストを表示する - (Unity モジュール)
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
Open
FriendsEssentialsWrapper_Starter.cs
and create a function calledGetFriendList
. This function retrieves the friend list and store the friend user IDs in theCachedFriendUserIds
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
- The file used in this tutorial is available in the Unity Byte Wars GitHub repository.