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+.
Install
Option A — One-click .unitypackage (recommended)
- Download CoolGameX-SDK.unitypackage.
- In Unity: Assets → Import Package → Custom Package…
- 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/.
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
- Create an empty GameObject in your first scene.
- Add Component → Cool GameX → Cool GameX Manager.
- 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();
}
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
| Member | Description |
|---|---|
Initialize(slug, url) | Initialize the SDK; reads the launcher token. |
IsInitialized | Whether Initialize has run. |
IsAuthenticated | Whether a player token is present. |
IsConnected | Server reachable on the last call. |
CheckConnection() | Ping the server now → updates IsConnected. |
StatusLine() | One-line debug string of SDK state. |
CoolAPI.Achievements
| Member | Description |
|---|---|
Unlock(slug) | Unlock an achievement (idempotent). |
UnlockDetailed(slug) | Unlock + know if it was newly unlocked. |
OnAchievementUnlocked | Event; fires on first unlock (slug). |
GetDefinitions() | Typed AchievementInfo[] for this game. |
CoolAPI.Stats
| Member | Description |
|---|---|
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
| Member | Description |
|---|---|
Owns(slug) | True if the player owns the DLC. |
ListOwned() | All owned DLC slugs for this game. |
CoolAPI.Playtime
| Member | Description |
|---|---|
StartSession() | Begin timing. |
EndSession() | Stop timing & report elapsed minutes. |
ReportMinutes(n) | Manually report minutes (heartbeat). |