Sign in

C#

SCILL provides a C# class that maps REST-APIs and provides convenience functions. It’s optimized for use in Unity.

Source Code

You can find the source code to our JavaScript SDK in our public Github repository: https://github.com/scillgame/scill-csharp. If you encounter any bugs or issues, please let us know in the Issues tab of Github.

Adding SDK to Unity

We provide source-code in our Github repository with a configured package.json. You can install the SDK by using these procedures:

  • Use Unity Package Manager to clone the Github Repository (https://github.com/scillgame/scill-csharp) in your project
  • Download the latest Release (https://github.com/scillgame/scill-csharp/releases/latest) and import into Unity by adding a “Custom Package”.
  • Download the Source, build the Solution and copy the DLLs into your Unity Asset Folder.
  • Download the Source and copy source files into your Unity Asset Folder

Adding SDK to other C# projects

  • Download the lastest release and Copy DLLs into your project.

Usage

Import the required namespaces into your application:

using SCILL;
using SCILL.Api;
using SCILL.Model;

The API has two main entries: SCILLBackend and SCILLClient. The SCILLBackend class requires an API key to initialize and should only be used in safe environments like a backend. SCILLBackend is also used to generate an access token, that is required when initializing the SCILLClient class. SCILLClient offers client side functionality like sending events and querying users challenges and battle passes.

More info about that can be found in our API-Reference.

Both classes SCILLBackend and SCILLClient wrap OpenAPI auto generated APIs like ChallengesApi. You may use them directly, have a look in the source of SCILLBackend and SCILLClient on how to set the API key or Access Token required for the backend REST APIs.

Check out this code from our Unity example to understand how to use this API:

using System.Collections.Generic;
using System.Threading.Tasks;
using SCILL;
using SCILL.Api;
using SCILL.Model;
using UnityEngine;

public class SCILLManager : MonoBehaviour
{
    // Properties to be set in the Unity inspector
    public string APIKey;
    public string AppId;
    public SCILL.Environment environment;

    // Getter for the access token
    public string AccessToken => _accessToken;
    
    // In this case, we use a unique devide identifier. Multi device support requires a user account system like
    // Steam, Playfab, etc.
    public string UserId => SystemInfo.deviceUniqueIdentifier;
    
    // Default session id. This is just an example value.
    public string SessionId => "1234";

    // Getter for the singleton instance of this class
    public static SCILLManager Instance; // **<- reference link to SCILL
    
    // Simple wrappers to get SCILL product APIs
    public EventsApi EventsApi => _scillClient.EventsApi;
    public ChallengesApi ChallengesApi => _scillClient.ChallengesApi;
    public BattlePassesApi BattlePassesApi => _scillClient.BattlePassesApi;
    public SCILLClient SCILLClient => _scillClient;

    // Local instances of SCILLClient. Please note, that SCILLBackend should not be used in game clients in production!
    private SCILLBackend _scillBackend;
    private SCILLClient _scillClient;
    private string _accessToken;
    
    private void Awake()
    {
        // Create an instance of this class and make sure it stays (also survives scene changes)
        if (Instance == null) {
            Instance = this;
            
            // This part should be done in the backend if possible to not expose the API key
            _scillBackend = new SCILLBackend(this.APIKey, environment);
            _accessToken = _scillBackend.GetAccessToken(UserId);

            _scillClient = new SCILLClient(_accessToken, AppId, environment);
            
            DontDestroyOnLoad(gameObject);
        }
        else {
            Destroy(gameObject);
        }
    }

    /// <summary>
    /// Unity method called every frame
    /// </summary>
    private void Update()
    {
    }

    // Basic convenience function to send an event. Users global UserId and sessionId
    public async void SendEventAsync(string eventName, string eventType = "single", EventMetaData metaData = null)
    {
        // Please note, in some cases you should change session ids. This is just a simple example where we don't need
        // to do that
        Debug.Log("Sending event " + eventName);
        var payload = new EventPayload(UserId, SessionId, eventName, eventType, metaData);
        var response = await EventsApi.SendEventAsync(payload);
        Debug.Log(response);
    }

    // Basic wrapper for getting personal challenges
    public async Task<List<ChallengeCategory>> GetPersonalChallengesAsync()
    {
        return await ChallengesApi.GetPersonalChallengesAsync(AppId);
    }
}