Skip to content

Latest commit

 

History

History
58 lines (41 loc) · 1.51 KB

webgl_installation.md

File metadata and controls

58 lines (41 loc) · 1.51 KB
cover coverY
../.gitbook/assets/UNITY3DxWAX-1920x360_Devs_03.png
0

WebGL installation

WebGL builds will require the index.html file to be customised.

Download the full customised file here.

Ensure that this line is added to make websockets work.

window.unityInstance = unityInstance;
Further reading

WebAssembly for security purposes does not have Networking-Capabilities.

Read more here: (https://webassembly.org/docs/security/)

Final script should have this included

      script.onload = () => {
        createUnityInstance(canvas, config, (progress) => {
          progressBarFull.style.width = 100 * progress + "%";
          }).then((unityInstance) => {
	  
	  // !!! IMPORTANT
	  window.unityInstance = unityInstance; // <-- THIS LINE MUST BE ADDED TO ENSURE WEBSOCKETS WORK!!!
          // !!! IMPORTANT
	  
          loadingBar.style.display = "none";
          fullscreenButton.onclick = () => {
          unityInstance.SetFullscreen(1);
          };
        }).catch((message) => {
          alert(message);
        });

Additional snippets

Unity WebGL requires an event listener to paste from the OS clipboard. Use the following structure in script.onload.

window.addEventListener('paste', function (e) {
      const str = e.clipboardData.getData('text');
      window.unityInstance.SendMessage('CanvasExample', 'OnBrowserClipboardPaste', str);
     });