/** 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 { 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: () => {} }; } }