Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
173 lines (152 loc) · 5.17 KB
/
Copy pathindex.html
File metadata and controls
173 lines (152 loc) · 5.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>ReactUnity Previewer</title>
<link rel="icon" href="./favicon.ico">
<style>
html,
body {
font-size: 0;
margin: 0;
height: 100%;
overflow: hidden;
}
#unity-canvas {
height: 100%;
width: 100%;
background: #231F20;
}
.loader-center {
position: absolute;
left: 0;
right: 0;
top: 50%;
height: 0;
overflow: visible;
display: block;
pointer-events: none;
user-select: none;
-webkit-user-select: none;
}
.loader {
position: absolute;
height: 50px;
top: -25px;
left: 50px;
right: 50px;
background: #c5cae9;
border-radius: 10px;
overflow: hidden;
}
.loader-bar {
height: 100%;
background: #3f51b5;
width: 0;
}
#error {
display: none;
position: absolute;
inset: 0;
overflow: auto;
padding: 3rem 1.5rem;
background: #fff;
color: #231F20;
font: 16px/1.5 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}
#error>div {
max-width: 40rem;
margin: 0 auto;
}
#error h1 {
font-size: 1.5rem;
margin: 0 0 1rem;
}
#error code {
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
background: #f1f1f4;
padding: .1em .3em;
border-radius: 3px;
}
</style>
</head>
<body>
<canvas id="unity-canvas"></canvas>
<div class="loader-center" id="loader-root">
<div class="loader">
<div class="loader-bar" id="loader-bar"></div>
</div>
</div>
<div id="error">
<div>
<h1>Couldn't load the previewer</h1>
<p>
The previewer's Unity WebGL build is hosted rather than bundled, so the first load needs
network access. It is cached by the browser afterwards.
</p>
<p>
To work offline, or to preview your own Unity scene instead, build a scene with a
<code>ReactRendererUGUI</code> component and copy the output into a <code>previewer</code>
folder in your React project, so that <code>previewer/index.html</code> exists. The dev
server prefers that over this page.
</p>
<p><a href="./info.html">More about the previewer and the dev server</a></p>
</div>
</div>
<script>
/*
* The Unity build lives on reactunity.github.io rather than in an npm package: it is
* ~26 MB, and shipping it as a dependency meant every install paid for it. GitHub Pages
* sends `Access-Control-Allow-Origin: *`, so a cross-origin fetch from this dev server
* is fine.
*
* `.unityweb` is Unity's name for "gzipped, and the loader inflates it itself". Pages
* cannot be told to send `Content-Encoding`, so the alternative is shipping the files
* raw, which is three times the download. It costs streaming compilation.
*
* The version is part of the path on purpose. Unity's loader, framework and wasm are
* built as a set and are not interchangeable, so each build gets its own directory and
* nothing is ever overwritten. It names the release the build ships in, not the day it
* was made. Publishing a new previewer build means adding a directory on that branch and
* bumping the version here -- in that order, or every dev server in the wild asks for a
* directory that is not there yet.
*/
var PREVIEWER_VERSION = '0.24.0';
var PREVIEWER_BASE = 'https://reactunity.github.io/Unity/previewer/' + PREVIEWER_VERSION + '/Build/';
function fail() {
document.getElementById('loader-root').style.display = 'none';
document.getElementById('error').style.display = 'block';
}
function onProgress(progress) {
var bar = document.getElementById('loader-bar');
if (bar) bar.style.width = (progress * 100) + '%';
var loader = document.getElementById('loader-root');
if (loader) loader.style.display = progress < 1 ? 'block' : 'none';
}
/*
* Unity's loader is a plain script defining a global `createUnityInstance`, so it has to
* be appended rather than imported.
*/
var loader = document.createElement('script');
loader.src = PREVIEWER_BASE + 'Previewer.loader.js';
loader.onerror = fail;
loader.onload = () => {
if (typeof createUnityInstance !== 'function') return fail();
createUnityInstance(document.getElementById('unity-canvas'), {
dataUrl: PREVIEWER_BASE + 'Previewer.data.unityweb',
frameworkUrl: PREVIEWER_BASE + 'Previewer.framework.js.unityweb',
codeUrl: PREVIEWER_BASE + 'Previewer.wasm.unityweb',
// Absolute like the rest. Left relative it would resolve against this dev server,
// which has no StreamingAssets to serve.
streamingAssetsUrl: PREVIEWER_BASE + '../StreamingAssets',
companyName: 'reactunity',
productName: 'dev-sample',
productVersion: PREVIEWER_VERSION,
}, onProgress).catch(fail);
};
document.head.appendChild(loader);
</script>
</body>
</html>