Skip to main content

Unity (WebGL) integration

Unity's C# cannot call the host's JavaScript directly, so the Unity package carries a .jslib transport (compiled into your WebGL build) and a C# facade. Unity 2021.3+, WebGL build target.

Install

Download the package files from the downloads page and place them in your project:

Project layout
Assets/Flickcade/
  Runtime/
    Flickcade.cs
    Flickcade.asmdef
    Plugins/WebGL/GameReels.jslib

(Or keep the folder under Packages/ as an embedded UPM package — add the provided package.json beside Runtime/; the download layout is already the UPM package layout.) On every platform except WebGL — including Play mode in the Editor — the facade compiles to safe no-ops with OnActive delivered once at startup, so game code needs no #if guards.

Minimum integration

C#
using FlickcadeSDK;

public class GameBootstrap : MonoBehaviour
{
    void Start()
    {
        Flickcade.OnActive += () => { Time.timeScale = 1f; AudioListener.pause = false; };
        Flickcade.OnHidden += () => { Time.timeScale = 0f; AudioListener.pause = true;  };
        Flickcade.Ready(); // when gameplay could start (after your async loads)
    }
}
Your build boots hidden — do not start gameplay or audio in your gameplay scene's Start(); wait for the first OnActive. And pause the audio graph on OnHidden: the app mutes you natively anyway, but a running AudioListener burns battery for no output.

Gameplay events

C#
Flickcade.LevelStart("3");
Flickcade.LevelEnd("3", Outcome.Win, ms: 41200);
Flickcade.Score(1250);
Flickcade.Reward(RewardType.Currency, "coin", 25);
Flickcade.Reward(RewardType.Item, "sword");   // amount omitted from the event
Flickcade.Custom("boss_phase", new Dictionary<string, object> { ["n"] = 2 });
Flickcade.AdBreak();

Semantics and limits are the same as the JavaScript surface — see the API reference. Every call returns bool — true when the bridge accepted the event, false when it was dropped (over a limit, invalid argument, no bridge, not a WebGL build) — and Flickcade.Version reads the bridge version. Keep WebGL Run In Backgroundenabled so the host's lifecycle, not the browser's focus heuristics, decides when you pause.

Build settings

Export with the default Publishing Settings. Flickcade serves your build exactly the way Unity's own server configurations do, so nothing needs to change for hosting:

SettingUseWhy
Compression FormatGzip (default) or BrotliBuild files ship precompressed (.gz / .br) and are served with the matching Content-Encoding, so the browser decodes them natively. Brotli is smaller; Gzip builds faster and previews in every browser.
Decompression FallbackOff (default)Not needed. Enabling it embeds a JavaScript decompressor, grows the loader and disables streaming WebAssembly compilation — a slower first frame for no benefit here.
Data CachingOffThe app keeps its own on-device build cache; Unity's IndexedDB cache would store every file twice.

Zip the contents of the build folder (index.html, Build/, TemplateData/) — a single top-level folder inside the archive is also accepted.

Keep index.html at the top level of the ZIP. Other HTML pages are fine — a docs/index.html beside a top-level index.html is accepted, because the top-level one is the entry point by both its depth and its name.

The upload is refused when nothing in the archive says which page is the game: a top-level game.html next to a deeper docs/index.html, or two index.html files at the same depth (web-mobile/ + web-desktop/). The error names the candidates — move the game's index.html to the top level, or drop the other page.

Size limits

LimitValueWhat it protects
Build ZIP128 MBThe on-device cache holds 128 MB per game; a larger build is re-downloaded on every play.
Any single file64 MB as uploadedOne response the phone can cache. A precompressed .data.gz decodes to roughly twice its size on the device, which is why the cap is half the per-game budget.
Files in the ZIP1500Every file is one HTTP request at load time. A Unity build is under 20.
The caps are what is allowed, not what plays well. The feed gives a build 8 seconds to call Flickcade.Ready() before it is retried and then shown as failed, and players scroll on long before that. Aim for a build under 32 MB, call Ready() as soon as your first scene can respond, and load the rest behind it.