C#

SCILL provides C# classes that map our REST-APIs and adds many convenience functions.

Warning

Please note: We use a special version of the C# SDK for Unity which is bundled in the SCILL Unity SDK. It’s the same interface and APIs as the general purpose C# SDK, but uses UnityWebRequest for API calls internally for better compatibility especially with mobile apps and WebGL.

Source Code

The C# SDK exists in two flavors:

  1. A version for C# backend environments and C# frontend environments, for example Xamarin.
  2. A special version for usage within Unity which uses UnityWebRequest under the hood.

The general purpose version can be found in https://github.com/scillgame/scill-csharp and the special unity version is bundled in the SCILL Unity SDK repository.

Adding SDK to Unity

Please use our SCILL Unity SDK as it comes with a specialized C# SDK using UnityWebRequest.

Adding SDK to other C# projects

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

Data Flow

This diagram highlights the basic data flow and the connections between your application and SCILL.

The client backend is not necessarily required, but should be implemented for security reasons. It makes sure, that the API-Key is not exposed to clients.

SCILL consists of a variety of different APIs that handle different tasks. SCILLClient class exists in most SCILL SDKs and adds convenience functions and implements some basic logic for you.

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);
    }
}