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

すべてを統合する - フレンドリストを表示する - (Unity モジュール)

Last updated on November 7, 2025

Connect the UI to get friend list

  1. Open FriendsMenu_Starter.cs and declare the FriendsEssentialsWrapper_Starter class as a private variable.

    private FriendsEssentialsWrapper_Starter friendsEssentialsWrapper;
  2. Replace the existing LoadFriendList() function with the code below to call the GetFriendList() function from the FriendsEssentialsWrapper_Starter class. This will trigger the actual friend list retrieval from the backend.

    private void LoadFriendList()
    {
    widgetSwitcher.SetWidgetState(AccelByteWarsWidgetSwitcher.WidgetState.Loading);
    ClearFriendList();

    friendsEssentialsWrapper.GetFriendList(OnLoadFriendListCompleted);
    }
  3. Replace the existing OnLoadFriendListCompleted callback function with the code below to handle the result.

    private void OnLoadFriendListCompleted(Result<Friends> result)
    {
    if (result.IsError)
    {
    widgetSwitcher.SetWidgetState(AccelByteWarsWidgetSwitcher.WidgetState.Error);
    return;
    }

    if (result.Value.friendsId.Length <= 0)
    {
    widgetSwitcher.SetWidgetState(AccelByteWarsWidgetSwitcher.WidgetState.Empty);
    return;
    }

    GetBulkUserInfo(result.Value);
    }
  4. Create a function called GetBulkUserInfo() to get the user information from the list of friend IDs.

    private void GetBulkUserInfo(Friends friends)
    {
    friendsEssentialsWrapper.GetBulkUserInfo(friends.friendsId, OnGetBulkUserInfoCompleted);
    }
  5. Create a callback function called OnGetBulkUserInfoCompleted() to handle the result.

    private void OnGetBulkUserInfoCompleted(Result<AccountUserPlatformInfosResponse> result)
    {
    if (result.IsError)
    {
    widgetSwitcher.SetWidgetState(AccelByteWarsWidgetSwitcher.WidgetState.Error);
    return;
    }

    ClearFriendList();
    widgetSwitcher.SetWidgetState(AccelByteWarsWidgetSwitcher.WidgetState.Not_Empty);

    PopulateFriendList(result.Value.Data);
    }
  6. Create a function called PopulateFriendList() to populate the friend list.

    private void PopulateFriendList(params AccountUserPlatformData[] userInfo)
    {
    foreach (AccountUserPlatformData baseUserInfo in userInfo)
    {
    CreateFriendEntry(baseUserInfo.UserId, AccelByteWarsOnlineUtility.GetDisplayName(baseUserInfo));
    }
    }
  7. Create a function called CreateFriendEntry() to create a friend entry for each friend. If the friend's display name is empty, the function will use the first five characters of the user ID as the display name.

    private void CreateFriendEntry(string userId, string displayName)
    {
    GameObject playerEntry = InstantiateToColumn(friendEntryPrefab);
    playerEntry.name = userId;

    FriendEntry playerEntryHandler = playerEntry.GetComponent<FriendEntry>();
    playerEntryHandler.EntryView = FriendEntry.FriendEntryView.Default;
    playerEntryHandler.UserId = userId;
    playerEntryHandler.FriendName.text = displayName;

    friendEntries.Add(userId, playerEntry);
    }
  8. Replace the existing OnEnable() function with the code below to initialize the friendsEssentialsWrapper variable and call the LoadFriendList() function.

    private void OnEnable()
    {
    if (friendsEssentialsWrapper == null)
    {
    friendsEssentialsWrapper = TutorialModuleManager.Instance.GetModuleClass<FriendsEssentialsWrapper_Starter>();
    }

    if (friendsEssentialsWrapper == null)
    {
    BytewarsLogger.LogWarning("FriendsEssentialsWrapper_Starter is not enabled");
    return;
    }

    LoadFriendList();
    }

Connect the UI to display avatars of friends

  1. Open FriendsMenu_Starter.cs and create a function called RetrieveUserAvatar() to get the user avatar.

    private void RetrieveUserAvatar(string userId)
    {
    friendsEssentialsWrapper.GetUserAvatar(userId, result => OnGetAvatarCompleted(result, userId));
    }
  2. Create a callback function called OnGetAvatarCompleted() to handle the result.

    private void OnGetAvatarCompleted(Result<Texture2D> result, string userId)
    {
    if (result.IsError)
    {
    BytewarsLogger.LogWarning($"Unable to get avatar for user Id: {userId}, " +
    $"Error Code: {result.Error.Code}, " +
    $"Error Message: {result.Error.Message}");
    return;
    }

    if (result.Value == null || !friendEntries.TryGetValue(userId, out GameObject friendEntry))
    {
    return;
    }

    Image friendImage = friendEntry.GetComponent<FriendEntry>().FriendImage;
    Rect imageRect = new Rect(0f, 0f, result.Value.width, result.Value.height);
    friendImage.sprite = Sprite.Create(result.Value, imageRect, Vector2.zero);
    }
  3. Update the CreateFriendEntry() function to call the RetrieveUserAvatar() function. Add the code below:

    private void CreateFriendEntry(string userId, string displayName)
    {
    //...
    friendEntries.Add(userId, playerEntry);

    RetrieveUserAvatar(userId);
    }

