# Leaderboard Season

## 1. Điều kiện tiên quyết

* Trong game cần phải tích hợp GSM SDK: [xem hướng dẫn](https://cscmobi-gsm.gitbook.io/gsm-sdk)
* Game đã được nhập dữ liệu  Leaderboard Season ở GSM CMS. Phần này nếu chưa biết, thì liên hệ tuyennv (skype: nguyenvantuyen\_12a9) để được hướng dẫn
* Game đã có FancyScrollView. Nếu chưa có thì tải và import: Download [tại đây](https://gitlab.com/cscmobistudios/gsm-sdk/-/tree/main/Unity/CSCMobiPlugin)

## 2. Download

* Tìm plugin có tên: LeaderboardSeason\_v0.0.0.2.unitypackage
* [Download tại đây](https://gitlab.com/cscmobistudios/gsm-sdk/-/tree/main/Unity/CSCMobiPlugin/LeaderboardSeason)
* Khi import có thể xem sample trong plugin
* Cần sửa lại appId trong GSMObject của LoadingScene, lấy giá trị appId tương ứng với dự án

## 3. Sử dụng

### 3.1 Add Script LeaderboardSeasonManager

* Cần add Script này vào game, nơi sử dụng Leaderboard

<figure><img src="/files/WJqtwlM7rZhuqydcCR32" alt=""><figcaption></figcaption></figure>

### 3.2 Tạo Script LeaderboardSeasonSampleController

* Mục đích để quản lý show leaderboard
* Sử dụng 2 Prefab: **LeaderboardSeasonPanel** và **LeaderboardSeasonFinishPanel**\
  \+ **LeaderboardSeasonPanel :** Là prefab hiển thị leaderboard\
  \+ **LeaderboardSeasonFinishPanel:** Là prefab hiển thị khi kết thúc 1 event leaderboard

Code mẫu:

```csharp
using GSM.Events;
using GSM.LeaderboardSeason;
using UnityEngine;

public class LeaderBoardSeasonSampleController : MonoBehaviour
{
    [SerializeField] private LeaderboardSeasonPanelController leaderboardPrefab;
    [SerializeField] private LeaderboardSeasonFinishPanel leaderboardResultPrefab;
    [SerializeField] private int score = 3370;
    [SerializeField] private string scoreType = "star";
    private void Awake()
    {
        LeaderboardSeasonManager.SetFuncGetPlayerName(() =>
        {
            //Trả về tên của người chơi hiện tại
            //Phía game sẽ thay đổi giá trị này tương ứng với logic của game.
            return "playerName";
        });
        //Nhận sự kiện khi có event được finish
        LeaderboardSeasonManager.OnLoadEventFinishCompleted += OnLoadEventFinishCompleted;
    }
    private void OnLoadEventFinishCompleted(GSMLeaderboadSeason.EventFinishedData[] eventFinishes)
    {
        if (LeaderboardSeasonManager.Instance.HasFinishedEventLeaderBoard)
        {
            var resultPanel = Instantiate(leaderboardResultPrefab);
            resultPanel.SetOnClaimReward((reward) =>
            {
                Debug.Log(reward);
            });
            var eventFinished = eventFinishes[0];
            resultPanel.Show(eventFinished);
        }
    }
    //Hiển thị leaderboard
    public void ShowLeaderboard()
    {
        if (!LeaderboardSeasonManager.Instance.HasEventLeaderBoard) return;
        Instantiate(leaderboardPrefab).GetComponent<LeaderboardSeasonPanelController>().Init(scoreType);
    }
    public void UpdateScore()
    {
        //Gửi điểm
        LeaderboardSeasonManager.Instance.SendScore(score, scoreType);
    }
}

```

* Mỗi leaderboard được phân loại theo scoreType

Ảnh demo:

<figure><img src="/files/2NP9sHxubpNdGsEMpyja" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://cscmobi-gsm.gitbook.io/csc-plugin/leaderboard-season.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
