Path: blob/main/projects/stack-bump-3d/TemplateData56/UnityProgress.js
1834 views
const rootPath = 'TemplateData56';12function UnityProgress(gameInstance, progress) {3if (!gameInstance.Module) {4return;5}67if (!gameInstance.logo) {8gameInstance.logo = document.createElement("div");9gameInstance.logo.className = "logo " + gameInstance.Module.splashScreenStyle;10gameInstance.container.appendChild(gameInstance.logo);11}1213if (!gameInstance.progress) {14gameInstance.progress = document.createElement("div");15gameInstance.progress.className = "progress " + gameInstance.Module.splashScreenStyle;16gameInstance.progress.empty = document.createElement("div");17gameInstance.progress.empty.className = "empty";18gameInstance.progress.appendChild(gameInstance.progress.empty);19gameInstance.progress.full = document.createElement("div");20gameInstance.progress.full.className = "full";21gameInstance.progress.appendChild(gameInstance.progress.full);22gameInstance.container.appendChild(gameInstance.progress);23gameInstance.textProgress = document.createElement("div");24gameInstance.textProgress.className = "text";25gameInstance.container.appendChild(gameInstance.textProgress);26}2728gameInstance.progress.full.style.width = (100 * progress) + "%";29gameInstance.progress.empty.style.width = (100 * (1 - progress)) + "%";30gameInstance.textProgress.innerHTML = 'Loading: ' + Math.floor(progress * 100) + '%';3132if (progress == 1) {33gameInstance.textProgress.innerHTML = 'Running... <img src="' + rootPath + '/gears.gif" class="spinner" />';34}3536if (progress == 'complete') {37gameInstance.logo.style.display = 'none';38gameInstance.progress.style.display = 'none';39gameInstance.textProgress.style.display = 'none';4041// see shared/EnableSound.js42const event = new Event('removeSoundOverlay');43document.dispatchEvent(event);44}45}4647window.Game = (function() {48var Game = function() {49this.registerEvents();50};5152Game.prototype.registerEvents = function() {53var _this = this;5455window.addEventListener("keydown", function(e) {56// space and arrow keys57if([8, 37, 38, 39, 40].indexOf(e.keyCode) > -1) {58e.preventDefault();59}60}, false);6162document.onmousedown = function() {63window.focus();64};6566document.addEventListener('DOMContentLoaded', function() {67_this.resize();68}, false);6970window.addEventListener('resize', function() {71setTimeout(function() {72_this.resize();73}, 1000);74}, false);75};7677Game.prototype.getQueryVariable = function(variable) {78var query = window.location.search.substring(1);79var vars = query.split("&");80for (var i = 0; i < vars.length; i++) {81var pair = vars[i].split("=");82if(pair[0] == variable){83return pair[1];84}85}86return(false);87}8889Game.prototype.resize = function() {90var ratioTolerant = this.getQueryVariable('ratio_tolerant');91if (ratioTolerant == false || this.fullscreen()) {92return;93}9495document.getElementsByTagName('body')[0].style.overflow = 'hidden';96var gameContainer = document.getElementById('gameContainer') || document.getElementById('unityContainer');97var canvas = document.getElementById('#canvas');9899var gameSizeRatio = gameContainer.offsetWidth / gameContainer.offsetHeight;100var maxHeight = this.maxHeight();101var maxWidth = window.innerWidth;102var windowSizeRatio = maxWidth / maxHeight;103var newStyle = {104width: gameContainer.offsetWidth,105height: gameContainer.offsetHeight106};107108if (ratioTolerant == 'true') {109newStyle = { width: maxWidth, height: maxHeight };110} else if (ratioTolerant == 'false') {111if (gameSizeRatio > windowSizeRatio) {112newStyle = { width: maxWidth, height: maxWidth / gameSizeRatio };113} else {114newStyle = { width: maxHeight * gameSizeRatio, height: maxHeight };115}116}117118this.updateStyle(gameContainer, newStyle);119120// canvas does not exists on page load121if (canvas) {122this.updateStyle(canvas, newStyle);123}124};125126Game.prototype.maxHeight = function() {127return window.innerHeight - 43;128};129130Game.prototype.updateStyle = function(element, size) {131element.setAttribute('width', size.width);132element.setAttribute('height', size.height);133element.style.width = size.width + 'px';134element.style.height = size.height + 'px';135};136137Game.prototype.fullscreen = function() {138return document.fullscreenElement ||139document.webkitFullscreenElement ||140document.mozFullScreenElement ||141document.msFullscreenElement;142};143144return Game;145})();146147new Game();148149150