no message

This commit is contained in:
2026-06-16 16:27:02 +08:00
parent 6e0a1fbcbb
commit 33070ad827
2436 changed files with 183 additions and 1746 deletions

View File

@@ -0,0 +1,55 @@
import CONFIG from '../playground/config.js';
/**
* 纯 CDN 根路径。
* 方案 A默认始终返回 unityCdnRemote浏览器直连 OSS须配置 OSS CORS
* 方案 BunityCdnUseSiteProxy / unityCdnUseDevProxy 为 true 时走 /cdn-unity 同源代理。
*/
export function getUnityCdnRoot() {
if (!CONFIG.usecdn) {
return '/unity';
}
const useProxy = CONFIG.unityCdnUseSiteProxy || CONFIG.unityCdnUseDevProxy;
if (useProxy && CONFIG.unityCdnDevProxy) {
return CONFIG.unityCdnDevProxy;
}
return CONFIG.unityCdnRemote || CONFIG.unitycdndir;
}
export function getUnityCdnBuildRoot() {
return `${getUnityCdnRoot()}/Build`;
}
/** 预取关卡库并注入,避免 LevelDatabase 回退到 /unity/ 或 editor 相对路径 */
export async function prefetchLevelsDatabase(cdnRoot) {
const root = String(cdnRoot || getUnityCdnRoot()).replace(/\/$/, '');
const jsonUrl = `${root}/levels-database.json`;
window.__tfrhLevelsDatabaseUrl = jsonUrl;
if (window.__tfrhLevelsDatabaseJson) {
return;
}
const brUrl = jsonUrl.replace(/\.json(\?.*)?$/i, '.json.br$1');
if (typeof DecompressionStream !== 'undefined') {
try {
const brRes = await fetch(brUrl);
if (brRes.ok) {
const text = await new Response(await brRes.arrayBuffer())
.pipeThrough(new DecompressionStream('brotli'))
.text();
window.__tfrhLevelsDatabaseJson = JSON.parse(text);
return;
}
} catch (e) {
console.warn('[unity-cdn] levels-database.json.br 预取失败,尝试 .json', e);
}
}
const res = await fetch(jsonUrl);
if (!res.ok) {
throw new Error(`levels-database HTTP ${res.status}: ${jsonUrl}`);
}
window.__tfrhLevelsDatabaseJson = await res.json();
}