zeh 238f7cf1ab First commit of the very basic Newgrounds API | 10 роки тому | |
---|---|---|
.. | ||
data | 10 роки тому | |
services | 10 роки тому | |
API.cs | 10 роки тому | |
GameObjectSurrogate.cs | 10 роки тому | |
README.md | 10 роки тому |
An initial implementation of the Newgrounds RESTful API in C# for Unity with no JavaScript bridges. It tries to mimic the syntax of the AS3 version of the API, although only a handful of methods are available.
This is currently used in my Escape Drill game for Ludum Dare #29, but missing a lot of features.
newgrounds
folder to your Unity project's "Scripts" folderMain
game class), connect to the API:
Newgrounds.API.Connect(apiId, encryptionKey);
Newgrounds.API.PostScore(name, value);For example:
Newgrounds.API.PostScore("High Score (level 1)", 1000); Newgrounds.API.PostScore("Tanks Destroyed", 10);
Newgrounds.API.Connect(string apiId, string encriptionKey)
(Static): Connects to the API. You need to do this before anything is posted. You can find the API id and encryption key values in the API Tools section of your project.Newgrounds.API.PostScore(string name, int value)
(Static): submit a score to the Newgrounds API. The name
is not an id, but rather how the score is represented in the website.connectionUserName
: current user name. Read-only.connectionUserId
: id of the current user. Read-only.connectionSessionId
: a long hash with the id of the current session. Read-only.The API will not work inside the editor by default. This is because it needs some kind of session ID that is passed by the website when the game is ran. However, the API does detect when you're running inside the editor and attempt to use a placeholder URL. To replace this placeholder URL with a real URL, go to your game's page, find the URL of the iframe used to host it, and replace the setContainerURLStatic()
call in line 45 of API.cs with this url. It will look like this:
http://uploads.ungrounded.net/alternate/999999/999999_alternate_9999.zip/?NewgroundsAPI_PublisherID=9&NewgroundsAPI_SandboxID=Abc999&NewgroundsAPI_SessionID=Abc999&NewgroundsAPI_UserName=john&NewgroundsAPI_UserID=999999&ng_username=john