Leaderboard Manager Scripting Reference

Scripting

Namespace

All code for this asset is under the following namespace(s):

// General Code
CarterGames.Assets.LeaderboardManager
// Editor Code (Custom Inspectors)
CarterGames.Assets.LeaderboardManager.Editor
// Example Code (Example Scene Only)
CarterGames.Assets.LeaderboardManager.Demo

To access code from the asset you will need to be using the asset namespace in your script or use the full path of the asset script in order to access it.

Example Usage

// Using statement 
using CarterGames.Assets.LeaderboardManager;
LeaderboardManager.CreateLeaderboard("Example");
// Full path usage
CarterGames.Assets.LeaderboardManager.LeaderboardManager.CreateLeaderboard("Example");
Scripting

Classes

All methods in class are static and can be accessed by using class name before the method without needing a reference to an instance of the script.

// Example of usage... replacing "MyMethodHere" with the method you want to call.
LeaderboardManager.MyMethodHere
Leaderboard Manager

Methods

CreateLeaderboard()

Creates a new leaderboard with the id entered and adds it to the leaderboard file for use in your project.

ArgumentTypeDescription
boardIDstringThe ID that the board should be accessed by, this is CaSe SeNsItIvE.

Example Usage

LeaderboardManager.CreateLeaderboard("Level1");
DeleteLeaderboard()

Deletes the leaderboard of the id entered. This is an instant action and cannot be undone when called.

ArgumentTypeDescription
boardIDstringThe ID that the board should be accessed by, this is CaSe SeNsItIvE.

Example Usage

LeaderboardManager.DeleteLeaderboard("Level1");
ClearLeaderboard()

Clears the leaderboard of the id entered of all entries. This is an instant action and cannot be undone when called.

ArgumentTypeDescription
boardIDstringThe ID that the board should be accessed by, this is CaSe SeNsItIvE.

Example Usage

LeaderboardManager.ClearLeaderboard("Level1");
BoardExists()

Gets whether or not a board of the id entered exists in the system.

ArgumentTypeDescription
boardIDstringThe ID that the board should be accessed by, this is CaSe SeNsItIvE.

Returns
bool – Does the board exists, true if it does, false if not.

Example Usage

// If Statement
if (LeaderboardManager.BoardExists("Level1"))
{
    // Do Stuff here
}
// Variable
var _hasBoard = LeaderboardManager.BoardExists("Level1");
GetLeaderboard()

Gets the data for the leaderboard of the id entered.

ArgumentTypeDescription
boardIDstringThe ID that the board should be accessed by, this is CaSe SeNsItIvE.

Retruns
LeaderboardDataThe data on the leaderboard requested or null if no data was found.

Example Usage

LeaderboardManager.GetLeaderboard("Level1");
AddEntryToBoard()

Adds an entry of the values defined to the board of the defined id. There are 2 versions of this method.

ArgumentTypeDescription
boardIDstringThe ID that the board should be accessed by, this is CaSe SeNsItIvE.
entryLeaderboardEntryThe entry data to add to the leaderboard.
ArgumentTypeDescription
boardIDstringThe ID that the board should be accessed by, this is CaSe SeNsItIvE.
namestringThe name to enter into the board entry.
scorestringThe score to enter into the board entry.

Example Usage

// LeaderboardEntry version...
LeaderboardManager.AddEntryToBoard("Level1", new LeaderboardEntry("John", 100));
// Standard version...
LeaderboardManager.AddEntryToBoard("Level1", "John", 100);
DeleteEntryFromBoard()

Removes an entry of the values defined from the board of the defined id. There are 2 versions of this method.

ArgumentTypeDescription
boardIDstringThe ID that the board should be accessed by, this is CaSe SeNsItIvE.
entryLeaderboardEntryThe entry data to add to the leaderboard.
ArgumentTypeDescription
boardIDstringThe ID that the board should be accessed by, this is CaSe SeNsItIvE.
namestringThe name to enter into the board entry.
scorestringThe score to enter into the board entry.

Example Usage

// LeaderboardEntry version...
LeaderboardManager.DeleteEntryFromBoard("Level1", new LeaderboardEntry("John", 100));
// Standard version...
LeaderboardManager.DeleteEntryFromBoard("Level1", "John", 100);
Save()

Updates the save file for the leaderboard data with the latest data in the system when called.

