Files
MatchMaster/assets/Script/module/Config/ActivityBundleLoader.ts
T
2026-10-12 15:00:49 +08:00

17 lines
1.1 KiB
TypeScript

/** Native ZIP cache is installed by the WeChat build extension; editor/web use Creator directly. */
export default class ActivityBundleLoader {
private static runtime(): any { return typeof window !== "undefined" && (window as any).__activityBundles; }
static beginCycle(): void { const runtime = this.runtime(); if (runtime) runtime.beginCycle(); }
static ensureBundle(name: string): Promise<cc.AssetManager.Bundle> {
const runtime = this.runtime();
if (runtime) return runtime.ensureBundle(name);
if (cc.sys && cc.sys.platform === cc.sys.WECHAT_GAME)
return Promise.reject(new Error("活动分包加载器未初始化,请重新构建小游戏"));
return new Promise((resolve, reject) => cc.assetManager.loadBundle(name, (error, bundle) => error ? reject(error) : resolve(bundle)));
}
static async acquireBundle(name: string): Promise<{ bundle: cc.AssetManager.Bundle; release: () => void }> {
const runtime = this.runtime();
return runtime ? runtime.acquireBundle(name) : { bundle: await this.ensureBundle(name), release: () => {} };
}
}