Unity SDK

The main MAJACLOUD SDK: C# for Unity with async/await and coroutine APIs, a setup window and a Starter sample.

On this page

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#

  1. Download the .unitypackage from your project page or the downloads page.
  2. In Unity: Assets ▸ Import Package ▸ Custom Package…, select the file and import everything.
  3. 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.

FieldValue
Base URLThe address of this install. https://majacloud.majanite.com
Project IDDashboard ▸ API keys.
Client KeyThe 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.

Never put the secret key (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:

C#
// 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.

C#
// 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 from https:// 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_HTTP on the server and HTTP downloads allowed in Player Settings).
Menu itemWhat it does
Tools ▸ Majacloud ▸ SetupKeys, connection test and behaviour settings.
Tools ▸ Majacloud ▸ Open Starter SampleOpens the Starter scene.
Tools ▸ Majacloud ▸ Rebuild Starter SampleRegenerates the Starter scene and prefabs.
Tools ▸ Majacloud ▸ Export .unitypackageExports the SDK as a .unitypackage.

Search page titles, headings and text.

↑↓ to navigate ↵ to open Esc to close