Skip to content

Commit

Permalink
update to support unity 2020.1.0b5
Browse files Browse the repository at this point in the history
  • Loading branch information
seleb committed Apr 22, 2020
1 parent 66ebb9f commit 937583d
Showing 1 changed file with 60 additions and 43 deletions.
103 changes: 60 additions & 43 deletions WebGLTemplates/BetterMinimal/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,11 @@
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>%UNITY_WEB_NAME%</title>
<script src="%UNITY_WEBGL_LOADER_URL%"></script>
<script>
var gameInstance = UnityLoader.instantiate("gameContainer", "%UNITY_WEBGL_BUILD_URL%");
var scaleToFit;
try {
scaleToFit = !!JSON.parse("%UNITY_CUSTOM_SCALE_TO_FIT%");
} catch (e) {
scaleToFit = true;
}

function onResize() {
var canvas = gameInstance.Module.canvas;
var container = gameInstance.container;
var w;
var h;

if (scaleToFit) {
w = window.innerWidth;
h = window.innerHeight;

var r = %UNITY_HEIGHT% / %UNITY_WIDTH%;

if (w * r > window.innerHeight) {
w = Math.min(w, Math.ceil(h / r));
}
h = Math.floor(w * r);
} else {
w = %UNITY_WIDTH%;
h = %UNITY_HEIGHT%;
}

container.style.width = canvas.style.width = w + "px";
container.style.height = canvas.style.height = h + "px";
container.style.top = Math.floor((window.innerHeight - h) / 2) + "px";
container.style.left = Math.floor((window.innerWidth - w) / 2) + "px";
}
window.addEventListener('resize', onResize);
</script>
<title>{{{ PRODUCT_NAME }}}</title>
<style>
html,
body {
background: #000;
background: %UNITY_CUSTOM_BACKGROUND%;
background: {{{ CUSTOM_BACKGROUND || '#000' }}};
width: 100%;
height: 100%;
overflow: visible;
Expand Down Expand Up @@ -75,8 +36,64 @@
</style>
</head>

<body onload="onResize();">
<div id="gameContainer"></div>
<body>
<div id="gameContainer">
<canvas id="unity-canvas"></canvas>
<script src="Build/{{{ LOADER_FILENAME }}}"></script>
<script>
createUnityInstance(document.querySelector("#unity-canvas"), {
dataUrl: "Build/{{{ DATA_FILENAME }}}",
frameworkUrl: "Build/{{{ FRAMEWORK_FILENAME }}}",
codeUrl: "Build/{{{ CODE_FILENAME }}}",
#if MEMORY_FILENAME
memoryUrl: "Build/{{{ MEMORY_FILENAME }}}",
#endif
#if SYMBOLS_FILENAME
symbolsUrl: "Build/{{{ SYMBOLS_FILENAME }}}",
#endif
streamingAssetsUrl: "StreamingAssets",
companyName: "{{{ COMPANY_NAME }}}",
productName: "{{{ PRODUCT_NAME }}}",
productVersion: "{{{ PRODUCT_VERSION }}}",
}).then(function (instance) {
var canvas = instance.Module.canvas;
var container = canvas.parentElement;
function onResize() {
var w;
var h;

if (scaleToFit) {
w = window.innerWidth;
h = window.innerHeight;

var r = {{{ HEIGHT }}} / {{{ WIDTH }}};

if (w * r > window.innerHeight) {
w = Math.min(w, Math.ceil(h / r));
}
h = Math.floor(w * r);
} else {
w = {{{ WIDTH }}};
h = {{{ HEIGHT }}};
}

container.style.width = canvas.style.width = w + "px";
container.style.height = canvas.style.height = h + "px";
container.style.top = Math.floor((window.innerHeight - h) / 2) + "px";
container.style.left = Math.floor((window.innerWidth - w) / 2) + "px";
}

var scaleToFit;
try {
scaleToFit = !!JSON.parse("{{{ SCALE_TO_FIT }}}");
} catch (e) {
scaleToFit = true;
}
window.addEventListener('resize', onResize);
onResize();
});
</script>
</div>
</body>

</html>

0 comments on commit 937583d

Please sign in to comment.