Sample: Highscores
Note: Highscores display functionality is limited, but can be improved upon request
PlayUR supports storing highscore information between participants. It has various functionality for using players usernames, fake names, etc.
Configuration
You can explore the different functionality provided by the PlayURPlugin.LeaderboardConfiguration
class. This configuration can be re-used across multiple leaderboards (see below when adding an entry to a leaderboard).
PlayURPlugin.LeaderboardConfiguration config;
void Start()
{
config = new PlayURPlugin.LeaderboardConfiguration
{
//descending = false,
title = "Sample Highscores",
//oneEntryPerPlayer = true
//maxItems = 5,
nameDisplayType = PlayURPlugin.LeaderboardConfiguration.NameDisplayType.CustomName,
//forceNameEntryDefaultValue = "Fred"
};
}
Adding Entries to the Leaderboard
You add scores to a leaderboard as defined by a leaderboardID
(in this sample it is test
).
var score = 5;
PlayURPlugin.instance.AddLeaderboardEntryAndShowHighScoreTable("test", score, config, closeCallback:() =>
{
print("done!");
});
You can also use PlayURPlugin.instance.AddLeaderboardEntry
to just add the entry and show the leaderboard later with PlayURPlugin.instance.ShowHighScoreTable
or PlayURPlugin.instance.ShowHighScoreTableFor
. Just be sure to pass through the correct leaderboardID
.
Custom Visuals
You can override the prefabs used to display aspects of the leaderboard on the PlayUR -> Plugin Configuration... -> Prefab Settings -> Highscore Table Prefab. It is recommended to make prefab variants of the prefabs found in PlayUR Plugin Folder / Runtime / Highscores
.
Unity Sample Requirements
You can import this sample from the Unity Package Manager. For the code to run, you will need a game set up in Unity (see Getting Started), and the following configured for the game on the PlayUR Dashboard: