Path: blob/main/projects/slope/TemplateData56/UnityProgress.js
1834 views
const rootPath = "TemplateData56";1function UnityProgress(gameInstance, progress) {2if (!gameInstance.Module) {3return;4}5if (!gameInstance.logo) {6gameInstance.logo = document.createElement("div");7gameInstance.logo.className = "logo " + gameInstance.Module.splashScreenStyle;8gameInstance.container.appendChild(gameInstance.logo);9}10if (!gameInstance.progress) {11gameInstance.progress = document.createElement("div");12gameInstance.progress.className = "progress " + gameInstance.Module.splashScreenStyle;13gameInstance.progress.empty = document.createElement("div");14gameInstance.progress.empty.className = "empty";15gameInstance.progress.appendChild(gameInstance.progress.empty);16gameInstance.progress.full = document.createElement("div");17gameInstance.progress.full.className = "full";18gameInstance.progress.appendChild(gameInstance.progress.full);19gameInstance.container.appendChild(gameInstance.progress);20gameInstance.textProgress = document.createElement("div");21gameInstance.textProgress.className = "text";22gameInstance.container.appendChild(gameInstance.textProgress);23}24gameInstance.progress.full.style.width = 100 * progress + "%";25gameInstance.progress.empty.style.width = 100 * (1 - progress) + "%";26gameInstance.textProgress.innerHTML = "Loading: " + Math.floor(progress * 100) + "%";27if (progress == 1) {28gameInstance.textProgress.innerHTML = 'Running... <img src="' + rootPath + '/gears.gif" class="spinner" />';29}30if (progress == "complete") {31gameInstance.logo.style.display = "none";32gameInstance.progress.style.display = "none";33gameInstance.textProgress.style.display = "none";34const event = new Event("removeSoundOverlay");35document.dispatchEvent(event);36}37}38window.Game = (function () {39var Game = function () {40this.registerEvents();41};42Game.prototype.registerEvents = function () {43var _this = this;44window.addEventListener(45"keydown",46function (e) {47if ([8, 37, 38, 39, 40].indexOf(e.keyCode) > -1) {48e.preventDefault();49}50},51false52);53document.onmousedown = function () {54window.focus();55};56document.addEventListener(57"DOMContentLoaded",58function () {59_this.resize();60},61false62);63window.addEventListener(64"resize",65function () {66setTimeout(function () {67_this.resize();68}, 1000);69},70false71);72};73Game.prototype.getQueryVariable = function (variable) {74var query = window.location.search.substring(1);75var vars = query.split("&");76for (var i = 0; i < vars.length; i++) {77var pair = vars[i].split("=");78if (pair[0] == variable) {79return pair[1];80}81}82return false;83};84Game.prototype.resize = function () {85var ratioTolerant = this.getQueryVariable("ratio_tolerant");86if (ratioTolerant == false || this.fullscreen()) {87return;88}89document.getElementsByTagName("body")[0].style.overflow = "hidden";90var gameContainer = document.getElementById("gameContainer") || document.getElementById("unityContainer");91var canvas = document.getElementById("#canvas");92var gameSizeRatio = gameContainer.offsetWidth / gameContainer.offsetHeight;93var maxHeight = this.maxHeight();94var maxWidth = window.innerWidth;95var windowSizeRatio = maxWidth / maxHeight;96var newStyle = { width: gameContainer.offsetWidth, height: gameContainer.offsetHeight };97if (ratioTolerant == "true") {98newStyle = { width: maxWidth, height: maxHeight };99} else if (ratioTolerant == "false") {100if (gameSizeRatio > windowSizeRatio) {101newStyle = { width: maxWidth, height: maxWidth / gameSizeRatio };102} else {103newStyle = { width: maxHeight * gameSizeRatio, height: maxHeight };104}105}106this.updateStyle(gameContainer, newStyle);107if (canvas) {108this.updateStyle(canvas, newStyle);109}110};111Game.prototype.maxHeight = function () {112return window.innerHeight - 43;113};114Game.prototype.updateStyle = function (element, size) {115element.setAttribute("width", size.width);116element.setAttribute("height", size.height);117element.style.width = size.width + "px";118element.style.height = size.height + "px";119};120Game.prototype.fullscreen = function () {121return document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement || document.msFullscreenElement;122};123return Game;124})();125new Game();126127