Skip to main content

Add friend requests menu - Add 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 display and handle sent or received friend requests. The UI files are available in the Resources section and consist of the following:

  • FriendRequestMenuCanvas_Starter: A UI menu to display received friend requests.
    • CS file: Assets/Resources/Modules/FriendEssentials/Scripts/UI/FriendRequestMenuHandler_Starter.cs
    • Prefab file: Assets/Resources/Modules/FriendEssentials/Prefabs/FriendRequest/FriendRequestMenuCanvas_Starter.prefab
  • SentFriendRequestMenuCanvas_Starter: A UI menu to display sent friend requests.
    • CS file: Assets/Resources/Modules/FriendEssentials/Scripts/UI/SentFriendRequestMenuHandler_Starter.cs
    • Prefab file: Assets/Resources/Modules/FriendEssentials/Prefabs/SentFriendRequest/SentFriendRequestMenuCanvas_Starter.prefab
  • FriendRequestEntryComponent: A UI component to display the received or sent friend request information, such as the display name, avatar, and action buttons.
    • CS file: Assets/Resources/Modules/FriendEssentials/Scripts/UI/FriendRequestsEntryHandler.cs
    • Prefab file: Assets/Resources/Modules/FriendEssentials/Prefabs/FriendRequest/FriendRequestEntryComponent.prefab
  • SentFriendRequestEntryComponent: A UI component to display the received or sent friend request information, such as the display name, avatar, and action buttons.
    • CS file: Assets/Resources/Modules/FriendEssentials/Scripts/UI/SentFriendRequestsEntryHandler.cs
    • Prefab file: Assets/Resources/Modules/FriendEssentials/Prefabs/SentFriendRequest/SentFriendRequestEntryComponent.prefab

Take a look at more details on how these UI menus are constructed.

Received Friend Requests Canvas

Below is the preview of the FriendRequestMenuCanvas_Starter.prefab. This prefab contains a list to display the received friend request entries.

Received friend requests widget Unity Byte Wars add friends

Sent Friend Requests Canvas

Below is the preview of the SentFriendRequestMenuCanvas_Starter.prefab. This prefab contains a list to display the sent friend request entries.

Sent friend requests widget Unity Byte Wars add friends

Friend Request Entry Component

Below is the preview of the FriendRequestEntryComponent.prefab. This prefab displays friend information, such as display name, avatar, and action buttons.

Received friend request entry widget Unity Byte Wars add friends

Sent Friend Request Entry Component

Below is the preview of the SentFriendRequestEntryComponent.prefab. This prefab displays friend information, such as display name, avatar, and action buttons.

Received friend request entry widget Unity Byte Wars add friends

What's in the Starter Pack

There are two UI scripts called FriendRequestMenuHandler_Starter.cs and SentFriendRequestMenuHandler_Starter.cs which include predefined code. Since most of the functionality for the menus of this module were outlined in Search for player, the explanation in this section will focus specifically on the functions that are unique to these script files.

The functionality already implemented in these scripts is the following:

  • A function called ClearFriendRequestList that is used to clear the friend request list, both incoming and outgoing.

      private void ClearFriendRequestList()
    {
    var tempFriendPanel = new List<GameObject>();
    foreach (var friendPanelHandler in _friendRequest)
    {
    if (friendPanelHandler.Value != null)
    {
    tempFriendPanel.Add(friendPanelHandler.Value.gameObject);
    }
    }

    tempFriendPanel.ForEach(Destroy);

    _friendRequest.Clear();
    }

Ready the UI

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

  1. Open Byte Wars in Unity.

  2. Open FriendRequestMenuHandler_Starter.cs and create a new function called GetFriendRequest.

    private void GetFriendRequest()
    {
    //TODO: replace logwarning with sdk warpper.
    Debug.LogWarning($"Get friend request list is not yet implemented.");
    }
  3. Open SentFriendRequestMenuHandler_Starter.cs and create a function using the snippet below.

    private void GetFriendRequest()
    {
    //TODO: replace logwarning with sdk warpper.
    Debug.LogWarning($"Sent friend request list is not yet implemented.");
    }
  4. Update the OnEnable() function for both FriendRequestMenuHandler_Starter.cs and SentFriendRequestMenuHandler_Starter.cs with the following code:

    private void OnEnable()
    {
    GetFriendRequest();
    }
  5. Play the game in the Editor. If your implementation up to this point was successful, you will be able to navigate to friend requests menus and receive the following logs:

    • For Social > Friend Requests:


      Get friend request list is not yet implemented.

    • For Social > Sent Friend Requests:


      Sent friend request list is not yet implemented.

Resources