| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- 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 = unityName + "/Build";
- var loaderUrl = buildUrl + "/" + unityName +".loader.js";
- var config = {
- dataUrl: buildUrl + "/" + unityName + ".data.unityweb",
- frameworkUrl: buildUrl + "/" + unityName + ".framework.js.unityweb",
- codeUrl: buildUrl + "/" + unityName + ".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");
- var isLoad = false;
- 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;
- isLoad = true;
- }).catch((message) => {
- alert(message);
- });
- };
- document.body.appendChild(script);
|