var container = document.querySelector("#unity-container"); var canvas = document.querySelector("#unity-canvas"); var loadingBar = document.querySelector("#unity-loading-bar"); var progressBarFull = document.querySelector("#unity-progress-bar-full"); var warningBanner = document.querySelector("#unity-warning"); function unityShowBanner(msg, type) { function updateBannerVisibility() { warningBanner.style.display = warningBanner.children.length ? 'block' : 'none'; } var div = document.createElement('div'); div.innerHTML = msg; warningBanner.appendChild(div); if (type == 'error') div.style = 'background: red; padding: 10px;'; else { if (type == 'warning') div.style = 'background: yellow; padding: 10px;'; setTimeout(function() { warningBanner.removeChild(div); updateBannerVisibility(); }, 5000); } updateBannerVisibility(); } var buildUrl = "C3Dev/Build"; var loaderUrl = buildUrl + "/C3Dev.loader.js"; var config = { dataUrl: buildUrl + "/C3Dev.data.unityweb", frameworkUrl: buildUrl + "/C3Dev.framework.js.unityweb", codeUrl: buildUrl + "/C3Dev.wasm.unityweb", streamingAssetsUrl: "StreamingAssets", companyName: "DefaultCompany", productName: "C3Monitor", productVersion: "0.1", showBanner: unityShowBanner, }; if (/iPhone|iPad|iPod|Android/i.test(navigator.userAgent)) { // Mobile device style: fill the whole browser client area with the game canvas: var meta = document.createElement('meta'); meta.name = 'viewport'; meta.content = 'width=device-width, height=device-height, initial-scale=1.0, user-scalable=no, shrink-to-fit=yes'; document.getElementsByTagName('head')[0].appendChild(meta); container.className = "unity-mobile"; // To lower canvas resolution on mobile devices to gain some // performance, uncomment the following line: // config.devicePixelRatio = 1; canvas.style.width = '100%'; canvas.style.height = '610px'; unityShowBanner('WebGL builds are not supported on mobile devices.'); } else { // Desktop style: Render the game canvas in a window that can be maximized to fullscreen: //canvas.style.width = '600px'; canvas.style.height = '610px'; canvas.style.width = '100%'; } loadingBar.style.display = "block"; var myGameInstance = null; var script = document.createElement("script"); script.src = loaderUrl; script.onload = () => { createUnityInstance(canvas, config, (progress) => { progressBarFull.style.width = Math.round(100 * progress) + "%"; progressBarFull.innerHTML = Math.round(100 * progress) + "%"; }).then((unityInstance) => { loadingBar.style.display = "none"; myGameInstance = unityInstance; }).catch((message) => { alert(message); }); }; document.body.appendChild(script);