SCILLManager

class SCILLManager : MonoBehaviour

Overview

This class is designed as a “Singleton” and uses DontDestroyOnLoad to make sure, that the class instance persists even after scene changes. It provides access to the SCILL SDK APIs and provides some convenience functions to make it easier to work with SCILL from your own code.

Create an empty GameObject in your Scene and add this script. Then set your API key, AppId and the language. If your app supports multiple languages, you can use the SetLanguage method to set the language via Script.

You can also choose an environment: You should leave that in Production. Sometimes, when working closely with our development team we might ask you to choose a different value but usually Production is the correct setting.

Production:

In production, you should not use this class by providing your API key! Instead you should override this class and override these functions:

  • GenerateAccessToken
  • GetUserId

More info on this topic can be found here: User IDs and Access Tokens. To summarize this topic: API keys are very powerful and therefore should be kept secret. Exposing things on client side aren’t secret, as everyone with a Debugger will be able to extract the API key very quickly from your code. The only way to keep the API key secret is to use it on server side - which can be a cloud function (AWS Lambda, Google Cloud Function, …) or your own HTTP server. Recommended procedure is to create that cloud function for example in NodeJS and to use the SCILL JavaScript SDK to generate the access token for the user.

Your own Subclass of SCILLManager will then override the functions listed above to load the access token from your backend, instead of generating it on client side with the API key as we do in the default implementation of this class.

Inspector Properties

AppId

This is the App id which you can find in the Admin Panel for your app.

public string AppId;

Environment

Leave in Production if you did not hear anything else from our development team.

public string Environment;

Language

Default language setting. You can use the SetLanguage method to change the language in runtime.

public SupportedLanguages Language;

APIKey

Set your API-Key in the inspector. This is for testing purposes. In production, you should implement a simple backend function to generate an access token for your user id.

public string APIKey;

UserId

Set a User ID which is used for testing. In your game you will need to set a persistent user id that will reliably identify the user over time. If you are building a Steam game this could be the Steam-ID for example.

public string UserId;

SessionId

Set a User ID which is used for testing. In your game you will need to set a persistent user id that will reliably identify the user over time. If you are building a Steam game this could be the Steam-ID for example.

public string UserId;

Properties

Instance

As this class is designed as a singleton you can use this getter to get a reference to the instance. It allows you to access the SCILLManager from everywhere in your code.

public static SCILLManager Instance { get; private set; }

Methods

GenerateAccessToken

public virtual string GenerateAccessToken(string userId)

This class uses the SCILLBackend class to call the GenerateAccessToken function to directly call SCILL backend with the API key provided in the inspector. This is not recommend in production and you should override this function to call a backend function you control to hide the API key from the user.

Parameters

userId string

The userId for which the access token should be generated.

Returns

Returns the access token as a string which is stored and reused for all further requests to the SCILL backend.

GetUserId

public virtual string GetUserId()

This class just returns the user id provided in the inspector. This is good to quickly test with one persistent user that you control. In production you need to override this function to return your own User ID depending on your game.

Returns

Returns the User ID which is then used in a call to GenerateAccessToken to generate the access token.

SendEventAsync

public async void SendEventAsync(string eventName, string eventType = "single", EventMetaData metaData = null)

Sends an event using EventsApi.SendEvent method. Select a proper eventName for your event. A list of supported events can be found in our Event Reference Guide. Depending on the event type, different additional properties can be send in the meta-data object.

Event type defines how the event is processed in the SCILL Backend. Two possible values are possible today:

single
The amount value (can be a property like amount, score, distance, …) of the event is incremented to the last event with the same structure. Use that for events that will collect skill over time (i.e. the number of kills in a shooter for example)
group
The amount value overrides the last events value. Use this type for events that don’t collect skill over time, but where the current value defines the skill. A laptime in a racing game for example is typically not summed up over time.
Parameters

event_name string

This is the event type as a string. These have predefined event names for many games and applications. It’s wise to use those as this allows us to analyse data and help you balancing your application or game.

event_type string

This is either single or group. You can send multiple events in one request (group) or send events in sequence. Please note, that depending on your tier you might run into rate limits.

meta_data EventMetaData

A EventMetaData object that you can/must use to set property values for the respective event.

Returns

In case of a success, this function returns an instance of ActionResponse. In case of a failure, this function returns an error.

SendEventAsync

public async void SendEventAsync(string eventName, string eventType = "single", string sessionId = null, EventMetaData metaData = null)

Sends an event using EventsApi.SendEvent method. Select a proper eventName for your event. A list of supported events can be found in our Event Reference Guide. Depending on the event type, different additional properties can be send in the meta-data object.

Event type defines how the event is processed in the SCILL Backend. Two possible values are possible today:

single
The amount value (can be a property like amount, score, distance, …) of the event is incremented to the last event with the same structure. Use that for events that will collect skill over time (i.e. the number of kills in a shooter for example)
group
The amount value overrides the last events value. Use this type for events that don’t collect skill over time, but where the current value defines the skill. A laptime in a racing game for example is typically not summed up over time.

The last parameter to be set is the SessionId. The SessionId defines how events of the single type are incremented together. Only events of the same SessionId will be incremented. If the SessionId changes, the counter starts at 0.

Parameters

event_name string

This is the event type as a string. These have predefined event names for many games and applications. It’s wise to use those as this allows us to analyse data and help you balancing your application or game.

event_type string

This is either single or group. You can send multiple events in one request (group) or send events in sequence. Please note, that depending on your tier you might run into rate limits.

session_id string

This is required if event_type is single and identifies a session. This can be anything used to group events together. For example this can be a level or a match id.

meta_data EventMetaData

A EventMetaData object that you can/must use to set property values for the respective event.

Returns

In case of a success, this function returns an instance of ActionResponse. In case of a failure, this function returns an error.