フレンドリクエストメニューを追加する - フレンドを追加する - (Unity モジュール)
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
- CS file:
- 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
- CS file:
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
- CS file:
- 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
- CS file:
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.
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.
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.
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.
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.
Open Byte Wars in Unity.
Open
FriendRequestMenuHandler_Starter.cs
and create a new function calledGetFriendRequest
.private void GetFriendRequest()
{
//TODO: replace logwarning with sdk warpper.
Debug.LogWarning($"Get friend request list is not yet implemented.");
}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.");
}Update the
OnEnable()
function for bothFriendRequestMenuHandler_Starter.cs
andSentFriendRequestMenuHandler_Starter.cs
with the following code:private void OnEnable()
{
GetFriendRequest();
}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
- The files used in this tutorial are available in the Unity Byte Wars GitHub repository.
- Assets/Resources/Modules/FriendEssentials/Prefabs/FriendRequest/FriendRequestMenuCanvas_Starter.prefab
- Assets/Resources/Modules/FriendEssentials/Scripts/UI/FriendRequestMenuHandler_Starter.cs
- Assets/Resources/Modules/FriendEssentials/Prefabs/FriendRequest/FriendRequestEntryComponent.prefab
- Assets/Resources/Modules/FriendEssentials/Scripts/UI/FriendRequestsEntryHandler.cs
- Assets/Resources/Modules/FriendEssentials/Prefabs/SentFriendRequest/SentFriendRequestMenuCanvas_Starter.prefab
- Assets/Resources/Modules/FriendEssentials/Scripts/UI/SentFriendRequestMenuHandler_Starter.cs
- Assets/Resources/Modules/FriendEssentials/Prefabs/SentFriendRequest/SentFriendRequestEntryComponent.prefab
- Assets/Resources/Modules/FriendEssentials/Scripts/UI/SentFriendRequestsEntryHandler.cs