From 04d5c9ae357e1d763248f4a75ef668c8fbcd32a5 Mon Sep 17 00:00:00 2001 From: dgflash Date: Sun, 11 May 2025 16:47:44 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B5=84=E6=BA=90=E5=8A=A0=E8=BD=BD=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E7=A7=BB=E9=99=A4=E8=BF=9C=E7=A8=8B=E5=8C=85=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=95=B0=E6=8D=AE=EF=BC=8C=E7=8E=B0=E4=BD=BF=E7=94=A8?= =?UTF-8?q?cc=E5=BC=95=E6=93=8E=E4=B8=AD=E8=BF=9C=E7=A8=8B=E5=8C=85?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/core/Root.ts | 1 - assets/core/common/loader/ResLoader.ts | 31 ++++++-------------------- 2 files changed, 7 insertions(+), 25 deletions(-) diff --git a/assets/core/Root.ts b/assets/core/Root.ts index bcc5fad..693b9f6 100644 --- a/assets/core/Root.ts +++ b/assets/core/Root.ts @@ -90,7 +90,6 @@ export class Root extends Component { // 设置默认资源包 oops.res.defaultBundleName = oops.config.game.bundleDefault; - oops.res.init(oops.config.game.data.bundle); // 游戏界面管理 oops.gui.mobileSafeArea = oops.config.game.mobileSafeArea; diff --git a/assets/core/common/loader/ResLoader.ts b/assets/core/common/loader/ResLoader.ts index 3ea8049..8489f6e 100644 --- a/assets/core/common/loader/ResLoader.ts +++ b/assets/core/common/loader/ResLoader.ts @@ -1,4 +1,4 @@ -import { Asset, AssetManager, __private, assetManager, error, js, resources, warn } from "cc"; +import { __private, Asset, AssetManager, assetManager, error, js, resources, warn } from "cc"; export type AssetType = __private.__types_globals__Constructor | null; export type Paths = string | string[]; @@ -35,8 +35,6 @@ export class ResLoader { //#region 资源配置数据 /** 全局默认加载的资源包名 */ defaultBundleName: string = "resources"; - /** 是否使用远程 CDN 资源 */ - cdn: boolean = false; /** 下载时的最大并发数 - 项目设置 -> 项目数据 -> 资源下载并发数,设置默认值;初始值为15 */ get maxConcurrency() { @@ -70,17 +68,6 @@ export class ResLoader { assetManager.downloader.retryInterval = value; } - /** 资源包配置 */ - private bundles: Map = new Map(); - //#endregion - - init(config: any) { - this.cdn = config.enable; - for (let bundleName in config.packages) { - this.bundles.set(bundleName, config.packages[bundleName]); - } - } - //#region 加载远程资源 /** * 加载远程资源 @@ -120,16 +107,13 @@ oops.res.loadRemote(this.url, opt, onComplete); //#region 资源包管理 /** * 加载资源包 - * @param url 资源地址 - * @param v 资源MD5版本号 + * @param name 资源地址 * @example -var serverUrl = "http://192.168.1.8:8080/"; // 服务器地址 -var md5 = "8e5c0"; // Cocos Creator 构建后的MD5字符 -await oops.res.loadBundle(serverUrl,md5); + await oops.res.loadBundle(name); */ - loadBundle(url: string, v?: string) { + loadBundle(name: string) { return new Promise((resolve, reject) => { - assetManager.loadBundle(url, { version: v }, (err, bundle: AssetManager.Bundle) => { + assetManager.loadBundle(name, (err, bundle: AssetManager.Bundle) => { if (err) { return error(err); } @@ -366,7 +350,7 @@ oops.res.loadDir("game", onProgressCallback, onCompleteCallback); */ release(path: string, bundleName?: string) { if (bundleName == undefined) bundleName = this.defaultBundleName; - + const bundle = assetManager.getBundle(bundleName); if (bundle) { const asset = bundle.get(path); @@ -483,8 +467,7 @@ oops.res.loadDir("game", onProgressCallback, onCompleteCallback); } // 自动加载资源包 else { - const v = this.cdn ? this.bundles.get(args.bundle) : ""; - bundle = await this.loadBundle(args.bundle, v); + bundle = await this.loadBundle(args.bundle); if (bundle) this.loadByBundleAndArgs(bundle, args); } }