AT THE MOMENT THE KONG API DOESN'T SEEM TO WORK. YOU MAY AS WELL TRY THE BELOW, BUT IT PROBABLY WONT WORK.
From what I understand, you need to create an object for Kongregate callbacks. I created an object called KongregateObject. Then in this object you place a script.
The first thing I did in my script was set DontDestroyOnLoad(transform.gameObject);
This means that your object will survive through different scenes. Then you only have to put the object in the first scene of your game.
These are the variable declarations I made:
var isKongregate = false;
var userId = 0;
var username = "Guest";
var gameAuthToken = "";
To initialise the Kong API I used the following line of code:
Application.ExternalEval("if(typeof(kongregateUnitySupport) != 'undefined'){kongregateUnitySupport.initAPI('KongregateObject', 'OnKongregateAPILoaded');}");
To use this code you need a callback function. What this does is when the Kong API is successfully loaded it gives you information such as the unique User ID, the UserName and the Game Authentication Token.
This is the example callback function. Put it in the same script.
function OnKongregateAPILoaded(userInfoString){
// We now know we're on Kongregate
isKongregate = true;
// Split the user info up into tokens
var params = userInfoString.Split("|"[0]);
userId = parseInt(params[0]);
username = params[1];
gameAuthToken = params[2];
}
If you want to know if someone has signed in and what their username is, put this code just below the initialisation.
Application.ExternalEval("kongregate.services.addEventListener('login', function(){var services = kongregate.services;var params=[services.getUserId(), services.getUsername(), services.getGameAuthToken()].join('|');kongregateUnitySupport.getUnityObject().SendMessage('KongregateObject', 'OnKongregateUserSignedIn', params);");
And of course your callback function:
// Called when the Kongregate user signs in, parse the tokenized user-info string that we
// generate below using Javascript.
function OnKongregateUserSignedIn(userInfoString){
var params = userInfoString.Split("|"[0]);
userId = parseInt(params[0]);
username = params[1];
gameAuthToken = params[2];
}
So here is the whole script:
var isKongregate = false;
var userId = 0;
var username = "NothingMuch";
var gameAuthToken = "";
// Begin the API loading process if it is available
Application.ExternalEval("if(typeof(kongregateUnitySupport) != 'undefined'){kongregateUnitySupport.initAPI('KongregateObject', 'OnKongregateAPILoaded');}");
// Register a sign in handler to let us know if the user signs in to Kongregate. Notice how we are using the
// Javascript API along with Application.ExternalEval, and then calling back into our app using SendMessage.
// We deliver the new user information as a simple pipe-delimited string, which we can easily parse using String.Split.
Application.ExternalEval("kongregate.services.addEventListener('login', function(){var services = kongregate.services;var params=[services.getUserId(), services.getUsername(), services.getGameAuthToken()].join('|');kongregateUnitySupport.getUnityObject().SendMessage('KongregateObject', 'OnKongregateUserSignedIn', params);");
function Awake () {
DontDestroyOnLoad (transform.gameObject);
username = "Guest";
}
function OnKongregateAPILoaded(userInfoString){
// We now know we're on Kongregate
isKongregate = true;
// Split the user info up into tokens
var params = userInfoString.Split("|"[0]);
userId = parseInt(params[0]);
username = params[1];
gameAuthToken = params[2];
}
// Called when the Kongregate user signs in, parse the tokenized user-info string that we
// generate below using Javascript.
function OnKongregateUserSignedIn(userInfoString){
var params = userInfoString.Split("|"[0]);
userId = parseInt(params[0]);
username = params[1];
gameAuth
Token = params[2];
}
Good Luck!
Hope this works better for you than it did for me. If you get it to work, please tell me what you did.