Improve exam flow and WebGL build
This commit is contained in:
Vendored
BIN
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+3
-24
@@ -1,9 +1,9 @@
|
||||
const cacheName = "DefaultCompany-运动伤害现场急救虚拟仿真实验-0.1.0";
|
||||
const contentToCache = [
|
||||
"Build/7a2dbded24d57e056180125b1583e7c4.loader.js",
|
||||
"Build/62981e01aece13a94bac539c85228c75.framework.js.gz",
|
||||
"Build/d1e2d1e3e120229ced20d8237eae353c.data.gz",
|
||||
"Build/e89ebbd31642308ad16cecffa889584e.wasm.gz",
|
||||
"Build/360830ff1fc916f53a94ba2fa3fd0d8f.framework.js.gz",
|
||||
"Build/1ffb9ec7407d7ad0a61ab4035c55d23d.data.gz",
|
||||
"Build/fcc5cc41937245b03571180d2961701c.wasm.gz",
|
||||
"TemplateData/style.css"
|
||||
|
||||
];
|
||||
@@ -15,32 +15,11 @@ self.addEventListener('install', function (e) {
|
||||
const cache = await caches.open(cacheName);
|
||||
console.log('[Service Worker] Caching all: app shell and content');
|
||||
await cache.addAll(contentToCache);
|
||||
await self.skipWaiting();
|
||||
})());
|
||||
});
|
||||
|
||||
self.addEventListener('activate', function (e) {
|
||||
e.waitUntil((async function () {
|
||||
const keys = await caches.keys();
|
||||
await Promise.all(keys.map(function (key) {
|
||||
return key === cacheName ? Promise.resolve() : caches.delete(key);
|
||||
}));
|
||||
await self.clients.claim();
|
||||
})());
|
||||
});
|
||||
|
||||
self.addEventListener('fetch', function (e) {
|
||||
if (e.request.method !== 'GET') {
|
||||
return;
|
||||
}
|
||||
|
||||
e.respondWith((async function () {
|
||||
const url = new URL(e.request.url);
|
||||
const isBuildAsset = url.pathname.includes('/Build/') || url.pathname.includes('/StreamingAssets/');
|
||||
if (!isBuildAsset && !url.pathname.endsWith('/TemplateData/style.css')) {
|
||||
return fetch(e.request);
|
||||
}
|
||||
|
||||
let response = await caches.match(e.request);
|
||||
console.log(`[Service Worker] Fetching resource: ${e.request.url}`);
|
||||
if (response) { return response; }
|
||||
|
||||
+3
-11
@@ -59,9 +59,9 @@
|
||||
var buildUrl = "Build";
|
||||
var loaderUrl = buildUrl + "/7a2dbded24d57e056180125b1583e7c4.loader.js";
|
||||
var config = {
|
||||
dataUrl: buildUrl + "/d1e2d1e3e120229ced20d8237eae353c.data.gz",
|
||||
frameworkUrl: buildUrl + "/62981e01aece13a94bac539c85228c75.framework.js.gz",
|
||||
codeUrl: buildUrl + "/e89ebbd31642308ad16cecffa889584e.wasm.gz",
|
||||
dataUrl: buildUrl + "/1ffb9ec7407d7ad0a61ab4035c55d23d.data.gz",
|
||||
frameworkUrl: buildUrl + "/360830ff1fc916f53a94ba2fa3fd0d8f.framework.js.gz",
|
||||
codeUrl: buildUrl + "/fcc5cc41937245b03571180d2961701c.wasm.gz",
|
||||
streamingAssetsUrl: "StreamingAssets",
|
||||
companyName: "DefaultCompany",
|
||||
productName: "运动伤害现场急救虚拟仿真实验",
|
||||
@@ -69,14 +69,6 @@
|
||||
showBanner: unityShowBanner,
|
||||
};
|
||||
|
||||
config.cacheControl = function (url) {
|
||||
if (url === config.dataUrl || url === config.frameworkUrl || url === config.codeUrl) {
|
||||
return "immutable";
|
||||
}
|
||||
return "must-revalidate";
|
||||
};
|
||||
config.devicePixelRatio = Math.min(window.devicePixelRatio || 1, 1.5);
|
||||
|
||||
// By default Unity keeps WebGL canvas render target size matched with
|
||||
// the DOM size of the canvas element (scaled by window.devicePixelRatio)
|
||||
// Set this to false if you want to decouple this synchronization from
|
||||
|
||||
+56
-11
@@ -120,23 +120,39 @@ function serveIndex(res) {
|
||||
html, body {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
background: #0d0a0b;
|
||||
background: #000;
|
||||
overscroll-behavior: none;
|
||||
touch-action: none;
|
||||
}
|
||||
body {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
}
|
||||
#unity-container {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: #0d0a0b;
|
||||
left: 50%;
|
||||
top: 50%;
|
||||
width: min(100vw, calc(100vh * 16 / 9));
|
||||
height: min(100vh, calc(100vw * 9 / 16));
|
||||
transform: translate(-50%, -50%);
|
||||
overflow: hidden;
|
||||
background: #000;
|
||||
}
|
||||
#unity-canvas {
|
||||
width: min(100vw, 177.7778vh) !important;
|
||||
height: min(56.25vw, 100vh) !important;
|
||||
aspect-ratio: 16 / 9;
|
||||
background: #231f20;
|
||||
display: block;
|
||||
width: 100% !important;
|
||||
height: 100% !important;
|
||||
background: #231f20;
|
||||
touch-action: none;
|
||||
}
|
||||
@supports (height: 100dvh) {
|
||||
#unity-container {
|
||||
width: min(100vw, calc(100dvh * 16 / 9));
|
||||
height: min(100dvh, calc(100vw * 9 / 16));
|
||||
}
|
||||
}
|
||||
#unity-loading-bar {
|
||||
left: 50% !important;
|
||||
@@ -278,6 +294,11 @@ function serveIndex(res) {
|
||||
|| el.msRequestFullscreen || el.mozRequestFullScreen;
|
||||
|
||||
function go() {
|
||||
if (screen.orientation && screen.orientation.lock) {
|
||||
screen.orientation.lock('landscape').catch(function(err) {
|
||||
console.warn('横屏锁定失败:', err);
|
||||
});
|
||||
}
|
||||
overlay.classList.add('hidden');
|
||||
}
|
||||
|
||||
@@ -297,18 +318,42 @@ function serveIndex(res) {
|
||||
/progressBarFull\.style\.width\s*=\s*100\s*\*\s*progress\s*\+\s*"%";/,
|
||||
'progressBarFull.style.width = 100 * progress + "%"; if (window.__landingSetProgress) window.__landingSetProgress(progress);'
|
||||
);
|
||||
if (!html.includes('name="viewport"')) {
|
||||
html = html.replace(
|
||||
'<meta http-equiv="Content-Type" content="text/html; charset=utf-8">',
|
||||
'<meta http-equiv="Content-Type" content="text/html; charset=utf-8">\\n <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover">'
|
||||
);
|
||||
}
|
||||
html = html.replace(
|
||||
/<canvas id="unity-canvas"[^>]*><\/canvas>/,
|
||||
'<canvas id="unity-canvas" width=1920 height=1080 tabindex="-1"></canvas>'
|
||||
);
|
||||
if (!html.includes('config.cacheControl')) {
|
||||
html = html.replace(
|
||||
/showBanner:\s*unityShowBanner,\s*\n\s*};/,
|
||||
'showBanner: unityShowBanner,\n };\n\n config.cacheControl = function (url) {\n if (url === config.dataUrl || url === config.frameworkUrl || url === config.codeUrl) {\n return "immutable";\n }\n return "must-revalidate";\n };'
|
||||
);
|
||||
}
|
||||
html = html.replace(
|
||||
/config\.devicePixelRatio\s*=\s*[^;]+;/,
|
||||
'config.devicePixelRatio = 1;'
|
||||
);
|
||||
if (!html.includes('config.devicePixelRatio')) {
|
||||
html = html.replace(
|
||||
/};\s*\n\s*\/\/ By default Unity keeps WebGL canvas render target size matched with/,
|
||||
'};\n config.devicePixelRatio = Math.min(window.devicePixelRatio || 1, 1.5);\n\n // By default Unity keeps WebGL canvas render target size matched with'
|
||||
'};\n config.devicePixelRatio = 1;\n\n // By default Unity keeps WebGL canvas render target size matched with'
|
||||
);
|
||||
}
|
||||
if (!html.includes('config.matchWebGLToCanvasSize = false;')) {
|
||||
html = html.replace(
|
||||
/config\.devicePixelRatio\s*=\s*1;/,
|
||||
'config.devicePixelRatio = 1;\n config.matchWebGLToCanvasSize = false;\n var UNITY_DESIGN_WIDTH = 1920;\n var UNITY_DESIGN_HEIGHT = 1080;\n function lockUnityCanvasResolution() {\n canvas.width = UNITY_DESIGN_WIDTH;\n canvas.height = UNITY_DESIGN_HEIGHT;\n }\n lockUnityCanvasResolution();\n window.addEventListener("resize", lockUnityCanvasResolution);\n window.addEventListener("orientationchange", function () { setTimeout(lockUnityCanvasResolution, 150); });\n document.addEventListener("fullscreenchange", lockUnityCanvasResolution);'
|
||||
);
|
||||
}
|
||||
html = html.replace(
|
||||
/if \(\s*\/iPhone\|iPad\|iPod\|Android\/i\.test\(navigator\.userAgent\)\s*\)\s*\{[\s\S]*?document\.getElementsByTagName\('head'\)\[0\]\.appendChild\(meta\);\s*\}/,
|
||||
''
|
||||
);
|
||||
html = html.replace(
|
||||
/loadingBar\.style\.display\s*=\s*"none";/,
|
||||
'if (window.__landingSetReady) window.__landingSetReady(); loadingBar.style.display = "none";'
|
||||
|
||||
Reference in New Issue
Block a user