
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.
Argument | Type | Description |
---|---|---|
boardID | string | The 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.
Argument | Type | Description |
---|---|---|
boardID | string | The 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.
Argument | Type | Description |
---|---|---|
boardID | string | The 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.
Argument | Type | Description |
---|---|---|
boardID | string | The ID that the board should be accessed by, this is CaSe SeNsItIvE. |
Returnsbool
– 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.
Argument | Type | Description |
---|---|---|
boardID | string | The ID that the board should be accessed by, this is CaSe SeNsItIvE. |
RetrunsLeaderboardData
– The 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.
Argument | Type | Description |
---|---|---|
boardID | string | The ID that the board should be accessed by, this is CaSe SeNsItIvE. |
entry | LeaderboardEntry | The entry data to add to the leaderboard. |
Argument | Type | Description |
---|---|---|
boardID | string | The ID that the board should be accessed by, this is CaSe SeNsItIvE. |
name | string | The name to enter into the board entry. |
score | string | The 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.
Argument | Type | Description |
---|---|---|
boardID | string | The ID that the board should be accessed by, this is CaSe SeNsItIvE. |
entry | LeaderboardEntry | The entry data to add to the leaderboard. |
Argument | Type | Description |
---|---|---|
boardID | string | The ID that the board should be accessed by, this is CaSe SeNsItIvE. |
name | string | The name to enter into the board entry. |
score | string | The 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.
Argument | Type | Description |
---|---|---|
name | string | The name of the entry to add. |
score | string | The score of the entry to add. |
Argument | Type | Description |
---|---|---|
entry | LeaderboardEntry | The 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.
Argument | Type | Description |
---|---|---|
name | string | The name of the entry to add. |
score | string | The score of the entry to add. |
Argument | Type | Description |
---|---|---|
entry | LeaderboardEntry | The 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.
Argument | Type | Description |
---|---|---|
id | string | The entry id of the entry to get. |
Argument | Type | Description |
---|---|---|
name | string | The name of the entry to get. |
score | string | The score of the entry to get. |
Argument | Type | Description |
---|---|---|
entry | LeaderboardEntry | The entry data to add to the board. |
ReturnsLeaderboardEntry
– 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
– The top 3 entries in the board in ascending order.LeaderboardEntry[]
Example Usage
LeaderboardData data;
var _top3Ascending = data.GetTop3Ascending;
GetTopXAscending()
Gets the top x number entries in the board with the lowest score.
Argument | Type | Description |
---|---|---|
x | int | The amount of entries to get. |
Returns
– The top x number entries in the board in ascending order.LeaderboardEntry[]
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
– All the entries in the board in ascending order.LeaderboardEntry[]
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.
Argument | Type | Description |
---|---|---|
entry | LeaderboardEntry | The entry to search for. |
Argument | Type | Description |
---|---|---|
name | string | The name the search for. |
score | string | The score the search for. |
Returns
– The position of the entry.int
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
– The top 3 entries in the board in descending order.LeaderboardEntry[]
Example Usage
LeaderboardData data;
var _top3Decending = data.GetTop3Decending;
GetTopXDescending()
Gets the top x number entries in the board with the highest score.
Argument | Type | Description |
---|---|---|
x | int | The amount of entries to get. |
Returns
– The top x number entries in the board in descending order.LeaderboardEntry[]
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
– All the entries in the board in descending order.LeaderboardEntry[]
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.
Argument | Type | Description |
---|---|---|
entry | LeaderboardEntry | The entry to search for. |
Argument | Type | Description |
---|---|---|
name | string | The name the search for. |
score | string | The score the search for. |
Returnsint
– 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.
Returnsdouble
– A id for the entry.
Example Usage
LeaderboardEntry entry;
Debug.Log(entry.EntryID);
Name
The name for the entry to the board.
Returnsstring
– 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
– A score of the person this entry is for.double
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.
Argument | Type | Description |
---|---|---|
score | double | The score to convert. |
Returns
– The timespan the score is equal to when converted to seconds.TimeSpan
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.
Returnsstring
– 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.
ReturnsDisplayOption
– 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.
Returnsint
– 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.