Example Usage

LeaderboardManager.Save();
Load()

Updates the system with the latest data from the save file for the leaderboard data when called.

Example Usage

LeaderboardManager.Load();

The leaderboard data class holds all the data for 1 leaderboard in the system. It has a variety of methods and properties to get information from the leaderboard to use in your projects.

Leaderboard Data Store

Constructors

The data script just has a blank constructor that sets up the leaderboards list to not be null.

// Blank Constructor for the data class...
public LeaderboardDataStore()

Example Usage

// Using blank constructor
var _board = new LeaderboardDataStore();
Leaderboard Data Store

Properties

Leaderboards

Gets/sets the leaderboards in the store.

Returns

List<LeaderboardData> – A list of all the leaderboards in the data store.

Example Usage

LeaderboardDataStore dataStore;
var _exampleBoard = dataStore.Leaderboards.FirstOrDefault(t => t.BoardID.Equals("Example"));

The leaderboard data class holds all the data for 1 leaderboard in the system. It has a variety of methods and properties to get information from the leaderboard to use in your projects.

Leaderboard Data

Constructors

The data script has the option to use a constructor to setup the board ID on creation as well as a blank one.

// Blank Constructor for the data class...
public LeaderboardData()
// Constructor that sets up the board ID when created...
public LeaderboardData(string id)

Example Usage

// Using blank constructor
var _board = new LeaderboardData();
// Using setup constructor
var _board = new LeaderboardData("Level1");
Leaderboard Data

Properties

BoardID

Gets/sets the board ID defined for this leaderboard.

Returns

string - The ID of the board.

Example Usage

LeaderboardData data;
Debug.Log(data.BoardID);
BoardData

Gets/sets the board data for this leaderboard.

Returns

List<LeaderboardEntry> – All the entries in the leaderboard as LeaderboardEntry data.

Example Usage

LeaderboardData data;
Debug.Log(data.BoardData.Count);
Leaderboard Data

Methods

AddEntry()

Adds an entry to the board. There are 2 versions of this method.

ArgumentTypeDescription
namestringThe name of the entry to add.
scorestringThe score of the entry to add.
ArgumentTypeDescription
entryLeaderboardEntryThe entry data to add to the board.

Example Usage

LeaderboardData data;
// Using name and score
data.AddEntry("John", 100);
// Using entry data
data.AddEntry(new LeaderboardEntry("John", 100));
DeleteEntry()

Removes an entry to the board. There are 2 versions of this method.

ArgumentTypeDescription
namestringThe name of the entry to add.
scorestringThe score of the entry to add.
ArgumentTypeDescription
entryLeaderboardEntryThe entry data to add to the board.

Example Usage

LeaderboardData data;
// Using name and score
data.DeleteEntry("John", 100);
// Using entry data
data.DeleteEntry(new LeaderboardEntry("John", 100));
ClearBoard()

⚠️ Note this action cannot be undone once called.

Clears the leaderboard of all data.

Example Usage

LeaderboardData data;
data.ClearBoard();
GetEntry()

Gets the entry at the entry ID entered. This method has several overloads, arguments for each are displayed below.

ArgumentTypeDescription
idstringThe entry id of the entry to get.
ArgumentTypeDescription
namestringThe name of the entry to get.
scorestringThe score of the entry to get.
ArgumentTypeDescription
entryLeaderboardEntryThe entry data to add to the board.

Returns
LeaderboardEntry – The leaderboard entry found in the board or null is no matching entries were found.

Example Usage

LeaderboardData data;
LeaderboardEntry entry;
// Using entry ID
entry = data.GetEntry(1);
// Using name and score
entry = data.GetEntry("John", 100);
// Using entry data
entry = data.GetEntry(new LeaderboardEntry("John", 100));
GetTop3Ascending()

Gets the top 3 entries in the board with the lowest score.

Returns
LeaderboardEntry[] – The top 3 entries in the board in ascending order.

Example Usage

LeaderboardData data;
var _top3Ascending = data.GetTop3Ascending;
GetTopXAscending()

Gets the top x number entries in the board with the lowest score.

ArgumentTypeDescription
xintThe amount of entries to get.

Returns
LeaderboardEntry[] – The top x number entries in the board in ascending order.

Example Usage

LeaderboardData data;
// Gets the top 5 entries ascending...
var _topXAscending = data.GetTopXAscending(5);
GetAllAscending()

