← Back to Cool GameX
Unity SDK · Free & MIT

CoolAPI for Unity

Ship your game on Cool GameX. Add achievements, playtime, player stats and DLC in a few lines of code — no dependencies, async/await, Unity 2021.3+.

v1.4.0 · MIT licensed · Unity 2021.3+ · ~16 KB · no external dependencies

🏆AchievementsUnlock + events
⏱️PlaytimeAuto sessions
📊Player StatsSet / add / get
🧩DLCOwnership checks
🔐AuthLauncher token
📡StatusOnline / offline

Install

Option A — One-click .unitypackage (recommended)

  1. Download CoolGameX-SDK.unitypackage.
  2. In Unity: Assets → Import Package → Custom Package…
  3. Pick the file, click Import. Assets/CoolGameX/ appears — done.

Option B — Zip

Download the .zip, unzip it, and drop the CoolGameX/ folder anywhere under your project's Assets/.

💡 You can also grab the SDK from inside the launcher: Admin → SDK tab has the same download plus a copy-paste quick start.

Quick start

First, create your game in the launcher's Admin panel and note its slug (e.g. my-cool-game). Then:

The easy way — no code

  1. Create an empty GameObject in your first scene.
  2. Add Component → Cool GameX → Cool GameX Manager.
  3. Set Game Slug and Server URL (https://coolgamex-davi.fly.dev).

It initializes the SDK, logs in with the launcher token, and tracks playtime automatically. Unlock achievements from anywhere:

using CoolGameX;

CoolGameXManager.Unlock("speed_runner");
CoolGameXManager.AddStat("enemies_killed");

// react to first-time unlocks (your own banner / SFX):
CoolGameXManager.AchievementUnlocked += slug => Debug.Log($"Unlocked {slug}!");

The manual way — full control

using CoolGameX;
using UnityEngine;

public class GameBootstrap : MonoBehaviour
{
    async void Start()
    {
        await CoolAPI.Initialize("my-cool-game", "https://coolgamex-davi.fly.dev");

        if (CoolAPI.IsAuthenticated)
            await CoolAPI.Auth.LoginWithToken(CoolAPI.Token);

        CoolAPI.Achievements.OnAchievementUnlocked += slug => Debug.Log($"🏆 {slug}");
        CoolAPI.Playtime.StartSession();
    }

    async void OnApplicationQuit() => await CoolAPI.Playtime.EndSession();
}
🔐 How login works: the launcher starts your game with the player's token on the command line (YourGame.exe --cgx-token=…). Initialize() reads it automatically. Outside the launcher, CoolAPI.IsAuthenticated is false — guard your calls. For editor testing, paste a token into the manager's Editor Test Token field.

Achievements

Unlocks are idempotent — call them as often as you like; the backend ignores duplicates and the event fires only the first time.

// simple
await CoolAPI.Achievements.Unlock("first_blood");

// detailed — know if it was newly unlocked
UnlockResult r = await CoolAPI.Achievements.UnlockDetailed("first_blood");
if (r.NewlyUnlocked) PlayFanfare();

// typed list of this game's achievements
AchievementInfo[] all = await CoolAPI.Achievements.GetDefinitions();

Player Stats

Persist per-player numbers — kills, levels cleared, coins, a high score. Stats live on the backend and follow the player across machines.

CoolGameXManager.AddStat("enemies_killed");        // +1
CoolGameXManager.SetStat("high_score", 9001);

// or await for the result:
int total = await CoolAPI.Stats.Add("enemies_killed", 5); // returns new total
await CoolAPI.Stats.Set("high_score", 9001);
int kills = await CoolAPI.Stats.Get("enemies_killed");

DLC

Players acquire DLC by redeeming a code or buying it in the launcher. Your game just checks ownership:

if (await CoolAPI.DLC.Owns("haunted-expansion"))
    UnlockExpansionContent();

string[] owned = await CoolAPI.DLC.ListOwned();

Playtime

The manager tracks sessions for you. To do it manually (or add a crash-proof heartbeat):

CoolAPI.Playtime.StartSession();
// ... every few minutes, so progress survives a crash:
await CoolAPI.Playtime.ReportMinutes(5);
// on quit:
await CoolAPI.Playtime.EndSession();

API reference

CoolAPI

MemberDescription
Initialize(slug, url)Initialize the SDK; reads the launcher token.
IsInitializedWhether Initialize has run.
IsAuthenticatedWhether a player token is present.
IsConnectedServer reachable on the last call.
CheckConnection()Ping the server now → updates IsConnected.
StatusLine()One-line debug string of SDK state.

CoolAPI.Achievements

MemberDescription
Unlock(slug)Unlock an achievement (idempotent).
UnlockDetailed(slug)Unlock + know if it was newly unlocked.
OnAchievementUnlockedEvent; fires on first unlock (slug).
GetDefinitions()Typed AchievementInfo[] for this game.

CoolAPI.Stats

MemberDescription
Set(key, value)Set a stat to an exact value.
Add(key, amount=1)Increment; returns the new total.
Get(key)Read a stat (0 if unset).
GetAllJson()Raw JSON of all stats for this game.

CoolAPI.DLC

MemberDescription
Owns(slug)True if the player owns the DLC.
ListOwned()All owned DLC slugs for this game.

CoolAPI.Playtime

MemberDescription
StartSession()Begin timing.
EndSession()Stop timing & report elapsed minutes.
ReportMinutes(n)Manually report minutes (heartbeat).

Need a hand?

Stuck on setup? We'll get you shipping.

Ask on Discord support@coolgamex.com