# Bring a Unity game

For a Unity WebGL game that already runs on other web game portals. You keep the project and the scenes; you swap the WebGL template and the portal calls, and check a few Player Settings. The full reference, with the mapping of every call, is the [Unity engine page](https://docs.zokogames.com/engines/unity). The overall route is in [bring your game](https://docs.zokogames.com/porting/overview).

## 1. Export settings

Install the package (`com.zokogames.sdk`, Unity 2021.3 or newer) as described in [Unity: install](https://docs.zokogames.com/engines/unity#install), then run **ZokoGames > Install WebGL Template**. Check these settings against what your build used before:

| Setting | On ZokoGames |
| --- | --- |
| **WebGL Template** | **ZokoGames**. It loads the SDK before the Unity loader and reports the download to the portal's loading bar. A custom template works if it keeps the canvas id `unity-canvas` and loads `https://sdk.zokogames.com/zokogames-sdk-v1.js` first. |
| **Compression Format** | **Brotli** or **Gzip**, one format for the whole build. The game origin sends the matching `Content-Encoding` for `.br` and `.gz` files. |
| **Decompression Fallback** | Off. Builds made for hosts that cannot set `Content-Encoding` often have it on; the portal does not need it. |
| Legacy `.unityweb` files | Not supported (validator warning `unity_unityweb`). Rebuild with Brotli or Gzip. |
| **Threading** | Off. A threaded build cannot start in the portal frame (`SharedArrayBuffer is not defined`). |
| Canvas Scaler | **Scale With Screen Size**: the canvas fills a frame whose size changes with fullscreen and rotation. |

Details and the reasons: [WebGL export settings that matter](https://docs.zokogames.com/engines/unity#webgl-export-settings-that-matter).

## 2. Replace the platform calls

Delete the other portal's template, `.jslib` and wrapper scripts first, so two SDKs never run side by side. Then call `ZokoSDK.InitAsync()` once in your first scene and map each call your game makes:

| Your game does | With ZokoSDK |
| --- | --- |
| Start the SDK | `await ZokoSDK.InitAsync()` once; then check `ZokoSDK.IsAvailable` (false when the SDK is `disabled`, and the game must still run). |
| Loading finished | Nothing to write for the engine download: the ZokoGames template sends `loadingStart` and `loadingStop` once the engine has started. Call `ZokoSDK.Game.LoadingStart()`, `LoadingProgress(p)` and `LoadingStop()` yourself only for a longer loading screen of your own or in a custom template. |
| Gameplay start and stop | `ZokoSDK.Game.GameplayStart()` at first control, `GameplayStop()` at pause, game over and level end. |
| Midgame ad (an interstitial or commercial break) | `ZokoSDK.Ad.RequestAdAsync(ZokoAdType.Midgame, adStarted: PauseForAd)`; resume after the `await`, which returns for every outcome. |
| Rewarded ad | The same with `ZokoAdType.Rewarded`; grant the reward only when it returns `null` (the ad finished). |
| Mute during ads | Nothing to write: `Ad.MuteAudioDuringAds` and `Ad.FollowPortalMute` are on by default. Pausing `Time.timeScale` stays your job. |
| Cloud save | `ZokoSDK.Data.SetInt`, `GetInt`, `SetString` and the other `Data` calls (synchronous after init). Games that saved to `PlayerPrefs` only can mirror them with `Data.PushPlayerPrefs` and `PullPlayerPrefs`, see [PlayerPrefs mirror](https://docs.zokogames.com/engines/unity#playerprefs-mirror-and-clipboard). |
| Leaderboard score | `ZokoSDK.User.SubmitScore(encryptedScore, score, done)` for a signed-in player, on a board you create in the console. No wrapper builds the encrypted payload; read [leaderboards](https://docs.zokogames.com/sdk/leaderboards#client-submission) before you choose a keyed board. |
| Purchases | `ZokoSDK.Store.GetCatalogItemsAsync`, `BuyItemAsync(sku)`, `ConsumeItemAsync(sku, qty)`, with products defined again in the console. Purchases are test purchases for now ([purchases](https://docs.zokogames.com/sdk/purchases)). |
| Sign-in prompt, player name | `ZokoSDK.User.ShowAuthPrompt(cb)`, `User.GetUserAsync()`. |

The working boot script on the engine page covers init, both ad types, save and score in one MonoBehaviour: [a working boot script](https://docs.zokogames.com/engines/unity#a-working-boot-script). Every other call is in the [mapping table](https://docs.zokogames.com/engines/unity#mapping).

The [compatibility shim](https://docs.zokogames.com/guides/migrating#two-ways-to-port) only helps JavaScript code. If your WebGL template or a `.jslib` of your own calls another portal's JavaScript SDK directly, the shim can bridge those calls, but your C# calls still move to `ZokoSDK`.

## 3. Build size and mobile

- The budget is 1,500 files, 250 MB unpacked and about 50 MB initial download (20 MB for mobile), estimated from **uncompressed** sizes, so Brotli does not rescue an oversized build.
- Keep the first scene small and load the rest with Addressables shipped inside the build; the rules are in [Addressables and custom builds](https://docs.zokogames.com/engines/unity#addressables-and-custom-builds).
- Managed Stripping Level High, Strip Engine Code on, ASTC textures for mobile, a small initial memory size.
- Unity games are off on iOS by default. Tick **Tested and works well on iOS** in the console only after testing on a real device ([mobile](https://docs.zokogames.com/guides/mobile)).
- Start music from a "tap to play" screen: browsers keep audio suspended until the first input.

## 4. Test before you submit

1. **In the Editor**, the simulator answers (`ZokoSDK.IsSimulated` is true). Tune it in `ZokoSDKSettings`: ad fill, no fill and error, a logged-out player, an ad blocker, a disabled SDK.
2. **A WebGL build on `localhost`** runs the SDK's own local mode, which also enforces the three-minute midgame cooldown that the simulator skips. Brotli builds need a server that sends `Content-Encoding: br`; build with compression Disabled for local tests if yours does not. See [Unity: test locally](https://docs.zokogames.com/engines/unity#test-locally).
3. **Upload the zip** (the build folder's contents, `index.html` at the archive root) and open the game's **Preview and QA** tab in the developer console. It runs the exact build in the portal frame with ads on and ticks the checklist as each call arrives ([build preview](https://docs.zokogames.com/getting-started/local-testing#the-build-preview-in-the-console)).

## Checklist

- [ ] ZokoGames WebGL template (or your own with `unity-canvas` and the SDK script first).
- [ ] Brotli or Gzip, Decompression Fallback off, no `.unityweb`, threading off.
- [ ] The other portal's template, `.jslib`, scripts, logos and sitelock removed.
- [ ] `InitAsync` first; the game plays when `IsAvailable` is false.
- [ ] Gameplay start and stop at the right moments.
- [ ] Both ad types pause and resume on every outcome; rewards only after a finished ad.
- [ ] Saves through `ZokoSDK.Data`; scores on a board created in the console.
- [ ] First scene within the initial download budget; iOS tested before you enable it.
- [ ] Tested on `localhost` and in **Preview and QA**.

## Next

- Full reference: [Unity](https://docs.zokogames.com/engines/unity).
- Before upload: [build validation](https://docs.zokogames.com/requirements/build-validation) and the [launch checklist](https://docs.zokogames.com/requirements/checklist).
- Upload and publish: [submission walkthrough](https://docs.zokogames.com/getting-started/submission-walkthrough).
