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

フレンド管理メニューを追加する - フレンドを管理する - (Unity モジュール)

Last updated on June 23, 2025

What's on the menu

In this tutorial, you will learn how to prepare the user interface (UI) that you will use to display blocked players and the action buttons to unfriend, block, and unblock players. The UI menus are available in the Resources section and consists of the following files:

  • BlockedPlayersMenu_Starter: A UI menu to show the blocked player list.
    • C# file: /Assets/Resources/Modules/ManagingFriends/Scripts/UI/BlockedPlayersMenu_Starter.cs
    • Prefab file: /Assets/Resources/Modules/ManagingFriends/Prefabs/BlockedPlayersMenu_Starter.prefab
  • BlockedPlayerEntry: A UI component to display the blocked friend information and an unblock button.
    • C# file: /Assets/Resources/Modules/ManagingFriends/Scripts/UI/BlockedPlayerEntry.cs
    • Prefab file: /Assets/Resources/Modules/ManagingFriends/Prefabs/BlockedPlayerEntry.prefab
  • FriendDetailsMenu_Starter: A UI menu to display individual friend information.
    • C# file: /Assets/Resources/Modules/FriendsEssentials/Scripts/UI/FriendDetailsMenu_Starter.cs
    • Prefab file: /Assets/Resources/Modules/FriendsEssentials/Prefabs/FriendDetailsMenu_Starter.prefab

Blocked Player Menu

Below is the preview of BlockedPlayersMenu_Starter.prefab. This menu is used to display blocked player list.

Blocked Player Menu Unity Byte Wars manage friends

The BlockedPlayersMenu_Starter.cs script has the following fields to store the UI references:

[Header("Blocked Players Component")]
[SerializeField] private GameObject playerEntryPrefab;

[Header("Menu Components")]
[SerializeField] private AccelByteWarsWidgetSwitcher widgetSwitcher;
[SerializeField] private RectTransform resultContentPanel;

The widgetSwitcher component is used to switch the menu between different states, such as the default view, loading state, empty result state, and error state. The resultContentPanel is used to display the friend request list by instantiating entries using the playerEntryPrefab.

It also has a function to clear the current displayed list:

private void ClearBlockedPlayers()
{
resultContentPanel.DestroyAllChildren();

blockedPlayers.Clear();
}

Friend Details Menu

Below is the preview of the FriendDetailsMenu_Starter.prefab. This prefab displays friend information, such as display name, avatar, block button, and unfriend button.

Potential friend entry widget Unity Byte Wars manage friends

The FriendDetailsMenu_Starter.cs sript has the following fields to store the UI references:

[Header("Friend Details"), SerializeField] private Image friendImage;
[SerializeField] private TMP_Text friendDisplayName;

[Header("Friend Components"), SerializeField] private Button blockButton;
[SerializeField] private Button unfriendButton;

public Image FriendImage => friendImage;
public TMP_Text FriendDisplayName => friendDisplayName;
public string UserId { get; set; } = string.Empty;

Blocked Players Entry

Below is the preview of the BlockedPlayerEntry.prefab. This prefab displays friend information, such as display name, avatar, and send invite buttons.

Potential friend entry widget Unity Byte Wars manage friends

The BlockedPlayerEntry.cs script has the following public getters and property to allow other script manipulate what it shows:

public string UserId { get; set; } = string.Empty;

public Image FriendImage => friendImage;
public TMP_Text FriendName => friendName;
public Button UnblockButton => unblockButton;

Ready the UI

  1. Open the BlockedPlayersMenu_Starter.cs file and find the following functions, which you will implement later on:

    • LoadBlockedPlayers(): You will implement this function to get the list of blocked players.

      private void LoadBlockedPlayers()
      {
      // TODO: Implement Load Blocked Players function here.
      BytewarsLogger.LogWarning("The LoadBlockedPlayers method is not implemented yet");
      }
    • OnLoadBlockedPlayersCompleted(): You will implement this function as the response to LoadBlockedPlayers().

      private void OnLoadBlockedPlayersCompleted(Result<BlockedList> result)
      {
      // TODO: Implement Load Blocked Players callback functions here.
      BytewarsLogger.LogWarning("The OnLoadBlockedPlayersCompleted method is not implemented yet");
      }
  2. Open FriendDetailsMenu_Starter.cs and find the following functions:

    • BlockPlayer(): You will implement this function to enable blocking other players.

      private void BlockPlayer()
      {
      // TODO: Implement Block Player function here.
      BytewarsLogger.LogWarning("BlockPlayer is not yet implemented.");
      }
    • OnBlockPlayerComplete(): You will implement this as a response function to the BlockPlayer() function.

      private void OnBlockPlayerComplete(Result<BlockPlayerResponse> result)
      {
      // TODO: Implement OnBlockPlayerComplete function here.
      BytewarsLogger.LogWarning("OnBlockPlayerComplete is not yet implemented.");
      }
    • Unfriend(): You will implement this function to enable unfriending other players.

      private void Unfriend()
      {
      // TODO: Implement Unfriend function here.
      BytewarsLogger.LogWarning("Unfriend is not yet implemented.");
      }
    • OnUnfriendCompleted(): You will implement this as a response function to the Unfriend() function.

      private void OnUnfriendCompleted(Result result)
      {
      // TODO: Implement OnUnfriendCompleted function here.
      BytewarsLogger.LogWarning("OnUnfriendCompleted is not yet implemented.");
      }
  3. In Unity Editor, go to Assets/Resources/Modules/ManagingFriends. There, you will find an asset config called ManagingFriendsAssetConfig. Open it and enable Is Starter Active in the Inspector. This will activate the friends management Starter files.

  4. Play the game in the Editor. If the implementation is successful, you will be able to navigate to the friends management menus and see the associated logs in the Console.

    • For Social > Block Players, you will see the following log:

      [BlockedPlayersMenu_Starter] [LoadBlockedPlayers] - The LoadBlockedPlayers method is not implemented yet
    • For Social > Friends > [click any friend entry] > Block, you will see the following log:

      [FriendDetailsMenu_Starter] [Unfriend] - Unfriend is not yet implemented.
    • For Social > Friends > [click any friend entry] > Unfriend, you will be able to see the following log:

      [FriendDetailsMenu_Starter] [BlockPlayer] - BlockPlayer is not yet implemented.

Resources