Skip to main content

Add friends management menu - Manage friends - (Unity module)

Last updated on October 24, 2024

What's on the menu

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

  • BlockedPlayersMenuCanvas_Starter: A UI menu to show the blocked player list.
    • CS file: /Assets/Resources/Modules/ManagingFriends/Scripts/UI/BlockedPlayersMenuHandler_Starter.cs
    • Prefab file: /Assets/Resources/Modules/ManagingFriends/Prefabs/BlockedPlayers/BlockedPlayersMenuCanvas_Starter.prefab
  • FriendDetailsMenuCanvas_Starter: A UI menu to display individual friend information.
    • CS file: /Assets/Resources/Modules/FriendEssentials/Scripts/UI/FriendDetailsMenuHandler_Starter.cs
    • Prefab file: /Assets/Resources/Modules/FriendEssentials/Prefabs/FriendDetails/FriendDetailsMenuCanvas_Starter.prefab
  • BlockedPlayerEntryComponent: A UI component to display the blocked friend information and an unblock button.
    • CS file: /Assets/Resources/Modules/ManagingFriends/Scripts/UI/BlockedFriendEntryHandler.cs
    • Prefab file: /Assets/Resources/Modules/ManagingFriends/Prefabs/BlockedPlayers/BlockedPlayerEntryComponent.prefab

Take a look at more details on how the UI is constructed.

Blocked Player Canvas

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

Potential friend entry widget Unity Byte Wars manage friends

Friend Details Canvas

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

Potential friend entry widget Unity Byte Wars manage friends

Blocked Players Component

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

Potential friend entry widget Unity Byte Wars manage friends

What's in the Starter Pack

There are two canvases that each have their own responsibilities.

First, BlockedPlayersMenuCanvas_Starter.prefab, which has a C# script called BlockedPlayersMenuHandler_Starter.cs. This script already includes predefined code which involves getting a list of user information, retrieving avatars, and generating the blocked players component.

Second, FriendDetailsMenuCanvas_Starter.prefab, which has C# script called FriendDetailsMenuHandler_Starter. In this menu, you will implement the block and unfriend functionalities by assigning the functions to the respective buttons.

Ready the UI

In this section, you will learn how to prepare the UI.

  1. Open BlockedPlayersMenuHandler_Starter.cs and update the GetBlockedPlayers function with the following code:

    private void GetBlockedPlayers()
    {
    CurrentView = BlockedFriendsView.Default;
    //TODO: replace logwarning with sdk warpper.
    Debug.LogWarning($"Get blocked player list is not yet implemented.");
    }
  2. Update OnEnable() with the following code:

    private void OnEnable()
    {
    GetBlockedPlayers();
    }
  3. Open FriendDetailsMenuHandler_Starter.cs and update OnUnfriendClicked() and OnUnfriendClicked() with the following code:

    private void OnUnfriendClicked()
    {
    Debug.LogWarning($"Unfriend a friend is not yet implemented.");
    }
    private void OnBlockCliked()
    {
    Debug.LogWarning($"Block a player is not yet implemented.");
    }
  4. In the 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.

    Activate Tutorial Module Asset Config starter mode Unity Byte Wars manage friends

  5. Play the game in the Editor and, if the implementation was successful, you will be able to navigate to the friends management menus and see their associated logs in the Console.

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

      Get blocked player list is not yet implemented.
    • For Social > Friends > [click any friend entry] > Block, you will see the following log:

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

      Unfriend a friend is not yet implemented.

Resources