no message
This commit is contained in:
@@ -4,6 +4,7 @@ import VM from 'scratch-vm';
|
||||
import Box from '../box/box.jsx';
|
||||
import { STAGE_DISPLAY_SIZES } from '../../lib/layout-constants.js';
|
||||
import CONFIG from '../../playground/config.js'; // 引入 config.js
|
||||
import { getUnityCdnRoot, getUnityCdnBuildRoot, prefetchLevelsDatabase } from '../../lib/unity-cdn.js';
|
||||
import RankBadgeGenerator from '../../playground/rank-badge-generator.js';
|
||||
// import FriendToggle from '../friend-toggle/FriendToggle.js';
|
||||
// import FriendListModal from '../friend-toggle/FriendListModal.js';
|
||||
@@ -1230,10 +1231,11 @@ const UnityComponent = function (props) {
|
||||
// if (canvas && !window.unityInstance) {
|
||||
const unityUrl = "/unity";
|
||||
const buildUrl = "/unity/Build";
|
||||
const cdnurt = CONFIG.unitycdndir;
|
||||
const cdnbuildurl = CONFIG.unitycdnbuilddir;
|
||||
const noneurl = ''
|
||||
const loaderUrl = buildUrl + "/mstest5.loader.js";
|
||||
const cdnRoot = CONFIG.usecdn ? getUnityCdnRoot() : unityUrl;
|
||||
const cdnBuildRoot = CONFIG.usecdn ? getUnityCdnBuildRoot() : buildUrl;
|
||||
let loaderUrl = CONFIG.usecdn
|
||||
? `${cdnBuildRoot}/mstest5.loader.js`
|
||||
: `${buildUrl}/mstest5.loader.js`;
|
||||
let config = {
|
||||
dataUrl: buildUrl + "/mstest5.data.br",
|
||||
frameworkUrl: buildUrl + "/mstest5.framework.js.br",
|
||||
@@ -1245,10 +1247,10 @@ const UnityComponent = function (props) {
|
||||
};
|
||||
if (CONFIG.usecdn) {
|
||||
config = {
|
||||
dataUrl: cdnbuildurl + "/mstest5.data.br",
|
||||
frameworkUrl: cdnbuildurl + "/mstest5.framework.js.br",
|
||||
codeUrl: cdnbuildurl + "/mstest5.wasm.br",
|
||||
streamingAssetsUrl: cdnurt + "/StreamingAssets",
|
||||
dataUrl: cdnBuildRoot + "/mstest5.data.br",
|
||||
frameworkUrl: cdnBuildRoot + "/mstest5.framework.js.br",
|
||||
codeUrl: cdnBuildRoot + "/mstest5.wasm.br",
|
||||
streamingAssetsUrl: cdnRoot + "/StreamingAssets",
|
||||
// dataUrl: buildUrl + "/Build.data.br",
|
||||
// frameworkUrl: buildUrl + "/Build.framework.js.br",
|
||||
// codeUrl: buildUrl + "/Build.wasm.br",
|
||||
@@ -1264,9 +1266,10 @@ const UnityComponent = function (props) {
|
||||
|
||||
script.onload = () => {
|
||||
window.iscreate = 0;
|
||||
createUnityInstance(canvas, config, (progress) => {
|
||||
// console.log(`加载进度: ${progress * 100}%`);
|
||||
}).then((unityInstance) => {
|
||||
const boot = () => {
|
||||
createUnityInstance(canvas, config, (progress) => {
|
||||
// console.log(`加载进度: ${progress * 100}%`);
|
||||
}).then((unityInstance) => {
|
||||
window.unityInstance = unityInstance;
|
||||
window.waitForUnityStepFinish = waitForUnityStepFinish;
|
||||
window.waitForUnityVehicleStepFinish = waitForUnityVehicleStepFinish;
|
||||
@@ -1289,6 +1292,15 @@ const UnityComponent = function (props) {
|
||||
}).catch((message) => {
|
||||
console.error(`Unity 实例创建失败: ${message}`);
|
||||
});
|
||||
};
|
||||
if (CONFIG.usecdn) {
|
||||
prefetchLevelsDatabase(cdnRoot).then(boot).catch((err) => {
|
||||
console.error('[unity-cdn] 关卡库预取失败', err);
|
||||
boot();
|
||||
});
|
||||
} else {
|
||||
boot();
|
||||
}
|
||||
};
|
||||
|
||||
document.body.appendChild(script);
|
||||
|
||||
@@ -4,6 +4,7 @@ import VM from 'scratch-vm';
|
||||
import Box from '../box/box.jsx';
|
||||
import { STAGE_DISPLAY_SIZES } from '../../lib/layout-constants.js';
|
||||
import CONFIG from '../../playground/config.js'; // 引入 config.js
|
||||
import { getUnityCdnRoot, getUnityCdnBuildRoot, prefetchLevelsDatabase } from '../../lib/unity-cdn.js';
|
||||
import RankBadgeGenerator from '../../playground/rank-badge-generator.js';
|
||||
// import FriendToggle from '../friend-toggle/FriendToggle.js';
|
||||
// import FriendListModal from '../friend-toggle/FriendListModal.js';
|
||||
@@ -1219,10 +1220,11 @@ const UnityComponent = function (props) {
|
||||
// if (canvas && !window.unityInstance) {
|
||||
const unityUrl = "/unity";
|
||||
const buildUrl = "/unity/Build";
|
||||
const cdnurt = CONFIG.unitycdndir;
|
||||
const cdnbuildurl = CONFIG.unitycdnbuilddir;
|
||||
const noneurl = ''
|
||||
const loaderUrl = buildUrl + "/mstest5.loader.js";
|
||||
const cdnRoot = CONFIG.usecdn ? getUnityCdnRoot() : unityUrl;
|
||||
const cdnBuildRoot = CONFIG.usecdn ? getUnityCdnBuildRoot() : buildUrl;
|
||||
let loaderUrl = CONFIG.usecdn
|
||||
? `${cdnBuildRoot}/mstest5.loader.js`
|
||||
: `${buildUrl}/mstest5.loader.js`;
|
||||
let config = {
|
||||
dataUrl: buildUrl + "/mstest5.data.br",
|
||||
frameworkUrl: buildUrl + "/mstest5.framework.js.br",
|
||||
@@ -1234,10 +1236,10 @@ const UnityComponent = function (props) {
|
||||
};
|
||||
if (CONFIG.usecdn) {
|
||||
config = {
|
||||
dataUrl: cdnbuildurl + "/mstest5.data.br",
|
||||
frameworkUrl: cdnbuildurl + "/mstest5.framework.js.br",
|
||||
codeUrl: cdnbuildurl + "/mstest5.wasm.br",
|
||||
streamingAssetsUrl: cdnurt + "/StreamingAssets",
|
||||
dataUrl: cdnBuildRoot + "/mstest5.data.br",
|
||||
frameworkUrl: cdnBuildRoot + "/mstest5.framework.js.br",
|
||||
codeUrl: cdnBuildRoot + "/mstest5.wasm.br",
|
||||
streamingAssetsUrl: cdnRoot + "/StreamingAssets",
|
||||
// dataUrl: buildUrl + "/Build.data.br",
|
||||
// frameworkUrl: buildUrl + "/Build.framework.js.br",
|
||||
// codeUrl: buildUrl + "/Build.wasm.br",
|
||||
@@ -1253,9 +1255,10 @@ const UnityComponent = function (props) {
|
||||
|
||||
script.onload = () => {
|
||||
window.iscreate = 0;
|
||||
createUnityInstance(canvas, config, (progress) => {
|
||||
// console.log(`加载进度: ${progress * 100}%`);
|
||||
}).then((unityInstance) => {
|
||||
const boot = () => {
|
||||
createUnityInstance(canvas, config, (progress) => {
|
||||
// console.log(`加载进度: ${progress * 100}%`);
|
||||
}).then((unityInstance) => {
|
||||
window.unityInstance = unityInstance;
|
||||
window.waitForUnityStepFinish = waitForUnityStepFinish;
|
||||
window.waitForUnityVehicleStepFinish = waitForUnityVehicleStepFinish;
|
||||
@@ -1278,6 +1281,15 @@ const UnityComponent = function (props) {
|
||||
}).catch((message) => {
|
||||
console.error(`Unity 实例创建失败: ${message}`);
|
||||
});
|
||||
};
|
||||
if (CONFIG.usecdn) {
|
||||
prefetchLevelsDatabase(cdnRoot).then(boot).catch((err) => {
|
||||
console.error('[unity-cdn] 关卡库预取失败', err);
|
||||
boot();
|
||||
});
|
||||
} else {
|
||||
boot();
|
||||
}
|
||||
};
|
||||
|
||||
document.body.appendChild(script);
|
||||
|
||||
@@ -4,6 +4,7 @@ import VM from 'scratch-vm';
|
||||
import Box from '../box/box.jsx';
|
||||
import { STAGE_DISPLAY_SIZES } from '../../lib/layout-constants.js';
|
||||
import CONFIG from '../../playground/config.js'; // 引入 config.js
|
||||
import { getUnityCdnRoot, getUnityCdnBuildRoot, prefetchLevelsDatabase } from '../../lib/unity-cdn.js';
|
||||
import RankBadgeGenerator from '../../playground/rank-badge-generator.js';
|
||||
// import FriendToggle from '../friend-toggle/FriendToggle.js';
|
||||
// import FriendListModal from '../friend-toggle/FriendListModal.js';
|
||||
@@ -1482,10 +1483,11 @@ const UnityComponent = function (props) {
|
||||
// if (canvas && !window.unityInstance) {
|
||||
const unityUrl = "/unity";
|
||||
const buildUrl = "/unity/Build";
|
||||
const cdnurt = CONFIG.unitycdndir;
|
||||
const cdnbuildurl = CONFIG.unitycdnbuilddir;
|
||||
const noneurl = ''
|
||||
const loaderUrl = buildUrl + "/mstest5.loader.js";
|
||||
const cdnRoot = CONFIG.usecdn ? getUnityCdnRoot() : unityUrl;
|
||||
const cdnBuildRoot = CONFIG.usecdn ? getUnityCdnBuildRoot() : buildUrl;
|
||||
let loaderUrl = CONFIG.usecdn
|
||||
? `${cdnBuildRoot}/mstest5.loader.js`
|
||||
: `${buildUrl}/mstest5.loader.js`;
|
||||
let config = {
|
||||
dataUrl: buildUrl + "/mstest5.data.br",
|
||||
frameworkUrl: buildUrl + "/mstest5.framework.js.br",
|
||||
@@ -1497,10 +1499,10 @@ const UnityComponent = function (props) {
|
||||
};
|
||||
if (CONFIG.usecdn) {
|
||||
config = {
|
||||
dataUrl: cdnbuildurl + "/mstest5.data.br",
|
||||
frameworkUrl: cdnbuildurl + "/mstest5.framework.js.br",
|
||||
codeUrl: cdnbuildurl + "/mstest5.wasm.br",
|
||||
streamingAssetsUrl: cdnurt + "/StreamingAssets",
|
||||
dataUrl: cdnBuildRoot + "/mstest5.data.br",
|
||||
frameworkUrl: cdnBuildRoot + "/mstest5.framework.js.br",
|
||||
codeUrl: cdnBuildRoot + "/mstest5.wasm.br",
|
||||
streamingAssetsUrl: cdnRoot + "/StreamingAssets",
|
||||
// dataUrl: buildUrl + "/Build.data.br",
|
||||
// frameworkUrl: buildUrl + "/Build.framework.js.br",
|
||||
// codeUrl: buildUrl + "/Build.wasm.br",
|
||||
@@ -1516,9 +1518,10 @@ const UnityComponent = function (props) {
|
||||
|
||||
script.onload = () => {
|
||||
window.iscreate = 0;
|
||||
createUnityInstance(canvas, config, (progress) => {
|
||||
// console.log(`加载进度: ${progress * 100}%`);
|
||||
}).then((unityInstance) => {
|
||||
const boot = () => {
|
||||
createUnityInstance(canvas, config, (progress) => {
|
||||
// console.log(`加载进度: ${progress * 100}%`);
|
||||
}).then((unityInstance) => {
|
||||
window.unityInstance = unityInstance;
|
||||
window.waitForUnityStepFinish = waitForUnityStepFinish;
|
||||
window.waitForUnityVehicleStepFinish = waitForUnityVehicleStepFinish;
|
||||
@@ -1542,6 +1545,15 @@ const UnityComponent = function (props) {
|
||||
}).catch((message) => {
|
||||
console.error(`Unity 实例创建失败: ${message}`);
|
||||
});
|
||||
};
|
||||
if (CONFIG.usecdn) {
|
||||
prefetchLevelsDatabase(cdnRoot).then(boot).catch((err) => {
|
||||
console.error('[unity-cdn] 关卡库预取失败', err);
|
||||
boot();
|
||||
});
|
||||
} else {
|
||||
boot();
|
||||
}
|
||||
};
|
||||
|
||||
document.body.appendChild(script);
|
||||
|
||||
55
scratch-gui/src/lib/unity-cdn.js
Normal file
55
scratch-gui/src/lib/unity-cdn.js
Normal file
@@ -0,0 +1,55 @@
|
||||
import CONFIG from '../playground/config.js';
|
||||
|
||||
/**
|
||||
* 纯 CDN 根路径。
|
||||
* 方案 A(默认):始终返回 unityCdnRemote,浏览器直连 OSS(须配置 OSS CORS)。
|
||||
* 方案 B:unityCdnUseSiteProxy / 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();
|
||||
}
|
||||
@@ -166,8 +166,16 @@ const CONFIG = {
|
||||
|
||||
version: "20260520",
|
||||
|
||||
unitycdndir: 'https://oss.eanic.cn/001_code_unity_res_20260520',
|
||||
unitycdnbuilddir: 'https://oss.eanic.cn/001_code_unity_res_20260520/Build',
|
||||
/** OSS 真实地址(生产环境浏览器直连) */
|
||||
unityCdnRemote: 'https://oss.eanic.cn/001_code_cocos_res_20260616',
|
||||
/** 方案 B:nginx / webpack 同源代理前缀(方案 A 直连 OSS 请保持 false) */
|
||||
unityCdnDevProxy: '/cdn-unity',
|
||||
/** 本地 npm start 也走代理(仅 unityCdnUseSiteProxy 或此项为 true 时生效) */
|
||||
unityCdnUseDevProxy: false,
|
||||
/** 生产 nginx 反向代理 OSS 同路径时设为 true(方案 B) */
|
||||
unityCdnUseSiteProxy: false,
|
||||
unitycdndir: 'https://oss.eanic.cn/001_code_cocos_res_20260616',
|
||||
unitycdnbuilddir: 'https://oss.eanic.cn/001_code_cocos_res_20260616/Build',
|
||||
python_pyodide_cdn_dir: 'https://oss.eanic.cn/001_code_python_res_20241213/pyodide/',
|
||||
|
||||
// 可以根据需要添加其他配置
|
||||
@@ -175,7 +183,7 @@ const CONFIG = {
|
||||
|
||||
|
||||
disabledev: false,
|
||||
usecdn: false,
|
||||
usecdn: true,
|
||||
lvlock: false,
|
||||
lvlock_normal_learn: !(typeof localStorage !== 'undefined' &&
|
||||
(localStorage.getItem('player_id') === '37' || localStorage.getItem('player_id') === '45' || localStorage.getItem('player_id') === '55')),
|
||||
|
||||
Reference in New Issue
Block a user