Unity integration
Native Unity setup, integration source and export guidance.
Downloads for this guide
Unity source packageSource + configuration/adapter + README; engine verification notes included.Download PlayIslandExample.csIndividual native integration source.Download PlayIsland.jslibNative C# to browser bridge.Support and prerequisites
Verified in local desktop and mobile-viewport Chromium: the exported starter loaded inside Play Island's real sandbox and completed a run with accepted start, progress and completion events. HTML5 also passed pause/resume and replay. This is not certification for every engine version or physical device. The same per-game event registration and provider approval requirements apply. Download the source package and read README.txt before building. Browser samples never need a secret key.
Set up the project
Open the extracted folder in Unity Hub using Unity 2022.3 LTS (project marker 2022.3.62f2) with Web build support installed. The supplied C# MonoBehaviour creates the sample controls. Choose Play Island → Build Web example: the editor command creates Assets/Example.unity and exports Build/. It selects the included PlayIsland Web template and disables compression and WebGL data caching (CacheStorage is unavailable in the sandbox). Keep client.js alongside index.html. No editor assembly or project source belongs in your submitted ZIP. This project compiled and exported successfully with Unity 2022.3.62f2 WebGL. Test your exported build under the platform sandbox and on the devices you support before shipping.
Native integration example
using System;
using System.Runtime.InteropServices;
using UnityEngine;
// Attach once; the included editor build command creates the scene for you.
public class PlayIslandExample : MonoBehaviour
{
#if UNITY_WEBGL && !UNITY_EDITOR
[DllImport("__Internal")] private static extern void PI_Connect(string objectName);
[DllImport("__Internal")] private static extern void PI_Report(string objectName, string name, string json);
[DllImport("__Internal")] private static extern void PI_Dispose();
#endif
[Serializable] private class Progress { public int progress; }
[Serializable] private class Result { public int score; public int progress = 100; }
private string message = "Connecting…", action;
private int stars;
private bool busy = true, running, broken;
private float startedAt;
private void Start()
{
gameObject.name = "PlayIslandExample";
#if UNITY_WEBGL && !UNITY_EDITOR
PI_Connect(gameObject.name);
#else
broken = true;
message = "Editor layout preview. Build Web and launch inside Play Island to connect.";
#endif
}
public void OnConfiguration(string json) { message = "Connected. Start a run."; busy = false; Debug.Log(json); }
public void OnError(string reason) { broken = true; busy = false; message = reason + " Reload after fixing the integration."; }
public void OnAccepted(string json)
{
if (action == "started") { stars = 0; running = true; startedAt = Time.realtimeSinceStartup; }
if (action == "progress") stars++;
if (action == "completed") running = false;
busy = false; message = "Accepted: " + action + " · " + stars + " / 5 stars"; Debug.Log(json);
}
private void Report(string name, string json)
{
if (busy || broken) return;
busy = true; action = name;
#if UNITY_WEBGL && !UNITY_EDITOR
PI_Report(gameObject.name, name, json);
#endif
}
private void OnGUI()
{
GUI.matrix = Matrix4x4.Scale(new Vector3(Screen.width / 720f, Screen.height / 540f, 1));
GUILayout.BeginArea(new Rect(30, 30, 660, 480));
GUILayout.Label("Play Island · Collect Five"); GUILayout.Label(message);
GUI.enabled = !busy && !broken && !running;
if (GUILayout.Button("Start run", GUILayout.Height(65))) Report("started", "{}");
GUI.enabled = !busy && !broken && running && stars < 5;
if (GUILayout.Button("Collect a star", GUILayout.Height(65))) Report("progress", JsonUtility.ToJson(new Progress { progress = (stars + 1) * 20 }));
GUI.enabled = !busy && !broken && running && stars == 5 && Time.realtimeSinceStartup - startedAt >= 4;
if (GUILayout.Button("Finish run", GUILayout.Height(65))) Report("completed", JsonUtility.ToJson(new Result { score = stars * 10 }));
GUI.enabled = true; GUILayout.EndArea();
}
private void OnDestroy()
{
#if UNITY_WEBGL && !UNITY_EDITOR
PI_Dispose();
#endif
}
}Browser interoperability
mergeInto(LibraryManager.library, {
PI_Connect: function(objectName) {
var target = UTF8ToString(objectName);
if (!window.PIExample) { SendMessage(target, 'OnError', 'Missing client.js in the Web template.'); return; }
window.PIExample.connect().then(function(config) {
SendMessage(target, 'OnConfiguration', JSON.stringify(config));
}).catch(function(error) { SendMessage(target, 'OnError', error.message); });
},
PI_Report: function(objectName, eventName, payload) {
var target = UTF8ToString(objectName), name = UTF8ToString(eventName), json = UTF8ToString(payload);
try {
window.PIExample.report(name, JSON.parse(json)).then(function(ack) {
SendMessage(target, 'OnAccepted', JSON.stringify(ack));
}).catch(function(error) { SendMessage(target, 'OnError', error.message); });
} catch (error) { SendMessage(target, 'OnError', error.message); }
},
PI_Dispose: function() { if (window.PIExample) window.PIExample.dispose(); }
});Event lifecycle and errors
The project uses the supplied client.js helper to call the real injected PlayIsland SDK. It waits for configuration and acknowledgement callbacks. The helper serializes reports, detects rejected events and stops after a timeout or rejection. It does not manufacture accepted events offline. The example's proposed registry permits score (integer 0–1,000,000) and progress (number 0–100); both are optional in that proposal. Staff must publish the relevant definitions for your game. Other games may have different required fields. Do not copy a built-in game's specialized counters. Wait for real gameplay before reporting completion; the server rejects completed within the first three seconds of a session. Stop after terminal acceptance; use started to begin a new run or reload the launcher. On error, display the reason, correct the problem and reload to obtain a clean sequence.
Test, export and submit
- Test the engine's own rendering and controls locally. A standalone/editor launch will not connect to Play Island.
- Build using the setup instructions above and inspect the resulting runtime files.
- Follow ZIP packaging and provider submission.
- Use the visual preview for loading/layout. Use a published /play/ launch for actual accepted-event tests.
- Verify configuration, accepted start/progress/result, guest behavior, signed-in receipts if configured, replay and mobile controls.
Saves, exit, platform leaderboard navigation and general player profiles are not available automatically to your new game. See feature availability before adding those buttons.
Engine reference
Unity browser scripting explains the native engine/browser mechanism. The Play Island contract is defined by the platform implementation, not by the engine documentation.