フレンドリクエストメニューを追加する - フレンドを追加する - (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:
FriendRequestsMenu_Starter: A UI menu to display received friend requests.
- C# file:
Assets/Resources/Modules/FriendsEssentials/Scripts/UI/FriendRequestsMenu_Starter.cs
- Prefab file:
Assets/Resources/Modules/FriendsEssentials/Prefabs/FriendRequestsMenu_Starter.prefab
- C# file:
SentFriendRequestsMenu_Starter: A UI menu to display sent friend requests.
- C# file:
Assets/Resources/Modules/FriendsEssentials/Scripts/UI/SentFriendRequestsMenu_Starter.cs
- Prefab file:
Assets/Resources/Modules/FriendsEssentials/Prefabs/SentFriendRequestsMenu_Starter.prefab
- C# file:
FriendEntry: A UI component to display friend request information such as display name, avatar, and action buttons.
- C# file:
Assets/Resources/Modules/FriendsEssentials/Scripts/UI/FriendEntry.cs
- Prefab file:
Assets/Resources/Modules/FriendsEssentials/Prefabs/FriendEntry.prefab
- C# file:
Take a look at the prefabs of these UI menus for more detailed information.
Friend Requests Menu
Below is the preview of the FriendRequestsMenu_Starter.prefab
. This menu is used to display sent friend requests.
The components used in this prefab are declared in the FriendRequestsMenu_Starter.cs
file. Below are the declarations of the components used by this prefab.
[Header("Friend Request Components")]
[SerializeField] private GameObject friendEntryPrefab;
[Header("Menu Components")]
[SerializeField] private AccelByteWarsWidgetSwitcher widgetSwitcher;
[SerializeField] private RectTransform resultContentPanel;
The widgetSwitcher
component is used to switch the menu between different states, such as the default view, loading state, empty result state, and error state. The resultContentPanel
is used to display the friend request list by instantiating entries using the friendEntryPrefab
.
Sent Friend Requests Menu
Below is the preview of the SentFriendRequestsMenu_Starter.prefab
. This menu is used to display received friend requests.
The components used in this prefab are declared in the SentFriendRequestsMenu_Starter.cs
file. This prefab uses the following declarations of components:
[Header("Friend Request Components")]
[SerializeField] private GameObject friendEntryPrefab;
[Header("Menu Components")]
[SerializeField] private AccelByteWarsWidgetSwitcher widgetSwitcher;
[SerializeField] private RectTransform resultContentPanel;
[SerializeField] private Button backButton;
The widgetSwitcher
component is used to switch the menu between different states, such as the default view, loading state, empty result state, and error state. The resultContentPanel
is used to display the friend request list by instantiating entries using the friendEntryPrefab
.
Friend Entry
Below is the preview of FriendEntry.prefab
which is used to display recieved and sent friend request information such as display name, avatar, and action buttons.
The components used in this prefab are declared in the FriendEntry.cs
file. Below are the declarations of those components:
[SerializeField] private Image friendImage;
[SerializeField] private TMP_Text friendName;
[SerializeField] private Button rejectButton;
[SerializeField] private Button acceptButton;
[SerializeField] private Button cancelButton;
To manipulate those components, the script have these public getters:
public Image FriendImage => friendImage;
public TMP_Text FriendName => friendName;
public Button CancelButton => cancelButton;
public Button RejectButton => rejectButton;
public Button AcceptButton => acceptButton;
Ready the UI
In this section, you will learn how to prepare the UI for both the Friend Requests and Sent Friend Requests menus.
Open the
FriendRequestsMenu_Starter.cs
file. You will see a function calledLoadIncomingFriendRequests
. Later on, you will implement this function to query all incoming friend requests.private void LoadIncomingFriendRequests()
{
// TODO: Implement Load Incoming Friend Requests here.
BytewarsLogger.LogWarning("The LoadIncomingFriendRequests method is not implemented yet");
}In the
FriendRequestsMenu_Starter.cs
file, find theOnEnable()
function. This function is called when the UI is enabled.private void OnEnable()
{
// TODO: Define Module Wrappers and Load Incoming Friend Requests here.
}Open the
SentFriendRequestsMenu_Starter.cs
file. You will see a function calledLoadOutgoingFriendRequests
. Later on, you will implement this function to query all outgoing friend requests.private void LoadOutgoingFriendRequests()
{
// TODO: Implement Load Outgoing Friend Requests here.
BytewarsLogger.LogWarning("The LoadOutgoingFriendRequests method is not implemented yet");
}In the
SentFriendRequestsMenu_Starter.cs
file, find theOnEnable()
function. This function is called when the UI is enabled.private void OnEnable()
{
// TODO: Define Module Wrappers and Load Outgoing Friend Requests here.
}In the Unity Editor, go to
Assets/Resources/Modules/FriendsEssentials
, open theFriendsEssentialsAssetConfig
asset file and make sure theIs Starter Active
is set to true.Play the game in the Editor, log in, and go to Social > Friends Requests. If your implementation up to this point is successful, you will be able to open the Friend Requests menu and receive the following logs:
[FriendRequestsMenu_Starter.cs] [LoadIncomingFriendRequests] [Warning] [79] - The LoadIncomingFriendRequests method is not implemented yet
Still while playing the game in the editor, go to Social > Sent Friend Requests. If your implementation up to this point is successful, you will be able to open the Sent Friend Requests menu and receive the following logs:
[SentFriendRequestsMenu_Starter.cs] [LoadOutgoingFriendRequests] [Warning] [79] - The LoadOutgoingFriendRequests method is not implemented yet
Resources
- The files used in this tutorial are available in the Unity Byte Wars GitHub repository:
- Assets/Resources/Modules/FriendsEssentials/FriendsEssentialsAssetConfig.asset
- Assets/Resources/Modules/FriendsEssentials/Prefabss/FriendRequestsMenu_Starter.prefab
- Assets/Resources/Modules/FriendsEssentials/Scripts/UI/FriendRequestsMenu_Starter.cs
- Assets/Resources/Modules/FriendsEssentials/Prefabss/SentFriendRequestsMenu_Starter.prefab
- Assets/Resources/Modules/FriendsEssentials/Scripts/UI/SentFriendRequestsMenu_Starter.cs
- Assets/Resources/Modules/FriendsEssentials/Prefabs/FriendEntry.prefab
- Assets/Resources/Modules/FriendsEssentials/Scripts/UI/FriendEntry.cs