From 29b59abf07e2b1ff9a4651c8fac4f81ac5fabae0 Mon Sep 17 00:00:00 2001 From: dgflash Date: Thu, 25 Sep 2025 19:43:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A1=86=E6=9E=B6=E5=86=85=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E4=B8=BAoops.res.loadAsync?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/core/common/loader/ZipLoader.ts | 13 +++++------- .../2d/SpineFinishedRelease.ts | 20 +++++++++---------- assets/libs/gui/language/LanguagePack.ts | 9 +++++---- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/assets/core/common/loader/ZipLoader.ts b/assets/core/common/loader/ZipLoader.ts index b13f3a6..cc7a803 100644 --- a/assets/core/common/loader/ZipLoader.ts +++ b/assets/core/common/loader/ZipLoader.ts @@ -17,14 +17,11 @@ export class ZipLoader { * @returns */ static load(url: string): Promise { - return new Promise((resolve, reject) => { - resLoader.load(url, BufferAsset, async (error: Error | null, asset: BufferAsset) => { - if (error) return reject(error); - - var zip = await JSZip.loadAsync(asset.buffer()); - this.zips.set(url, zip); - resolve(zip); - }) + return new Promise(async (resolve, reject) => { + let asset = await resLoader.loadAsync(url, BufferAsset); + var zip = await JSZip.loadAsync(asset.buffer()); + this.zips.set(url, zip); + resolve(zip); }); } diff --git a/assets/libs/animator-effect/2d/SpineFinishedRelease.ts b/assets/libs/animator-effect/2d/SpineFinishedRelease.ts index 5f71a21..367e1ee 100644 --- a/assets/libs/animator-effect/2d/SpineFinishedRelease.ts +++ b/assets/libs/animator-effect/2d/SpineFinishedRelease.ts @@ -5,7 +5,7 @@ * @LastEditTime: 2022-04-08 15:42:16 */ -import { Component, sp, _decorator } from 'cc'; +import { _decorator, Component, sp } from 'cc'; import { oops } from '../../../core/Oops'; const { ccclass, property } = _decorator; @@ -28,21 +28,21 @@ export class SpineFinishedRelease extends Component { this.spine.setCompleteListener(this.onSpineComplete.bind(this)); if (this.resPath) { - oops.res.load(this.resPath, sp.SkeletonData, (err: Error | null, sd: sp.SkeletonData) => { - if (err) { - console.error(`加载【${this.resPath}】的 SPINE 资源不存在`); - return; - } - - this.spine.skeletonData = sd; - this.spine.setAnimation(0, "animation", false); - }); + this.loadSkeletonData(); } else { this.spine.setAnimation(0, "animation", false); } } + private async loadSkeletonData() { + let sd = await oops.res.loadAsync(this.resPath, sp.SkeletonData); + if (sd) { + this.spine.skeletonData = sd; + this.spine.setAnimation(0, "animation", false); + } + } + private onSpineComplete() { if (this.isDestroy) { this.node.destroy(); diff --git a/assets/libs/gui/language/LanguagePack.ts b/assets/libs/gui/language/LanguagePack.ts index 1d22726..5d23bce 100644 --- a/assets/libs/gui/language/LanguagePack.ts +++ b/assets/libs/gui/language/LanguagePack.ts @@ -83,11 +83,12 @@ export class LanguagePack { return; } - resLoader.load(path, TTFFont, (err: Error | null, font: TTFFont) => { - if (err == null) Logger.instance.logConfig(path, "下载语言包 ttf 资源"); + const font = await resLoader.loadAsync(path, TTFFont); + if (font) { LanguageData.font = font; - resolve(); - }); + Logger.instance.logConfig(path, "下载语言包 ttf 资源"); + } + resolve(); }); }