Files
cocos/assets/scripts/core/ResourcesBundle.ts
刘宇飞 d393302388 Complete Cocos Creator port with level bundles, themes, and tooling.
Adds level prefabs, theme assets, audio, extensions, and deployment scripts for the Unity WebGL migration.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-16 15:30:58 +08:00

24 lines
844 B
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { assetManager } from 'cc';
const RESOURCES_BUNDLE = 'resources';
let bundlePromise: Promise<assetManager.Bundle> | null = null;
/** 拆分分包后须先 loadBundle('resources')resources.load 才可用 */
export function ensureResourcesBundle(): Promise<assetManager.Bundle> {
const existing = assetManager.getBundle(RESOURCES_BUNDLE);
if (existing) return Promise.resolve(existing);
if (bundlePromise) return bundlePromise;
bundlePromise = new Promise((resolve, reject) => {
assetManager.loadBundle(RESOURCES_BUNDLE, (err, bundle) => {
bundlePromise = null;
if (err || !bundle) {
reject(err ?? new Error(`bundle "${RESOURCES_BUNDLE}" unavailable`));
return;
}
resolve(bundle);
});
});
return bundlePromise;
}