Example usage
The following example highlights how a developer might use the VIVEPORT Stats and Achievements 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 Stats and Achievements API. -
Call
DownloadStats()
to download and cache stat and achievement data locally. -
Do any of the following:
-
Call
GetStat()
to retrieve stats from the cache. Make sure to call the correct version of the function (float
orint
) for the stat. -
Call
GetAchievement()
to retrieve achievement status from cache. -
If applicable, call
GetAchievementUnlockTime()
to get achievement unlock times from cache.
-
Call
-
Do any of the following:
-
Call
SetStat()
to set the value of a stat. Make sure to call the correct version of the function (float
orint
) for the stat. -
Call
SetAchievement()
to unlock an achievement. -
Call
ClearAchievement()
to lock an achievement.
-
Call
-
Make sure to call
UploadStats()
to upload all stats cached in the SDK to the VIVEPORT backend. -
Call
Viveport.Api.Shutdown
to release VIVEPORT SDK resources when no longer needed. In Unity, this is typically either in MonoBehaviorOnDestroy()
or beforeApplication.Quit()
.