The SDK requires Message Bridge setup in the website.
- Download the unitypackage from https://github.com/thirdweb-dev/unity-webgl/releases
- In your Project, Right click -> Import Package -> Custom Package. Select the unitypackage that you downloaded from (1).
- Include the
Thirdwebprefab in your scene. https://github.com/thirdweb-dev/unity-webgl/tree/master/Assets/Thirdweb - Access the Thirdweb SDK however you want! An example use case of the SDK: https://github.com/thirdweb-dev/unity-webgl/blob/master/Assets/Examples/MouseClickTest.cs
npm install @3rdweb/sdk @3rdweb/unity-bridge
- In your web app, initialize ThirdwebBridgeSDK: https://github.com/thirdweb-dev/unity-webgl-template/blob/master/src/App.tsx#L11
// replace RPC url to the correct network RPC url
const bridge = new ThirdwebBridgeSDK("https://rpc-mumbai.maticvigil.com")- Create UnityInstance in the window context for message bridging: https://github.com/thirdweb-dev/unity-webgl-template/blob/master/src/App.tsx#L20-L30
const interval = setInterval(() => {
if (window.createUnityInstance) {
clearInterval(interval);
window.createUnityInstance(canvasRef.current, window.unityConfig)
.then((unityInstance) => {
window.unityInstance = unityInstance;
});
}
}, 500);- After connecting wallet, update the ThirdwebBridgeSDK signer whenever a signer is available: https://github.com/thirdweb-dev/unity-webgl-template/blob/master/src/App.tsx#L45-L50
const signer = provider.getSigner();
bridge.setProviderOrSigner(signer);- Your C# Unity SDK can now make authenticated SDK function calls like transferring asset or buying asset.
https://github.com/thirdweb-dev/unity-webgl-template
- Open project
- Expand the
Assetsfolder - Open the
Scenesdropdown - Open the
Sample Scene - Click
File-> `Build Settings - Choose
WebGl - Click
Buid and runat the bottom right of the popup dialog
Assumes the
unity-webgl-templateandunity-webglfolders are in the same directory
$ cd unity-webgl-template
$ yarn run build
$ cd unity-webgl
$ rm -rf Assets/WebGLTemplates/Thirdweb/*
$ cp -r ../unity-webgl-template/* Assets/WebGLTemplates/Thirdweb- Collapse the
Assetsfolder - Right click the
Thirdwebasset - Click
Export Package... - Uncheck everything and only select the
Thirdwebfolders - Name the file
ThirdwebSDK
This outputs a .unitypackage file that can be distributed to WebGL developers
which they can use to import and use the bridge.
Publish new releases here
You can uypload the .unitypackage file directly to Github for distribution
unity-webgl: Project that contains all the Thirdweb C# methods that can be called within games, builds and packages the pluginunity-webgl-template: A template WebGL project that is used in theunity-webglproject as a template sceneunity-webgl-bridge: Used to setup a communication channel between the WebGL canvas and the C# unity game