フレンド管理メニューを追加する - フレンドを管理する - (Unity モジュール)
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
- CS file:
- 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
- CS file:
- 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
- CS file:
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.
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.
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.
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.
Open
BlockedPlayersMenuHandler_Starter.cs
and update theGetBlockedPlayers
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.");
}Update
OnEnable()
with the following code:private void OnEnable()
{
GetBlockedPlayers();
}Open
FriendDetailsMenuHandler_Starter.cs
and updateOnUnfriendClicked()
andOnUnfriendClicked()
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.");
}In the Unity Editor, go to
Assets/Resources/Modules/ManagingFriends
. There, you will find an asset config called ManagingFriendsAssetConfig. Open it and enableIs Starter Active
in the Inspector. This will activate the friends management Starter files.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
- The files used in this tutorial are available in the Unity Byte Wars GitHub repository.
- Assets/Resources/Modules/ManagingFriends/ManagingFriendsAssetConfig.asset
- Assets/Resources/Modules/ManagingFriends/Scripts/UI/BlockedPlayersMenuHandler_Starter.cs
- Assets/Resources/Modules/ManagingFriends/Prefabs/BlockedPlayers/BlockedPlayersMenuCanvas_Starter.prefab
- Assets/Resources/Modules/FriendEssentials/Scripts/UI/FriendDetailsMenuHandler_Starter.cs
- Assets/Resources/Modules/FriendEssentials/Prefabs/FriendDetails/FriendDetailsMenuCanvas_Starter.prefab