-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathindex.html
More file actions
161 lines (155 loc) · 5.1 KB
/
Copy pathindex.html
File metadata and controls
161 lines (155 loc) · 5.1 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
<!DOCTYPE html>
<html lang="en-us">
<head>
<base href="https://cdn.jsdelivr.net/gh/web-ports/jsab@372b6ad58c88f69f1faaa9223c5993ae488c1032/">
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Unity WebGL Player | JSB</title>
<link rel="shortcut icon" href="TemplateData/favicon.ico">
<link rel="stylesheet" href="TemplateData/style.css">
<script src="TemplateData/UnityProgress.js"></script>
<script src="Build/UnityLoader.js"></script>
<style>
body {
cursor: url('Cursor.png'), auto;
background-color: black;
margin: 0;
padding: 0;
overflow: hidden;
}
#unityContainer {
width: 100vw !important;
height: 100vh !important;
}
canvas {
width: 100% !important;
height: 100% !important;
}
#loading-text {
position: fixed;
top: 20px;
left: 50%;
transform: translateX(-50%);
z-index: 999999;
font-size: 48px;
font-family: cursive;
font-weight: bold;
pointer-events: none;
background: linear-gradient(
270deg,
#ff0000,
#ff7f00,
#ffff00,
#00ff00,
#0000ff,
#4b0082,
#8f00ff
);
background-size: 400% 400%;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
animation: rainbow 3s ease infinite;
}
@keyframes rainbow {
0% { background-position: 0% 50%; }
50% { background-position: 100% 50%; }
100% { background-position: 0% 50%; }
}
</style>
</head>
<body>
<div id="loading-text"
style="color: white; font-size: 48px; font-family: cursive; text-align: center; margin-top: 20px;"> LOADING...
</div>
<div class="webgl-content">
<div id="unityContainer"></div>
</div>
<script>
var loadingText = document.querySelector("#loading-text");
let totalBytes = 0;
let loadedBytes = 0;
async function fetchWithProgress(url) {
const response = await fetch(url);
const reader = response.body.getReader();
let chunks = [];
let received = 0;
while (true) {
const {
done,
value
} = await reader.read();
if (done) break;
received += value.length;
loadedBytes += value.length;
chunks.push(value);
let mbDone = (loadedBytes / (1024 * 1024)).toFixed(2);
let mbTotal = '132.83';
loadingText.textContent = `LOADING... ${mbDone} MB / ${mbTotal} MB`;
}
let fullBuffer = new Uint8Array(received);
let offset = 0;
for (let chunk of chunks) {
fullBuffer.set(chunk, offset);
offset += chunk.length;
}
return fullBuffer.buffer;
}
async function mergeFiles(fileParts, cacheKey) {
const cache = await caches.open("jsab-cache");
const cachedResponse = await cache.match(cacheKey);
if (cachedResponse) {
const blob = await cachedResponse.blob();
return URL.createObjectURL(blob);
}
const buffers = await Promise.all(
fileParts.map(part => fetchWithProgress(part))
);
const mergedBlob = new Blob(buffers);
const response = new Response(mergedBlob);
await cache.put(cacheKey, response);
return URL.createObjectURL(mergedBlob);
}
function getParts(file, start, end) {
let parts = [];
for (let i = start; i <= end; i++) {
parts.push(file + ".part" + i);
}
return parts;
}
(async () => {
const [dataUrl, wasmUrl, bundle] = await Promise.all([
mergeFiles(getParts("Build/jsab.data.unityweb", 1, 4), "jsab.data.unityweb"),
mergeFiles(getParts("Build/jsab.wasm.code.unityweb", 1, 2), "jsab.wasm.code.unityweb"),
mergeFiles(getParts("StreamingAssets/aa/WebGL/fonts_tmp_assets_all_c2712a523e390d12249a703a5257c93b.bundle", 1, 3), "fonts_tmp_assets_all_c2712a523e390d12249a703a5257c93b.bundle"),
]);
const originalOpen = XMLHttpRequest.prototype.open;
const originalSend = XMLHttpRequest.prototype.send;
XMLHttpRequest.prototype.open = function (method, url, ...rest) {
this._requestUrl = url;
if (url.includes("jsab.data.unityweb")) {
url = dataUrl;
} else if (url.includes("jsab.wasm.code.unityweb")) {
url = wasmUrl;
} else if (url.includes("fonts_tmp_assets_all_c2712a523e390d12249a703a5257c93b.bundle")) {
url = bundle;
} else if (url.includes(".bundle")) {
loadingText.style.display = "block";
loadingText.textContent = url.split("/").pop().replace(".bundle", "");
}
this._modifiedUrl = url;
return originalOpen.call(this, method, url, ...rest);
};
XMLHttpRequest.prototype.send = function (...args) {
if (this._requestUrl && this._requestUrl.includes(".bundle")) {
this.addEventListener("loadend", () => {
loadingText.style.display = "none";
});
}
return originalSend.apply(this, args);
};
var unityInstance = UnityLoader.instantiate("unityContainer", "Build/jsab.json", {onProgress: UnityProgress});
loadingText.style.display = "none";
})();
</script>
</body>
</html>