Improve exam flow and WebGL build

This commit is contained in:
yangbear
2026-07-17 05:42:52 +08:00
parent 9b4690d396
commit bd76dfd9ec
34 changed files with 89955 additions and 8244 deletions
+56 -11
View File
@@ -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";'