Connect the entry to the friend details menu

  1. Open FriendsMenu_Starter.cs and create a function called OnFriendEntryClicked() to handle the friend entry click event. This function will instantiate the friend details menu canvas, pass the user information, and change the menu to the friend details menu.

    private void OnFriendEntryClicked(string userId, string displayName, FriendEntry playerEntryHandler)
    {
    if (friendDetailsAssetEnum is AssetEnum.FriendDetailsMenu_Starter)
    {
    MenuManager.Instance.InstantiateCanvas(friendDetailsAssetEnum);
    }

    if (!MenuManager.Instance.AllMenu.TryGetValue(friendDetailsAssetEnum, out MenuCanvas menuCanvas))
    {
    BytewarsLogger.LogWarning($"Unable to find {friendDetailsAssetEnum} in menu manager");
    return;
    }

    if (menuCanvas.gameObject.TryGetComponent(out FriendDetailsMenu_Starter friendDetailMenu))
    {
    friendDetailMenu.UserId = userId;
    friendDetailMenu.FriendImage.sprite = playerEntryHandler.FriendImage.sprite;
    friendDetailMenu.FriendDisplayName.text = displayName;
    }

    MenuManager.Instance.ChangeToMenu(friendDetailsAssetEnum);
    }
  2. Update the CreateFriendEntry() function to add an event listener to the friend entry to call the OnFriendEntryClicked() function. Add the code below.

    private void CreateFriendEntry(string userId, string displayName)
    {
    //...
    playerEntryHandler.FriendName.text = displayName;

    Button friendButton = playerEntry.GetComponent<Button>();
    friendButton.onClick.AddListener(() => OnFriendEntryClicked(userId, displayName, playerEntryHandler));

    friendEntries.Add(userId, playerEntry);
    //...
    }

Connect the UI to Friends Action Events

In this section, you will use the static action events that you have used in the Add friends and Manage friends modules. If you have not completed or do not intend to complete those modules, you will only forfeit the real-time friend list update feature.

  1. Open FriendsMenu_Starter.cs and create a function called OnFriendListUpdate(). It will trigger the LoadFriendList() function, updating the current displayed list.

    private void OnFriendListUpdate(string userId)
    {
    if (!gameObject.activeSelf)
    {
    return;
    }

    LoadFriendList();
    }
  2. Update the Awake() function to bind the action events in the wrapper to the OnFriendListUpdate() function. Add the code below:

    private void Awake()
    {
    //...
    backButton.onClick.AddListener(MenuManager.Instance.OnBackPressed);

    FriendsEssentialsModels.OnRequestAccepted += OnFriendListUpdate;
    ManagingFriendsModels.OnPlayerUnfriended += OnFriendListUpdate;
    ManagingFriendsModels.OnPlayerBlocked += OnFriendListUpdate;
    //...
    }
  3. Replace the OnDestroy() function with the code below to unbind those events when the UI is destroyed.

    private void OnDestroy()
    {
    FriendsEssentialsModels.OnRequestAccepted -= OnFriendListUpdate;
    ManagingFriendsModels.OnPlayerUnfriended -= OnFriendListUpdate;
    ManagingFriendsModels.OnPlayerBlocked -= OnFriendListUpdate;
    }

Connect the UI to display friend details

  1. Open FriendDetailsMenu_Starter.cs and declare the module wrappers by adding the following code:

    private FriendsEssentialsWrapper friendsEssentialsWrapper;
  2. Update the OnEnable() function and define the module wrappers. Add the code below.

    private void OnEnable()
    {
    if (friendsEssentialsWrapper == null)
    {
    friendsEssentialsWrapper = TutorialModuleManager.Instance.GetModuleClass<FriendsEssentialsWrapper>();
    }

    if (friendsEssentialsWrapper != null && !string.IsNullOrEmpty(UserId))
    {
    friendsEssentialsWrapper.GetFriendshipStatus(UserId, OnGetFriendshipStatusCompleted);
    }

    DisableAllButtons();
    }
  3. Update Awake() to wire up incoming/request lifecycle events and declare the registered functions.

    private void Awake()
    {
    ...
    InitializePartyButtons();

    FriendsEssentialsModels.OnIncomingRequest += OnIncomingRequest;
    FriendsEssentialsModels.OnRequestAccepted += OnRequestAccepted;
    FriendsEssentialsModels.OnRequestCanceled += OnRequestCanceled;
    FriendsEssentialsModels.OnRequestRejected += OnRequestRejected;
    }

    private void OnRequestRejected (string userId)
    {
    if (!gameObject.activeSelf || userId != UserId)
    {
    return;
    }

    addFriendButton.gameObject.SetActive(true);
    cancelButton.gameObject.SetActive(false);
    }
    private void OnRequestCanceled (string userId)
    {
    if (!gameObject.activeSelf || userId != UserId)
    {
    return;
    }
    addFriendButton.gameObject.SetActive(true);
    acceptButton.gameObject.SetActive(false);
    rejectButton.gameObject.SetActive(false);
    }
    private void OnIncomingRequest (string userId)
    {
    if (!gameObject.activeSelf || userId != UserId)
    {
    return;
    }
    acceptButton.gameObject.SetActive(true);
    rejectButton.gameObject.SetActive(true);
    addFriendButton.gameObject.SetActive(false);
    }
    private void OnRequestAccepted (string userId)
    {
    if (!gameObject.activeSelf || userId != UserId)
    {
    return;
    }
    unfriendButton.gameObject.SetActive(true);
    cancelButton.gameObject.SetActive(false);
    }

