- Notifications
You must be signed in to change notification settings - Fork0
Helper that uses the Newgrounds Unity API providing a more Unity workflow enviroment.
License
MonoFlauta/Newgrounds-Unity-API-Helper
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
The Newgrounds Unity API Helper is a wrapper that tries to be more friendly for developers that use mostly Unity when trying to use theNewgrounds API. It also tries to simplify its use by making the request through a single calling method or giving extra performance functionality.
The officialNewgrounds API is included in the project inside the NewgroundsUnityAPIHelper folder under the name ofNewgroundsAPI.It was originally made byJosh Tuttle (a.k.a PsychoGoldfish) and his contribution was crucial for all developers that wanted to use the Newgrounds API in their web games made with Unity.
Even the API is already very useful as it is and you can do everything with it, I personally preferred to always create a wrapper in order to work more comfortably. The main goal of the wrapper is to simplify the use of the API and even add a few performance tricks.Feel free to use it or ask for help if you need it/propose improvements by using theIssues section.
The following list contains all the things you need to fully use the helper.
- In order to start, you will need to have the Package folder inside your project. Once you have it, you will be able to use it's functionality
- Go to the Packages/Helper/Resources/ folder and enter the NewgroundsAPI prefab
- Set the App ID inside the core component with the aes_base 64 key
That's all! Now you will be able to call the methods you need.
In order to unlock a medal, you can call the following anywhere but replacing the 1234 for the medal id:
NewgroundsAPIHelper.Instance.UnlockMedal(1234);
You can also add an action and get the unlock result by adding a callback:
NewgroundsAPIHelper.Instance.UnlockMedal(1234, unlock => { //Do something});
In order to fetch information of medals, you will need, in most of cases, to load medals first. To do so, you can do the following:
NewgroundsAPIHelper.Instance.LoadMedals();
This information will be stored by the NewgroundsAPIHelper in order to be able to respond to other messages. It will also avoid requesting information over and over again avoiding to have unnecesary async calls.Apart from this, you will also be able to get all the medals information in the same call by adding a callback method:
NewgroundsAPIHelper.Instance.LoadMedals(medals => { //Do something});
Note that this method is only optional.
You can ask if a medal is unlocked or not. Unless the medal has been unlocked during the current player session, you will need to call LoadMedals method first and make sure that it has finished by using the callback for example.To know if a medal was unlocked, replace the 1234 for the medal id:
var isMedalUnlocked = NewgroundsAPIHelper.Instance.IsMedalUnlocked(1234);
You can get the whole list of medals. To do so, you will need to call LoadMedals method first and make sure that it has finished by using the callback for example.To get the whole list of medals, call the following method:
var allMedals = NewgroundsAPIHelper.Instance.GetAllMedals();
You can also get filtered lists of medals like all unlocked medals:
var allUnlockedMedals = NewgroundsAPIHelper.Instance.GetAllUnlockedMedals();
and all locked medals:
var allLockedMedals = NewgroundsAPIHelper.Instance.GetAllLockedMedals();
You can get information from a specific medal. Unless the medal has been unlocked during the current player session, you will need to call LoadMedals method first and make sure that it has finished by using the callback for example.To get the information of a medal, replace the 1234 with the medal id and do the following:
var medal = NewgroundsAPIHelper.Instance.GetMedal(1234);
You can post scores to a specific board by doing:
var boardId = 1234;var score = 100;NewgroundsAPIHelper.Instance.PostScore(boardId, score);
If you want, you can also have a callback that let's you know once the score has been posted:
var boardId = 1234;var score = 100;NewgroundsAPIHelper.Instance.PostScore(boardId, score, () =>{ //Do something});
You can get a scoreboard in order to read it's information. In order to do that, you can do the following:
var boardId = 1234;NewgroundsAPIHelper.Instance.GetScoreboard(boardId, scoreboard => { //Do something});
You can also get all the scoreboards if you want by doing:
NewgroundsAPIHelper.Instance.GetScoreboards(scoreboards => { //Do something});
You can get the scores from a scoreboard and filter them by global, personal or social scores.
- Global includes all players who posted to that scoreboard
- Personal includes scores by the player only
- Social includes scores by the player and his friends
In order to do it you need to do:
var boardId = 1234;NewgroundsAPIHelper.Instance.GetGlobalScores(boardId, scores => { //Do something});
And you can add a bunch of optional parameters:
var boardId = 1234;var period = ScoreboardPeriod.CurrentDay;var limit = 10;var skip = 0;string filterTag = null;NewgroundsAPIHelper.Instance.GetGlobalScores(boardId, scores => { //Do something},period, limit, skip, filterTag);
You can log events by calling the following method with the event name:
NewgroundsAPIHelper.Instance.LogEvent("event name");
And you can optionally add a callback event to know if you want when the event has been logged:
NewgroundsAPIHelper.Instance.LogEvent("event name", () => { //Do something});
You can call Ping method and receive the result in a callback:
NewgroundsAPIHelper.Instance.Ping(ping => { //Do something});
You can get the current date time in two formats: string or DateTime. In order to do so, it will depend on the callback you use.
NewgroundsAPIHelper.Instance.GetDateTime(OnGetDateTime);
You can get the client version in two formats: string or Version (custom struct). In order to do so, it will depend on the callback you use.
NewgroundsAPIHelper.Instance.GetVersion(OnGetVersion);
You can load the urls you added on the official urls in the API dashboard by doing:
var openInNewTab = true;NewgroundsAPIHelper.Instance.OpenAuthorUrl(openInNewTab);
And you can add a callback to know when it worked successfully.
var openInNewTab = true;NewgroundsAPIHelper.Instance.OpenAuthorUrl(openInNewTab, url => { //Do something});
You can get the session data by doing:
NewgroundsAPIHelper.Instance.GetSession(session => { //Do something});
You can end a session by doing:
NewgroundsAPIHelper.Instance.EndSession();
And optionally you can add a callback to know once the session was ended:
NewgroundsAPIHelper.Instance.EndSession(() => { //Do something});
You can start a session by doing:
NewgroundsAPIHelper.Instance.StartSession();
And optionally you can add a callback to know once the session was started:
NewgroundsAPIHelper.Instance.StartSession(session => { //Do something});
You can increment the "Total views" stadistics by doing:
NewgroundsAPIHelper.Instance.LogView();
And optionally you can add a callback to know once it was logged:
NewgroundsAPIHelper.Instance.LogView(()=>{ //Do something});
You can get the current date time in two formats: string or DateTime. In order to do so, it will depend on the callback you use.
NewgroundsAPIHelper.Instance.GetLatestVersion(OnGetLatestVersion);
You can get to know if it is a deprecated version by doing:
NewgroundsAPIHelper.Instance.IsDeprecatedVersion(isDeprecated =>{ //Do something});
You can get to know if it is a domain defined in the "Game Protection" settings
NewgroundsAPIHelper.Instance.GetHostLicense(isLicensed =>{ //Do something});
You can know if a user is logged in by doing:
NewgroundsAPIHelper.Instance.IsUserLoggedIn(isLoggedIn => { //Do something});
About
Helper that uses the Newgrounds Unity API providing a more Unity workflow enviroment.
Resources
License
Uh oh!
There was an error while loading.Please reload this page.