Gets all entries in the board in ascending order.

Returns
LeaderboardEntry[] – All the entries in the board in ascending order.

Example Usage

LeaderboardData data;
var _allAscending = data.GetAllAscending;
GetPositionAscending()

Gets the position of the entered entry in the leaderboard from an ascending score perspective. There are two versions of this method.

ArgumentTypeDescription
entryLeaderboardEntryThe entry to search for.
ArgumentTypeDescription
namestringThe name the search for.
scorestringThe score the search for.

Returns
int – The position of the entry.

Example Usage

LeaderboardData data;
LeaderboardEntry entry;
// Using LeaderboardEntry...
var _positionAscending = data.GetPositionAscending(entry);
// Using Name & Score Values...
var _positionAscending = data.GetPositionAscending("John", 100);
GetTop3Descending()

Gets the top 3 entries in the board with the highest score.

Returns
LeaderboardEntry[] – The top 3 entries in the board in descending order.

Example Usage

LeaderboardData data;
var _top3Decending = data.GetTop3Decending;
GetTopXDescending()

Gets the top x number entries in the board with the highest score.

ArgumentTypeDescription
xintThe amount of entries to get.

Returns
LeaderboardEntry[] – The top x number entries in the board in descending order.

Example Usage

LeaderboardData data;
// Gets the top 5 entries descending...
var _topXDecending = data.GetTopXDescending(5);
GetAllAscending()

Gets all entries in the board in descending order.

Returns
LeaderboardEntry[] – All the entries in the board in descending order.

Example Usage

LeaderboardData data;
var _allDescending = data.GetAllDescending;
GetPositionDescending()

Gets the position of the entered entry in the leaderboard from an descending score perspective. There are two versions of this method.

ArgumentTypeDescription
entryLeaderboardEntryThe entry to search for.
ArgumentTypeDescription
namestringThe name the search for.
scorestringThe score the search for.

Returns
int – The position of the entry.

Example Usage

LeaderboardData data;
LeaderboardEntry entry;
// Using LeaderboardEntry...
var _positionDescending = data.GetPositionDescending(entry);
// Using Name & Score Values...
var _positionDescending = data.GetPositionDescending("John", 100);

The leaderboard data class holds all the data for 1 leaderboard in the system. It has a variety of methods and properties to get information from the leaderboard to use in your projects.

Leaderboard Entry

Constructors

The data script has 2 constructors, a blank constructor that does nothing other than making a new instance of the class & a setup constructor that takes in a name and score.

// Blank Constructor for the data class...
public LeaderboardEntry()
// Setup Constructor
public LeaderboardEntry(string name, double score)

Example Usage

// Using blank constructor
var _entry = new LeaderboardEntry();
// Using setup constructor
var _entry = new LeaderboardEntry("John", 100);
Leaderboard Entry

Properties

EntryID

The entry number for this entry, not the position, but the order of when it was added.

Returns
double – A id for the entry.

Example Usage

LeaderboardEntry entry;
Debug.Log(entry.EntryID);
Name

The name for the entry to the board.

Returns
string – The name of the person this entry is for.

Example Usage

LeaderboardEntry entry;
Debug.Log(entry.Name);
Score

The entry number for this entry, not the position, but the order of when it was added.

Returns
double – A score of the person this entry is for.

Example Usage

LeaderboardEntry entry;
Debug.Log(entry.Score);
Leaderboard Entry

Methods

ConvertScoreToTime()

Converts the score value to a timespan going from seconds. You can use the same code in this method to make your own for milliseconds, minutes etc.

ArgumentTypeDescription
scoredoubleThe score to convert.

Returns
TimeSpan – The timespan the score is equal to when converted to seconds.

Example Usage

LeaderboardEntry entry;
Debug.Log(entry.ConvertScoreToTime(entry.score));

The leaderboard display class is a pre-built display system for a leaderboard. You can display a leaderboard without touching the code in the script at all. However here you’ll find the public options you can edit via code should you wish.

If you are looking for information on the inspector for this script, please refer to the breakdowns section of the documentation page.

Leaderboard Display

Properties

BoardID

The board id of the leaderboard to display. This is a property with a get and set that are public.

Returns
string – A id of the board that is being displayed.

Example Usage

