Skip to content

Commit 0dcf99c

Browse files
committed
add logo/spinner/progress
1 parent 179829a commit 0dcf99c

File tree

2 files changed

+110
-7
lines changed

2 files changed

+110
-7
lines changed

Assets/WebGLTemplates/BetterTemplate/index.html

Lines changed: 105 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,119 @@
33

44
<head>
55
<meta charset="utf-8">
6-
<title>%UNITY_WEB_NAME%</title>
6+
<title>WebGLFitWindow</title>
77
<style>
8-
body { margin: 0; }
9-
#gameContainer { width: 100vw; height: 100vh; }
10-
canvas { width: 100%; height: 100%; display: block; }
8+
html {
9+
box-sizing: border-box;
10+
}
11+
*, *:before, *:after {
12+
box-sizing: inherit;
13+
}
14+
body {
15+
margin: 0;
16+
background: #444;
17+
}
18+
#gameContainer {
19+
width: 100vw;
20+
height: 100vh;
21+
}
22+
canvas {
23+
width: 100%;
24+
height: 100%;
25+
display: block;
26+
}
27+
28+
.logo {
29+
width: 50vw;
30+
height: 33vh;
31+
background-image: url(logo.png);
32+
background-position: bottom center;
33+
background-size: contain;
34+
background-repeat: no-repeat;
35+
}
36+
37+
.progress {
38+
margin: 1.5em;
39+
border: 1px solid white;
40+
width: 50vw;
41+
display: none;
42+
}
43+
.progress .full {
44+
margin: 2px;
45+
background: white;
46+
height: 1em;
47+
transform-origin: top left;
48+
}
49+
50+
#loader {
51+
position: absolute;
52+
left: 0;
53+
top: 0;
54+
width: 100vw;
55+
height: 100vh;
56+
display: flex;
57+
flex-direction: column;
58+
align-items: center;
59+
justify-content: center;
60+
}
61+
62+
.spinner,
63+
.spinner:after {
64+
border-radius: 50%;
65+
width: 5em;
66+
height: 5em;
67+
}
68+
.spinner {
69+
margin: 10px;
70+
font-size: 10px;
71+
position: relative;
72+
text-indent: -9999em;
73+
border-top: 1.1em solid rgba(255, 255, 255, 0.2);
74+
border-right: 1.1em solid rgba(255, 255, 255, 0.2);
75+
border-bottom: 1.1em solid rgba(255, 255, 255, 0.2);
76+
border-left: 1.1em solid #ffffff;
77+
transform: translateZ(0);
78+
animation: spinner-spin 1.1s infinite linear;
79+
}
80+
@keyframes spinner-spin {
81+
0% {
82+
transform: rotate(0deg);
83+
}
84+
100% {
85+
transform: rotate(360deg);
86+
}
87+
}
88+
1189
</style>
12-
<script src="%UNITY_WEBGL_LOADER_URL%"></script>
90+
<script src="Build/UnityLoader.js"></script>
1391
<script>
14-
var gameInstance = UnityLoader.instantiate("gameContainer", "%UNITY_WEBGL_BUILD_URL%");
92+
var gameInstance = UnityLoader.instantiate("gameContainer", "Build/dist.json", {onProgress: UnityProgress});
93+
function UnityProgress(gameInstance, progress) {
94+
if (!gameInstance.Module) {
95+
return;
96+
}
97+
const loader = document.querySelector("#loader");
98+
if (!gameInstance.progress) {
99+
const progress = document.querySelector("#loader .progress");
100+
progress.style.display = "block";
101+
gameInstance.progress = progress.querySelector(".full");
102+
loader.querySelector(".spinner").style.display = "none";
103+
}
104+
gameInstance.progress.style.transform = `scaleX(${progress})`;
105+
if (progress === 1) {
106+
loader.style.display = "none";
107+
}
108+
}
15109
</script>
16110
</head>
17111

18112
<body>
19113
<div id="gameContainer"></div>
114+
<div id="loader">
115+
<div class="logo"></div>
116+
<div class="spinner"></div>
117+
<div class="progress"><div class="full"></div></div>
118+
</div>
20119
</body>
21120

22121
</html>

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@
22

33
I have no idea why Unity choose to not make its WebGL exporter default
44
to filling the window like pretty much all other WebGL apps on the net
5-
but in any case here is a minimal template
5+
but in any case here is a template
66

77
Example: https://greggman.github.io/better-unity-webgl-template/
88

9+
## Instructions
10+
911
The short version is you just need the `Assets/WebGLTemplates/BetterTemplate` folder
1012
in your project. Then pick `Edit->Project Settings->Player`, in the WebGL tab
1113
under *Resolution and Presentation* pick "BetterTemplate".
1214

1315
<img src="https://i.stack.imgur.com/r5Jns.png" width="358">
1416

17+
Change `Assets/WebGLTemplates/BetterTemplate/logo.png` to whatever you want.
18+
1519

0 commit comments

Comments
 (0)