No description, website, or topics provided.
Clone or download
Latest commit 303e664 Jun 5, 2015


If you are developing a web build of your unity game for Spilgames, then you can use this plugin to help you interact with the Spilgames web portal API.

You can download the plugin here: Download

Or you can directly download this repo.


Here is an example of a Unity web player game working with the spil API plugin: Example

This example is also included in the unity plugin so that you can see how it's put together.

Basic Setup

  1. Download the Unity Package and import it to your project.
  2. Add the SpilGamesAPI prefab to the very first scene your game loads.
  3. Either in the script directly, or in the prefab inspector, add your Spilgames Game ID.
  4. Add the code that pauses/unpauses your game to the following methods.
    pauseGame () { //your pause stuff }
    resumeGame () { //your resume stuff }
    These methods will be called before and after showing external content in your game.
  5. Call the ShowSpilMoreGames() and GameBreak() methods in your game in the places agreed on with your publishing lead.
  6. Set the position of the portal logo. In the example, I have created a button that displays the returned portal logo. brandingButtonImage. Then when that button is clicked, it calls BrandingLogoClicked();. Feel free to do this another way if you don't want to use this method.
  7. Ask your spil contact whether it is necessary to include a game lock feature in your game. If so, then add some code to lock the game to the OnSiteLock method. An example would be a UI panel that appears over the game blocking input.

Now test your game in the test tool. You should be able to trigger all green ticks on the right of the page.


Social Features

If your game is configured to use social features, then you can use the following methods to retrieve data regarding the user.


This Method will activate a Login popup on the portal, forcing the user to login.

public void ForceAuthentication(){ Application.ExternalEval ( "GameAPI.User.forceAuthentication();" ); }


This method will get a JSON string of info about the user. The data is passed to the method SetUpUser(); You can do whatever you need to with the data in that method.
public void GetUser(){ Application.ExternalEval ( "GameAPI.User.getUser(function (userData){if(typeof u !== 'undefined' && u.getUnity && typeof u.getUnity === 'function'){u.getUnity().SendMessage('SpilGamesAPI', 'SetUpUser', JSON.stringify(userData));}});" ); }

This method will get a JSON string of the logged in users friends. The data is passed to the method SetUpFriends(); You can do whatever you need to with the data in that method.

public void GetFriends(){ Application.ExternalEval ( "GameAPI.Friends.getFriends(function (friendsData){if(typeof u !== 'undefined' && u.getUnity && typeof u.getUnity === 'function'){u.getUnity().SendMessage('SpilGamesAPI', 'SetUpFriends', JSON.stringify(friendsData));}});" ); }
You can also send a score or achievements (awards) to the portal if the portal is configured to receive it using the ScoreSubmit and AwardSubmit methods.

Recent Changes
V 0.0.8: Now works with Unity WebGL Export.