Skip to content
This repository has been archived by the owner on Nov 12, 2022. It is now read-only.

Releases: thirdweb-dev/unity-webgl-sdk

v1.0.0

17 Nov 08:09
06d6784
Compare
Choose a tag to compare

Installation

In the Unity project:

  1. Download the unitypackage below
  2. In your Project, Right click -> Import Package -> Custom Package. Select the unitypackage that you downloaded from (1).
  3. Include the Thirdweb prefab in your scene. https://github.com/nftlabs/unity-webgl/tree/master/Assets/Thirdweb
  4. Access the Thirdweb SDK however you want! An example use case of the SDK: https://github.com/nftlabs/unity-webgl/blob/master/Assets/Examples/MouseClickTest.cs

In the web project:

npm install @3rdweb/sdk @3rdweb/unity-bridge
  1. In your web app, initialize ThirdwebBridgeSDK: https://github.com/nftlabs/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")
  1. Create UnityInstance in the window context for message bridging: https://github.com/nftlabs/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);
  1. After connecting wallet, update the ThirdwebBridgeSDK signer whenever a signer is available: https://github.com/nftlabs/unity-webgl-template/blob/master/src/App.tsx#L45-L50
const signer = provider.getSigner();
bridge.setProviderOrSigner(signer);
  1. Your C# Unity SDK can now make authenticated SDK function calls like transferring asset or buying asset.

See Also: Example Unity WebGL Website

https://github.com/nftlabs/unity-webgl-template