Game Engines
Unity WebGL Integration
Learn how to connect your Unity WebGL game to the BentoTiles SDK using C# and .jslib.
Unity WebGL Setup Guide
Integrate the BentoTiles SDK into your Unity WebGL game project using our C# bridge and .jslib plugin.
1. Add .jslib Plugin
Copy BentoTilesSDK.jslib into your Unity project's Assets/Plugins/WebGL/ folder:
mergeInto(LibraryManager.library, {
BentoTiles_Init: function (gameIdPtr) {
var gameId = UTF8ToString(gameIdPtr);
if (window.BentoTiles) window.BentoTiles.init({ gameId: gameId });
},
BentoTiles_CommercialBreak: function (objectNamePtr, beforeCbPtr, afterCbPtr) {
var objectName = UTF8ToString(objectNamePtr);
var beforeCb = UTF8ToString(beforeCbPtr);
var afterCb = UTF8ToString(afterCbPtr);
if (window.BentoTiles) {
window.BentoTiles.commercialBreak({
beforeAd: function () { SendMessage(objectName, beforeCb); },
afterAd: function () { SendMessage(objectName, afterCb); }
});
}
}
});2. Add C# Script
Attach BentoTilesSDK.cs to a GameObject in your main scene:
using System.Runtime.InteropServices;
using UnityEngine;
public class BentoTilesSDK : MonoBehaviour
{
[DllImport("__Internal")]
private static extern void BentoTiles_Init(string gameId);
[DllImport("__Internal")]
private static extern void BentoTiles_CommercialBreak(string objectName, string beforeCb, string afterCb);
void Start()
{
#if UNITY_WEBGL && !UNITY_EDITOR
BentoTiles_Init("my-unity-game");
#endif
}
public void ShowAd()
{
#if UNITY_WEBGL && !UNITY_EDITOR
BentoTiles_CommercialBreak(gameObject.name, "OnBeforeAd", "OnAfterAd");
#endif
}
public void OnBeforeAd() { AudioListener.pause = true; Time.timeScale = 0; }
public void OnAfterAd() { AudioListener.pause = false; Time.timeScale = 1; }
}