Example usage
The following example highlights how a developer might use the VIVEPORT Leaderboards API in their title.
Make sure you have a VIVEPORT ID and Key for your title before trying to implement any of the API functions.
-
Call the Top Level API using
Viveport.Api.Init
to initialize the VIVEPORT SDK. For Unity developers, this is typically called as MonobehaviorStart()
. -
Call
Viveport.UserStats.IsReady()
to initialize the VIVEPORT Leaderboards API. -
Call
Viveport.Leaderboard.DownloadLeaderBoardScores()
to download scores. -
Do any of the following:
-
Call
Viveport.Leadboard.GetCount()
to check the number of leaderboard scores, which can be used to determine index values forGetLeaderboardScore()
. -
Call
GetLeaderboardSortMethod()
to get the sorting method used for the leaderboard score order. This can be used to organize the information for local display. -
Call
GetLeaderboardDisplayType()
to determine what kind of data the leaderboard stores. SeeLeaderBoardDisplayType()
for a complete list.
-
Call
-
Call
GetLeaderboardScore()
using the correct index to retrieve scores. - Show leaderboards to the end user.
-
If there are new score to upload, call
UpLoadLeaderboardScore()
to upload them to the VIVEPORT backend.
Keep in mind that changes will be handled based on the leaderboard configuration in the VIVEPORT Developer Console , such as whether the scores are aggregated or replaced. -
Call
Viveport.Api.Shutdown
to release VIVEPORT SDK resources when no longer needed. In Unity, this is typically either in MonoBehaviorOnDestroy()
or beforeApplication.Quit()
.