LeaderboardDisplay display;
// Getter
var _id = display.BoardID;
// Setter
display.BoardID = "Example";
DisplayOption

The display option for the leaderboard display to use. This is a property with a get and set that are public.

Returns
DisplayOption – A display option that is currently in use.

Example Usage

LeaderboardDisplay display;
// Getter
var _option = display.DisplayOption;
// Setter
display.DisplayOption = DisplayOption.AsWritten;
EntriesToShow

The display option for the leaderboard display to use. This is a property with a get and set that are public.

Returns
int – The amount of entries to show.

Example Usage

LeaderboardDisplay display;
// Getter
var _entries = display.EntriesToShow;
// Setter
display.EntriesToShow = 5;
UpdateDisplay

Updates the display to show the latest entries using the settings defined in the script.

Example Usage

LeaderboardDisplay display;
display.UpdateDisplay();
ClearDisplay

Clears the display visuals of entries.

Example Usage

LeaderboardDisplay display;
display.ClearDisplay();

The leaderboard option enum holds all the display options for leaderboard display script.

💡 Note: that there will only work with the display script we provide. You will have to implement your own usage

Display Option

Enum

Unassigned

The none/null option for the display enum. This will not display the leaderboard if using the leaderboard display provided with the asset.

AsWritten

Display the leaderboard in the order it is written in the data. This is essentially unordered, but great if you want to show the latest entries in the board.

Ascending

Display the leaderboard in ascending order based on the score of each entry.

Descending

Display the leaderboard in descending order based on the score of each entry.

Top3Ascending

Displays the leaderboard in ascending order based on the score of each entry, but only shows the first 3 entries.

Top3Descending

Displays the leaderboard in descending order based on the score of each entry, but only shows the first 3 entries.

TopXAscending

Displays the leaderboard in ascending order based on the score of each entry, but only shows the amount of entries setup in the EntriesToShow value on the display script.

TopXDescending

Displays the leaderboard in descending order based on the score of each entry, but only shows the amount of entries setup in the EntriesToShow value on the display script.

The leaderboard time format enum holds all the display options for leaderboard display script to format the score value as a time value instead. This only take effect if the format as time bool is true.

💡 Note: that there will only work with the display script we provide. You will have to implement your own usage

Display Time Format

Enum

All examples below use the following values in their score values:

123
456
12345

Unassigned

The none/null option for the display enum. This will not display the leaderboard score values as their raw values with no formatting.


MillisecondsOnly

Display the leaderboard score as if the score value is in milliseconds only.

Example

123
456
345

SecondsOnly

Display the leaderboard score as if the score value is in seconds only.

Example

03
36
45

SecondsMilliseconds

Display the leaderboard score as if the score value is in seconds followed by milliseconds.

Example

00:123
00:456
12:345

MinutesOnly

Display the leaderboard score as if the score value is in minutes only.

Example

02
07
25

MinutesSeconds

Display the leaderboard score as if the score value is in minutes followed by seconds.

Example

02:03
07:36
25:45

MinutesSecondsMilliseconds

Display the leaderboard score as if the score value is in minutes followed by seconds and milliseconds.

Example

00:00:123
00:00:456
00:12:345

HoursOnly

Display the leaderboard score as if the score value is in hours only.

Example

00
00
03

HoursMinutes

Display the leaderboard score as if the score value is in hours followed by minutes.

Example

00:02
00:07
03:25

HoursMinutesSeconds

Display the leaderboard score as if the score value is in hours followed by minutes and seconds.

Example

00:02:03
00:07:36
03:25:45

HoursMinutesSecondsMilliseconds

Display the leaderboard score as if the score value is in hours followed by minutes, seconds & milliseconds.

Example

00:00:00:123
00:00:00:456
00:00:12:345

This is an exact copy of the leaderboard display script but with text mesh pro instead of the unity text component. Please refer to the leaderboard display script section for scripting reference.

The example manager is the script that runs the example scene and nothing else. You don’t need it for the asset but you can use it as a guide to help you should you need it.

Example Manager

Methods

AddToBoard()

Calls the leaderboard manager to add an entry to the board. It uses the text fields in the example scene to get the fields to add.

RemoveFromBoard()

Calls the leaderboard manager to remove an entry to the board. It uses the text fields in the example scene to get the fields to remove.

ClearBoard()

Calls the leaderboard manager to clear the leaderboard data.