Connect the UI to send friend request

  1. Update the Addfriend() function to enable sending a friend request to player. Replace the existing implementation with the code below.

    private void AddFriend()
    {
    friendsEssentialsWrapper.SendFriendRequest(UserId, OnAddfriendCompleted);
    addFriendButton.gameObject.SetActive(false);
    }
  2. Create a new function called OnAddfriendCompleted() to handle the result.

    private void OnAddfriendCompleted(Result result)
    {
    if (result.IsError)
    {
    MenuManager.Instance.PromptMenu.ShowPromptMenu(FriendsEssentialsModels.PromptErrorTitle,
    result.Error.Message, "OK", null);
    return;
    }

    BytewarsLogger.Log($"Successfully add player with user ID: {UserId}");

    MenuManager.Instance.PushNotification(new PushNotificationModel
    {
    Message = result.IsError ? FriendsEssentialsModels.DefaultSendFriendRequestErrorMessage : FriendsEssentialsModels.FriendRequestSentDetailsMessage
    });
    cancelButton.gameObject.SetActive(true);
    }

Connect the UI to cancel friend request

  1. Update the CancelFriendRequest() function to cancel friend request. Replace the existing implementation with the code below.

    private void CancelFriendRequest()
    {
    friendsEssentialsWrapper.CancelFriendRequests(UserId, OnFriendRequestCanceled);
    cancelButton.gameObject.SetActive(false);
    }
  2. Create a new function called OnFriendRequestCanceled() to handle the result.

    private void OnFriendRequestCanceled (Result result)
    {
    if (result.IsError)
    {
    MenuManager.Instance.PromptMenu.ShowPromptMenu(FriendsEssentialsModels.PromptErrorTitle,
    result.Error.Message, "OK", null);
    return;
    }

    BytewarsLogger.Log($"Successfully canceled friend request with user ID: {UserId}");

    MenuManager.Instance.PushNotification(new PushNotificationModel
    {
    Message = result.IsError ? FriendsEssentialsModels.ErrorStatusMessage : FriendsEssentialsModels.FriendRequestCanceledMessage
    });

    addFriendButton.gameObject.SetActive(true);
    }

Connect the UI to accept friend request

  1. Update the AcceptFriendRequest() function to accept a friend request. Replace the existing implementation with the code below.

    private void AcceptFriendRequest()
    {
    friendsEssentialsWrapper.AcceptFriend(UserId, OnAcceptFriendCompleted);
    acceptButton.gameObject.SetActive(false);
    rejectButton.gameObject.SetActive(false);
    }
  2. Create a new function called OnAcceptFriendCompleted() to handle the result.

    private void OnAcceptFriendCompleted (Result result)
    {
    if (result.IsError)
    {
    MenuManager.Instance.PromptMenu.ShowPromptMenu(FriendsEssentialsModels.PromptErrorTitle,
    result.Error.Message, "OK", null);
    return;
    }

    BytewarsLogger.Log($"Successfully accepted friend request with user ID: {UserId}");

    MenuManager.Instance.PushNotification(new PushNotificationModel
    {
    Message = result.IsError ? FriendsEssentialsModels.ErrorStatusMessage : FriendsEssentialsModels.FriendRequestAcceptedMessage
    });

    unfriendButton.gameObject.SetActive(true);
    }

Connect the UI to decline friend request

  1. Update the RejectFriendRequest() function to decline a friend request. Replace the existing implementation with the code below.

    private void RejectFriendRequest()
    {
    friendsEssentialsWrapper.DeclineFriend(UserId, OnRejectFriendRequest);
    rejectButton.gameObject.SetActive(false);
    acceptButton.gameObject.SetActive(false);
    }
  2. Create a new function called OnRejectFriendRequest() to handle the result.

    private void OnRejectFriendRequest (Result result)
    {
    if (result.IsError)
    {
    MenuManager.Instance.PromptMenu.ShowPromptMenu(FriendsEssentialsModels.PromptErrorTitle,
    result.Error.Message, "OK", null);
    return;
    }

    BytewarsLogger.Log($"Successfully accepted friend request with user ID: {UserId}");

    MenuManager.Instance.PushNotification(new PushNotificationModel
    {
    Message = result.IsError ? FriendsEssentialsModels.ErrorStatusMessage : FriendsEssentialsModels.FriendRequestRejectedMessage
    });

    addFriendButton.gameObject.SetActive(true);
    }

Resources