Skip to content

Latest commit

 

History

History
58 lines (48 loc) · 2.06 KB

README.md

File metadata and controls

58 lines (48 loc) · 2.06 KB

unity-library

The integration of the globalstats.io API into a library for unity

This is still a work-in-progress. Please let us know any feedback you have or special use cases you have.

Usage

Simply add the .cs file to your project.

Preparations

First, before using the library in your project, you have to set a few paramters:

GlobalstatsIO.api_id = "Your_API_ID";
GlobalstatsIO.api_secret = "Your_API_Secret";

You can set those anywhere in the code. The values are static and will be kept as long as you game is running.

Submitting Scores

To submit a player score instatiante a object, add the values and call share()

GlobalstatsIO gs = new GlobalstatsIO();

string user_name = "Nickname";

Dictionary<string, string> values = new Dictionary<string, string> ();
values.Add ("score", Score.score.ToString());
values.Add ("shots", Score.shots_fired.ToString());
values.Add ("time", (Score.play_time * 1000).ToString());

if (gs.share ("", user_name, values)) {
    // Success
}
else {
    // An Error occured
}

The share call will store the users name and the ID it received back from globalstst.io. This allows you to send updated to the score by simply doing the same call again with the new values.

You can check if there is a ID stored via this variable

if (GlobalstatsIO.statistic_id != "") {
    // A statistic was already shared, new calls to share() will do an update
}

You can also simply reset it by assigning an empty string to the value.

Linking Scores

Most of the time you want to allow the user to link his scores with his globalstats.io account. In this case you can do this with following lines

GlobalstatsIO gs = new GlobalstatsIO();
gs.linkStatistic ();
Application.OpenURL (GlobalstatsIO.link_data.url);

Of course, this will use the data from the prior share() call for linking.

Feedback

If you encounter any issues you can create a issue here on github. You can also report any issues or questions and suggestions you have to us via email to [email protected] or via the feedback form on our website https://globalstats.io