Unity SDK
The main MAJACLOUD SDK: C# for Unity with async/await and coroutine APIs, a setup window and a Starter sample.
Requirements#
- Unity 2021.3 LTS or newer, including Unity 6. Built-in, URP and HDRP all work: the SDK has no rendering code.
- Only Unity's built-in modules (UnityWebRequest, JSON, uGUI). TextMesh Pro is used by the sample.
- Editor, Windows, macOS, Linux, Android, iOS and WebGL. No threads are used, so async/await is safe on WebGL. IL2CPP-safe.
Install#
- Download the
.unitypackagefrom your project page or the downloads page. - In Unity: Assets ▸ Import Package ▸ Custom Package…, select the file and import everything.
- When Unity asks to import TMP Essentials for the sample, accept.
Everything lives in Assets/Majacloud: Runtime (the SDK), Editor (setup tools), Samples/Starter and Tests.
Connect your project#
Tools ▸ Majacloud ▸ Setup (also under Project Settings ▸ Majacloud) writes Assets/Resources/MajacloudSettings.asset. The SDK initializes itself from it before the first scene loads.
| Field | Value |
|---|---|
| Base URL | The address of this install. https://majacloud.majanite.com |
| Project ID | Dashboard ▸ API keys. |
| Client Key | The public key starting with pk_live_. Safe to ship in builds. |
Test connection stores the project name, plan and the Remote Config public key, which pins signature verification to your server.
sk_live_…) in a game build or web page. Anything shipped to players can be read.Configure from code#
Create settings at runtime, for example to point development builds at a staging server:
// Switch environments from code (e.g. a staging server in development builds)
var settings = ScriptableObject.CreateInstance<MajacloudSettings>();
settings.Configure("https://staging.yourstudio.com", "<project id>", "pk_live_…");
Majacloud.Initialize(settings);Async and coroutines#
Every async method (…Async) has a coroutine twin that takes a callback, for code that does not use async/await.
// Every async method has a coroutine version with a callback
StartCoroutine(Majacloud.Leaderboards.GetTop("coins", 10, result =>
{
if (result.Ok) Debug.Log(result.Value.Total + " players");
}));Starter sample#
Samples/Starter/Scenes/MajacloudStarter.unity has five tabs: Leaderboard, Cloud save, Rewards, Config and Account. It expects the content created by Add Starter sample content.
Reusable prefabs in Samples/Starter/Prefabs: MajacloudLeaderboardView, MajacloudPlayerBadge and MajacloudDailyRewardButton. Drop them into your UI and set the slug or reward key in the inspector.
WebGL and mobile#
- Serve WebGL builds over HTTPS: browsers block
http://requests fromhttps://pages. The API already sends the CORS headers WebGL needs. - Browsers only open new tabs from a click. For account linking on WebGL, start the flow first and open it inside a button handler (see Players).
- Testing on a phone against a server on your computer needs HTTPS too (or, for development only,
ALLOW_INSECURE_HTTPon the server and HTTP downloads allowed in Player Settings).
Editor menu#
| Menu item | What it does |
|---|---|
Tools ▸ Majacloud ▸ Setup | Keys, connection test and behaviour settings. |
Tools ▸ Majacloud ▸ Open Starter Sample | Opens the Starter scene. |
Tools ▸ Majacloud ▸ Rebuild Starter Sample | Regenerates the Starter scene and prefabs. |
Tools ▸ Majacloud ▸ Export .unitypackage | Exports the SDK as a .unitypackage. |