Skip to main content

Leaderboards menu overview - Weekly leaderboard - (Unity module)

Last updated on November 25, 2024

What's on the menu

In this tutorial, you will learn about the components available in Byte Wars for periodic leaderboards. Since a periodic leaderboard is part of the AccelByte Gaming Services (AGS) Leaderboard service, you will reuse all the Leaderboard Menu user interface (UI) from All time leaderboard.

As a reminder, these prepared files are available in the Resources section and consist of the following:

  • LeaderboardSelectionMenuCanvas_Starter: A UI menu that displays all available leaderboard lists.
    • CS file: /Assets/Resources/Modules/LeaderboardEssentials/Scripts/UI/LeaderboardSelectionMenu_Starter.cs
    • Prefab file: /Assets/Resources/Modules/LeaderboardEssentials/Prefabs/LeaderboardSelectionMenuCanvas_Starter.prefab
  • LeaderboardCycleMenuCanvas_Starter: A UI menu that displays all available leaderboard period options.
    • CS file: /Assets/Resources/Modules/LeaderboardEssentials/Scripts/UI/LeaderboardCycleMenu_Starter.cs
    • Prefab file: /Assets/Resources/Modules/LeaderboardEssentials/Prefabs/LeaderboardCycleMenuCanvas_Starter.prefab
  • LeaderboardMenuCanvas_Starter: A UI menu that displays the ranking list of the chosen leaderboard.
    • CS file: /Assets/Resources/Modules/LeaderboardEssentials/Scripts/UI/LeaderboardMenu_Starter.cs
    • Prefab file: /Assets/Resources/Modules/LeaderboardEssentials/Prefabs/LeaderboardMenuCanvas_Starter.prefab
  • RankingEntryPanel: A UI component to hold the ranking information.
    • CS file: /Assets/Resources/Modules/LeaderboardEssentials/Scripts/UI/Components/RankingEntryPanel.cs
    • Prefab file: /Assets/Resources/Modules/LeaderboardEssentials/Prefabs/Components/RankingEntryPanel.prefab
  • LeaderboardItemButton: A UI component that is used for the leaderboard options button.
    • Prefab file: /Assets/Resources/Modules/LeaderboardEssentials/Prefabs/Components/LeaderboardItemButton.prefab

Ready the UI

There are some changes needed for adding all Periodic Leaderboard UI, so you will need to add some functionalities in your starter scripts that handle the Leaderboard Cycle Menu and Leaderboard Menu UI.

Add event delegate in Leaderboard Cycle menu

  1. Open LeaderboardCycleMenu_Starter.cs.

  2. Add the Weekly value in the LeaderboardCycleType enum, so you can know which period type you are using since both use a different button.

    public enum LeaderboardCycleType
    {
    AllTime,
    Weekly
    }
  3. Create a delegate and an event that will be invoked when the Leaderboard Cycle Menu is opened. You will use these to generate the Period button later.

    public delegate void LeaderboardCycleMenuDelegate(
    LeaderboardCycleMenu_Starter leaderboardCycleMenu,
    Transform leaderboardListPanel,
    GameObject leaderboardItemButtonPrefab);

    public static event LeaderboardCycleMenuDelegate onLeaderboardCycleMenuActivated = delegate { };
    private void OnEnable()
    {
    ...
    if (ApiClientHelper.IsPlayerLoggedIn)
    {
    onLeaderboardCycleMenuActivated.Invoke(this, leaderboardListPanel, leaderboardItemButtonPrefab);
    }
    }

Add event delegates in Leaderboard menu

  1. Open LeaderboardMenu_Starter.cs.

  2. Create a delegate and an event that you will use later to query and display the periodic leaderboard ranking list.

    public delegate void LeaderboardMenuDelegate(LeaderboardMenu_Starter leaderboardMenu,
    UserCycleRanking[] userCycleRankings = null);

    public static event LeaderboardMenuDelegate onDisplayRankingListEvent = delegate { };
  3. Modify the DisplayRankingList() function to invoke the onDisplayRankingListEvent event.

    private void DisplayRankingList()
    {
    ...
    onDisplayRankingListEvent.Invoke(this);
    }

Enable starter mode

  1. In the Unity Editor, open the PeriodicLeaderboardEssentialsAssetConfig in the Inspector. You can find this file in Assets/Resources/Modules/PeriodicLeaderboard/PeriodicLeaderboardEssentialsAssetConfig.asset.

  2. In the Inspector, below the Tutorial Module Starter category, make sure the Is Starter Active is ticked.

    Unity Inspector with the Periodic Leaderboard Essentials Asset Config file checking is Starter Active Unity Byte Wars weekly leaderboard

note

At this point, if you try to play the game, you will not see the periodic leaderboard button in the leaderboard cycle selection menu yet. This is expected and will be resolved later in this module.

Resources