Skip to content

Commit 3f49d1a

Browse files
author
Saravanan Raghunathan
committed
fix
1 parent 5b34af9 commit 3f49d1a

File tree

2 files changed

+133
-2
lines changed

2 files changed

+133
-2
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
/[Ll]ibrary/
66
/[Tt]emp/
77
/[Oo]bj/
8-
/[Bb]uild/
9-
/[Bb]uilds/
8+
#/[Bb]uild/
9+
#/[Bb]uilds/
1010
/[Ll]ogs/
1111
/[Uu]ser[Ss]ettings/
1212

Build/WebGL/index.html

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<!DOCTYPE html>
2+
<html lang="en-us">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
6+
<title>Unity WebGL Player | Puzzle-1-Task</title>
7+
<link rel="shortcut icon" href="TemplateData/favicon.ico">
8+
<link rel="stylesheet" href="TemplateData/style.css">
9+
</head>
10+
<body>
11+
<div id="unity-container" class="unity-desktop">
12+
<canvas id="unity-canvas" width=960 height=600 tabindex="-1"></canvas>
13+
<div id="unity-loading-bar">
14+
<div id="unity-logo"></div>
15+
<div id="unity-progress-bar-empty">
16+
<div id="unity-progress-bar-full"></div>
17+
</div>
18+
</div>
19+
<div id="unity-warning"> </div>
20+
<div id="unity-footer">
21+
<div id="unity-webgl-logo"></div>
22+
<div id="unity-fullscreen-button"></div>
23+
<div id="unity-build-title">Puzzle-1-Task</div>
24+
</div>
25+
</div>
26+
<script>
27+
28+
var container = document.querySelector("#unity-container");
29+
var canvas = document.querySelector("#unity-canvas");
30+
var loadingBar = document.querySelector("#unity-loading-bar");
31+
var progressBarFull = document.querySelector("#unity-progress-bar-full");
32+
var fullscreenButton = document.querySelector("#unity-fullscreen-button");
33+
var warningBanner = document.querySelector("#unity-warning");
34+
35+
// Shows a temporary message banner/ribbon for a few seconds, or
36+
// a permanent error message on top of the canvas if type=='error'.
37+
// If type=='warning', a yellow highlight color is used.
38+
// Modify or remove this function to customize the visually presented
39+
// way that non-critical warnings and error messages are presented to the
40+
// user.
41+
function unityShowBanner(msg, type) {
42+
function updateBannerVisibility() {
43+
warningBanner.style.display = warningBanner.children.length ? 'block' : 'none';
44+
}
45+
var div = document.createElement('div');
46+
div.innerHTML = msg;
47+
warningBanner.appendChild(div);
48+
if (type == 'error') div.style = 'background: red; padding: 10px;';
49+
else {
50+
if (type == 'warning') div.style = 'background: yellow; padding: 10px;';
51+
setTimeout(function() {
52+
warningBanner.removeChild(div);
53+
updateBannerVisibility();
54+
}, 5000);
55+
}
56+
updateBannerVisibility();
57+
}
58+
59+
var buildUrl = "Build";
60+
var loaderUrl = buildUrl + "/WebGL.loader.js";
61+
var config = {
62+
dataUrl: buildUrl + "/WebGL.data.br",
63+
frameworkUrl: buildUrl + "/WebGL.framework.js.br",
64+
codeUrl: buildUrl + "/WebGL.wasm.br",
65+
streamingAssetsUrl: "StreamingAssets",
66+
companyName: "DefaultCompany",
67+
productName: "Puzzle-1-Task",
68+
productVersion: "0.1.0",
69+
showBanner: unityShowBanner,
70+
};
71+
72+
// By default, Unity keeps WebGL canvas render target size matched with
73+
// the DOM size of the canvas element (scaled by window.devicePixelRatio)
74+
// Set this to false if you want to decouple this synchronization from
75+
// happening inside the engine, and you would instead like to size up
76+
// the canvas DOM size and WebGL render target sizes yourself.
77+
// config.matchWebGLToCanvasSize = false;
78+
79+
// If you would like all file writes inside Unity Application.persistentDataPath
80+
// directory to automatically persist so that the contents are remembered when
81+
// the user revisits the site the next time, uncomment the following line:
82+
// config.autoSyncPersistentDataPath = true;
83+
// This autosyncing is currently not the default behavior to avoid regressing
84+
// existing user projects that might rely on the earlier manual
85+
// JS_FileSystem_Sync() behavior, but in future Unity version, this will be
86+
// expected to change.
87+
88+
if (/iPhone|iPad|iPod|Android/i.test(navigator.userAgent)) {
89+
// Mobile device style: fill the whole browser client area with the game canvas:
90+
91+
var meta = document.createElement('meta');
92+
meta.name = 'viewport';
93+
meta.content = 'width=device-width, height=device-height, initial-scale=1.0, user-scalable=no, shrink-to-fit=yes';
94+
document.getElementsByTagName('head')[0].appendChild(meta);
95+
container.className = "unity-mobile";
96+
canvas.className = "unity-mobile";
97+
98+
// To lower canvas resolution on mobile devices to gain some
99+
// performance, uncomment the following line:
100+
// config.devicePixelRatio = 1;
101+
102+
103+
} else {
104+
// Desktop style: Render the game canvas in a window that can be maximized to fullscreen:
105+
106+
canvas.style.width = "960px";
107+
canvas.style.height = "600px";
108+
}
109+
110+
loadingBar.style.display = "block";
111+
112+
var script = document.createElement("script");
113+
script.src = loaderUrl;
114+
script.onload = () => {
115+
createUnityInstance(canvas, config, (progress) => {
116+
progressBarFull.style.width = 100 * progress + "%";
117+
}).then((unityInstance) => {
118+
loadingBar.style.display = "none";
119+
fullscreenButton.onclick = () => {
120+
unityInstance.SetFullscreen(1);
121+
};
122+
}).catch((message) => {
123+
alert(message);
124+
});
125+
};
126+
127+
document.body.appendChild(script);
128+
129+
</script>
130+
</body>
131+
</html>

0 commit comments

Comments
 (0)