統計データプロファイルメニュー UI - 統計データを追跡し表示する - (Unity モジュール)
What's on the Menu
In this section, you'll learn how to prepare UIs to display player statistics values. These UIs are defined in the following classes:
StatsProfileMenu_Starter: A C# class used to display statistical values and categories.
- CS file:
Assets/Resources/Modules/StatsEssentials/Scripts/UI/StatsProfileMenu_Starter.cs
- Prefab file:
Assets/Resources/Modules/StatsEssentials/Prefabs/StatsProfileMenu_Starter.prefab
- CS file:
StatsProfileEntry: A C# class used to display individual statistical values.
- CS file:
Assets/Resources/Modules/PartyEssentials/Scripts/UI/StatsProfileEntry.cs
- Prefab file:
Assets/Resources/Modules/PartyEssentials/Prefabs/StatsProfileEntry.prefab
- CS file:
Take a closer look at how these UIs are constructed.
Stats Profile Widget
Below is a preview of the StatsProfileMenu_Starter
prefab. This prefab includes tab menus that display statistical values based on game modes.
The components used in this menu are defined in the StatsProfileMenu_Starter
class. The widgetSwitcher
is a helper component used to display the menu state (e.g., loading, error, empty result, or result). Each statistical value is categorized into different panels based on the game modes. These panels are organized using the statsPanelList
helper variable.
[SerializeField] private AccelByteWarsWidgetSwitcher widgetSwitcher;
[SerializeField] private StatsProfileEntry statsEntryPrefab;
[SerializeField] private Transform singlePlayerStatsPanel;
[SerializeField] private Transform eliminationPlayerStatsPanel;
[SerializeField] private Transform teamDeathmatchPlayerStatsPanel;
[SerializeField] private Button backButton;
Stats Profile Widget Entry
Below is a preview of the StatsProfileEntry
prefab. This prefab is used to display a statistic's name and its value.
The components used in this widget are defined in the StatsProfileEntry
class.
[SerializeField] private TMP_Text statNameText;
[SerializeField] private TMP_Text statValueText;
Ready the UI
In this section, you are going to prepare the menus mentioned earlier to start integrating the statistics.
Open the
StatsProfileMenu_Starter
class and create a new function below. Later, you will revisit this function to send requests to get player statistics values from AGS. For now, add the code below to switch the menu to the loading state.private void DisplayStats()
{
widgetSwitcher.SetWidgetState(AccelByteWarsWidgetSwitcher.WidgetState.Loading);
}In the
OnEnable()
function when the menu is displayed, call the function above.void OnEnable()
{
DisplayStats();
}In the Unity editor, go to
Assets/Resources/Modules/StatsEssentials
and open theStatsEssentialsAssetConfig.asset
. Then, make sure to activate the module in starter mode by ticking theIs Active
checkbox and theIs Starter Active
checkbox.Next, play the game in the editor. You'll be able to navigate to Main Menu > Profile > Stats menu.
Resources
The files used in this tutorial are available in the Unity Byte Wars GitHub repository.
- Assets/Resources/Modules/StatsEssentials/Scripts/UI/StatsProfileMenu_Starter.cs
- Assets/Resources/Modules/StatsEssentials/Prefabs/StatsProfileMenu_Starter.prefab
- Assets/Resources/Modules/StatsEssentials/Scripts/UI/StatsProfileEntry.cs
- Assets/Resources/Modules/StatsEssentials/Prefabs/StatsProfileEntry.prefab