フレンド管理メニューを追加する - フレンドを管理する - (Unity モジュール)
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:
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/FriendsEssentials/Scripts/UI/FriendDetailsMenuHandler_Starter.cs
- Prefab file:
/Assets/Resources/Modules/FriendsEssentials/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/BlockedPlayerEntryHandler.cs
- Prefab file:
/Assets/Resources/Modules/ManagingFriends/Prefabs/BlockedPlayers/BlockedPlayerEntryComponent.prefab
- CS file:
Blocked Player Canvas
Below is the preview of BlockedPlayersMenuCanvas_Starter.prefab
. This prefab contains the following panels:
- Default Panel: Displays default text messages when there are no blocked players.
- Loading Panel: Displays loading animation when the game is fetching blocked players.
- Loading Failed Panel: Displays a message when the game fails to fetch blocked players.
- Result Content Panel: Displays the list of blocked players.
The BlockedPlayersMenuHandler_Starter.cs
script has the following fields to store the UI references:
[Header("Blocked Players Component"), SerializeField] private GameObject playerEntryPrefab;
[Header("View Panels"), SerializeField] private RectTransform defaultPanel;
[SerializeField] private RectTransform loadingPanel;
[SerializeField] private RectTransform loadingFailedPanel;
[SerializeField] private RectTransform resultContentPanel;
Change the panel by setting the value of currentView
attribute. For example:
currentView = BlockedFriendsView.Default;
It also has a function to clear the current displayed list:
private void ClearBlockedPlayers()
{
resultContentPanel.DestroyAllChildren();
blockedPlayers.Clear();
}
Friend Details Canvas
Below is the preview of the FriendDetailsMenuCanvas_Starter.prefab
. This prefab displays friend information, such as display name, avatar, block button, and unfriend button.
The FriendDetailsMenuHandler_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 Component
Below is the preview of the BlockedPlayerEntryComponent.prefab
. This prefab displays friend information, such as display name, avatar, and send invite buttons.
The FriendDetailsMenuHandler_Starter.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
Open the
BlockedPlayersMenuHandler_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 toLoadBlockedPlayers()
.private void OnLoadBlockedPlayersCompleted(Result<BlockedList> result)
{
// TODO: Implement Load Blocked Players callback functions here.
BytewarsLogger.LogWarning("The OnLoadBlockedPlayersCompleted method is not implemented yet");
}
Open
FriendDetailsMenuHandler_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 theBlockPlayer()
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 theUnfriend()
function.private void OnUnfriendCompleted(Result result)
{
// TODO: Implement OnUnfriendCompleted function here.
BytewarsLogger.LogWarning("OnUnfriendCompleted is not yet implemented.");
}
In 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. 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:
[BlockedPlayersMenuHandler_Starter] [LoadBlockedPlayers] - The LoadBlockedPlayers method is not implemented yet
For Social > Friends > [click any friend entry] > Block, you will see the following log:
[FriendDetailsMenuHandler_Starter] [Unfriend] - Unfriend is not yet implemented.
For Social > Friends > [click any friend entry] > Unfriend, you will be able to see the following log:
[FriendDetailsMenuHandler_Starter] [BlockPlayer] - BlockPlayer 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/FriendsEssentials/Scripts/UI/FriendDetailsMenuHandler_Starter.cs
- Assets/Resources/Modules/FriendsEssentials/Prefabs/FriendDetails/FriendDetailsMenuCanvas_Starter.prefab