統計データプロファイルメニュー UI - 統計データを追跡し表示する - (Unity モジュール)
What's on the menu
In this tutorial, you will learn how to prepare the user interface (UI) to display statistic (stat) values. Later, this menu will display the highest score stat stored in the AccelByte Gaming Services (AGS) Admin Portal.
The Stats Profile Menu UI has been created for you, but it still needs some additional code before you can connect it with the AccelByte Gaming Services (AGS) Game SDK. These files are available in the Resources section and consist of the following files:
- StatsHandler_Starter.cs: a C# script that contains most of the stats implementation.
- CS file:
/Assets/Resources/Modules/StatsEssentials/Scripts/UI/StatsHandler_Starter.cs
- CS file:
- StatsProfileMenuCanvas_Starter.prefab: A GameObject prefab that was created from a Canvas Panel UI GameObject.
- Prefab file:
/Assets/Resources/Modules/StatsEssentials/Prefabs/StatsProfileMenuCanvas_Starter.prefab
- Prefab file:
The Stats Profile Menu only has a default state. This menu is only accessible from the Profile Menu and its menu button is already exposed in the Main Menu. See below for a more detailed explanation of the prepared UI.
Stats Profile Menu
The Stats Profile Menu will display player stats based on the query result from the AGS Statistics service. It contains Stats Items Texts, Stats Items Value Texts, and a Back Button that uses TextMeshPro for the Text UI.
The following code is the declaration for the UI references in StatsHandler_Starter.cs
:
[SerializeField] private TMP_Text singlePlayerStatValueText;
[SerializeField] private TMP_Text eliminationStatValueText;
[SerializeField] private TMP_Text teamDeathmatchStatValueText;
[SerializeField] private Button backButton;
The function named OnBackButtonClicked()
will listen to the backButton
variable's onClick
event and redirect the player to the previous menu with MenuManager
. The following sets the listener for onClick
event inside the Start()
function:
void Start()
{
backButton.onClick.AddListener(OnBackButtonClicked);
}
private void OnBackButtonClicked()
{
MenuManager.Instance.OnBackPressed();
}
Here's the preview of the Stats Profile Menu:
Ready the UI
Here in this section, you will prepare the UI for the AGS Game SDK Statistics integration.
Open Byte Wars in Unity.
Open
StatsHandler_Starter.cs
.Inside the
Start()
function, addOnBackButtonClicked()
to listen to the back button'sonClick
event. Also, set the statistics value texts to the default value0
.void Start()
{
backButton.onClick.AddListener(OnBackButtonClicked);
singlePlayerStatValueText.text = "0";
eliminationStatValueText.text = "0";
teamDeathmatchStatValueText.text = "0";
}Back in the Unity Editor, from the Project window, open the
Assets/Resources/Modules/StatsEssentials/StatsEssentialsAssetConfig.asset
and enableIs Starter Active
to be able to use your starter setup.
Resources
- GitHub Link to the files in the Unity Byte Wars repository: