From 654737c8b2af7429f9cc2ed0575143668e7ce3e5 Mon Sep 17 00:00:00 2001 From: dgflash Date: Fri, 26 Sep 2025 17:43:32 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E5=BA=9F=E5=BC=83oops.res.loadAsync?= =?UTF-8?q?=EF=BC=8C=E5=8A=9F=E8=83=BD=E4=B8=8Eoops.res.load=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E5=90=88=E5=B9=B6=202.=20=E5=BA=9F=E5=BC=83oops.res.p?= =?UTF-8?q?reloadAsync=EF=BC=8C=E5=8A=9F=E8=83=BD=E4=B8=8Eoops.res.preload?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E5=90=88=E5=B9=B6=203.=20=E5=BA=9F=E5=BC=83G?= =?UTF-8?q?ameComponent.loadAsync=EF=BC=8C=E5=8A=9F=E8=83=BD=E4=B8=8EGameC?= =?UTF-8?q?omponent.load=E6=96=B9=E6=B3=95=E5=90=88=E5=B9=B6=204.=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9C=AC=E5=9C=B0=E5=AD=98=E5=82=A8=E5=8A=A0?= =?UTF-8?q?=E5=AF=86=E5=AE=89=E5=8D=93=E5=B9=B3=E5=8F=B0=E6=8A=A5=E9=94=99?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/core/common/audio/AudioEffectPool.ts | 2 +- assets/core/common/audio/AudioMusic.ts | 2 +- assets/core/common/loader/ResLoader.ts | 267 +++++++----------- assets/core/common/loader/ZipLoader.ts | 2 +- .../common/storage/StorageSecurityCrypto.ts | 17 +- .../common/storage/StorageSecuritySimple.ts | 30 +- assets/core/gui/layer/LayerGame.ts | 4 +- assets/core/gui/layer/LayerUI.ts | 2 +- assets/core/utils/EncryptUtil.ts | 87 ++---- assets/core/utils/JsonUtil.ts | 2 +- assets/core/utils/ViewUtil.ts | 2 +- .../2d/SpineFinishedRelease.ts | 2 +- .../libs/animator-effect/EffectSingleCase.ts | 6 +- assets/libs/gui/language/LanguagePack.ts | 4 +- assets/module/common/GameComponent.ts | 46 +-- 15 files changed, 168 insertions(+), 307 deletions(-) diff --git a/assets/core/common/audio/AudioEffectPool.ts b/assets/core/common/audio/AudioEffectPool.ts index c676057..2971a78 100644 --- a/assets/core/common/audio/AudioEffectPool.ts +++ b/assets/core/common/audio/AudioEffectPool.ts @@ -148,7 +148,7 @@ export class AudioEffectPool { this.res_project.set(bundle, paths); } if (paths.indexOf(path) == -1) paths.push(path); - clip = await resLoader.loadAsync(bundle, path, AudioClip); + clip = await resLoader.load(bundle, path, AudioClip); } } diff --git a/assets/core/common/audio/AudioMusic.ts b/assets/core/common/audio/AudioMusic.ts index d493c57..3c8b140 100644 --- a/assets/core/common/audio/AudioMusic.ts +++ b/assets/core/common/audio/AudioMusic.ts @@ -123,7 +123,7 @@ export class AudioMusic extends Node { clip = await resLoader.loadRemote(path, { ext: `.${extension}` }); } else { - clip = await resLoader.loadAsync(params.bundle!, path, AudioClip); + clip = await resLoader.load(params.bundle!, path, AudioClip); } this._isLoading = false; diff --git a/assets/core/common/loader/ResLoader.ts b/assets/core/common/loader/ResLoader.ts index 5202b6a..47d99d7 100644 --- a/assets/core/common/loader/ResLoader.ts +++ b/assets/core/common/loader/ResLoader.ts @@ -1,4 +1,4 @@ -import { __private, AnimationClip, Asset, AssetManager, assetManager, AudioClip, Font, ImageAsset, js, JsonAsset, Material, Mesh, Prefab, resources, sp, SpriteFrame, Texture2D, warn } from "cc"; +import { __private, AnimationClip, Asset, AssetManager, assetManager, AudioClip, Font, ImageAsset, js, JsonAsset, Material, Mesh, Prefab, resources, sp, SpriteFrame, Texture2D } from "cc"; export type AssetType = __private.__types_globals__Constructor | null; export type Paths = string | string[]; @@ -149,54 +149,40 @@ export class ResLoader { * @param onProgress 加载进度回调 * @param onComplete 加载完成回调 */ - preload(bundleName: string, paths: Paths, type: AssetType, onProgress: ProgressCallback, onComplete: CompleteCallback): void; - preload(bundleName: string, paths: Paths, onProgress: ProgressCallback, onComplete: CompleteCallback): void; - preload(bundleName: string, paths: Paths, onComplete?: CompleteCallback): void; - preload(bundleName: string, paths: Paths, type: AssetType, onComplete?: CompleteCallback): void; - preload(paths: Paths, type: AssetType, onProgress: ProgressCallback, onComplete: CompleteCallback): void; - preload(paths: Paths, onProgress: ProgressCallback, onComplete: CompleteCallback): void; - preload(paths: Paths, onComplete?: CompleteCallback): void; - preload(paths: Paths, type: AssetType, onComplete?: CompleteCallback): void; + preload(bundleName: string, paths: Paths, type: AssetType, onProgress: ProgressCallback): Promise; + preload(bundleName: string, paths: Paths, onProgress: ProgressCallback): Promise; + preload(bundleName: string, paths: Paths): Promise; + preload(bundleName: string, paths: Paths, type: AssetType): Promise; + preload(paths: Paths, type: AssetType, onProgress: ProgressCallback): Promise; + preload(paths: Paths, onProgress: ProgressCallback): Promise; + preload(paths: Paths): Promise; + preload(paths: Paths, type: AssetType): Promise; preload( bundleName: string, - paths?: Paths | AssetType | ProgressCallback | CompleteCallback, - type?: AssetType | ProgressCallback | CompleteCallback, - onProgress?: ProgressCallback | CompleteCallback, - onComplete?: CompleteCallback, + paths?: Paths | AssetType | ProgressCallback, + type?: AssetType | ProgressCallback, + onProgress?: ProgressCallback ) { - let args: ILoadResArgs | null = null; - if (typeof paths === "string" || paths instanceof Array) { - args = this.parseLoadResArgs(paths, type, onProgress, onComplete); - args.bundle = bundleName; - } - else { - args = this.parseLoadResArgs(bundleName, paths, type, onProgress); - args.bundle = this.defaultBundleName; - } - args.preload = true; - this.loadByArgs(args); - } - - /** - * 异步加载一个资源 - * @param bundleName 远程包名 - * @param paths 资源路径 - * @param type 资源类型 - */ - preloadAsync(bundleName: string, paths: Paths, type: AssetType): Promise; - preloadAsync(bundleName: string, paths: Paths): Promise; - preloadAsync(paths: Paths, type: AssetType): Promise; - preloadAsync(paths: Paths): Promise; - preloadAsync(bundleName: string, - paths?: Paths | AssetType | ProgressCallback | CompleteCallback, - type?: AssetType | ProgressCallback | CompleteCallback): Promise { return new Promise((resolve, reject) => { - this.preload(bundleName, paths, type, (err: Error | null, data: AssetManager.RequestItem) => { + let onComplete = (err: Error | null, data: AssetManager.RequestItem) => { if (err) { - warn(err.message); + resolve(null!); + return; } resolve(data); - }); + } + + let args: ILoadResArgs | null = null; + if (typeof paths === "string" || paths instanceof Array) { + args = this.parseLoadResArgs(paths, type, onProgress, onComplete); + args.bundle = bundleName; + } + else { + args = this.parseLoadResArgs(bundleName, paths, type, onComplete); + args.bundle = this.defaultBundleName; + } + args.preload = true; + this.loadByArgs(args); }); } @@ -247,57 +233,28 @@ export class ResLoader { * @param onProgress 加载进度回调 * @param onComplete 加载完成回调 * @example -oops.res.load("spine_path", sp.SkeletonData, (err: Error | null, sd: sp.SkeletonData) => { - -}); + const sd = await oops.res.load("spine_path", sp.SkeletonData); */ - load(bundleName: string, paths: Paths, type: AssetType, onProgress: ProgressCallback, onComplete: CompleteCallback): void; - load(bundleName: string, paths: Paths, onProgress: ProgressCallback, onComplete: CompleteCallback): void; - load(bundleName: string, paths: Paths, onComplete?: CompleteCallback): void; - load(bundleName: string, paths: Paths, type: AssetType, onComplete?: CompleteCallback): void; - load(paths: Paths, type: AssetType, onProgress: ProgressCallback, onComplete: CompleteCallback): void; - load(paths: Paths, onProgress: ProgressCallback, onComplete: CompleteCallback): void; - load(paths: Paths, onComplete?: CompleteCallback): void; - load(paths: Paths, type: AssetType, onComplete?: CompleteCallback): void; - load( - bundleName: string, - paths?: Paths | AssetType | ProgressCallback | CompleteCallback, - type?: AssetType | ProgressCallback | CompleteCallback, - onProgress?: ProgressCallback | CompleteCallback, - onComplete?: CompleteCallback, - ) { - let args: ILoadResArgs | null = null; - if (typeof paths === "string" || paths instanceof Array) { - args = this.parseLoadResArgs(paths, type, onProgress, onComplete); - args.bundle = bundleName; - } - else { - args = this.parseLoadResArgs(bundleName, paths, type, onProgress); - args.bundle = this.defaultBundleName; - } - this.loadByArgs(args); - } - - /** - * 异步加载一个资源 - * @param bundleName 远程包名 - * @param paths 资源路径 - * @param type 资源类型 - */ - loadAsync(bundleName: string, paths: Paths, type: AssetType): Promise; - loadAsync(bundleName: string, paths: Paths): Promise; - loadAsync(paths: Paths, type: AssetType): Promise; - loadAsync(paths: Paths): Promise; - loadAsync(bundleName: string, - paths?: Paths | AssetType | ProgressCallback | CompleteCallback, - type?: AssetType | ProgressCallback | CompleteCallback): Promise { - return new Promise((resolve, reject) => { - this.load(bundleName, paths, type, (err: Error | null, asset: T) => { + load(bundleName: string, paths: Paths | AssetType, type?: AssetType | ProgressCallback, onProgress?: ProgressCallback) { + return new Promise((resolve, reject) => { + let onComplete = (err: Error | null, data: T) => { if (err) { - warn(err.message); + resolve(null!); + return; } - resolve(asset); - }); + resolve(data); + } + + let args: ILoadResArgs | null = null; + if (typeof paths === "string" || paths instanceof Array) { + args = this.parseLoadResArgs(paths, type, onProgress, onComplete); + args.bundle = bundleName; + } + else { + args = this.parseLoadResArgs(bundleName, paths, type, onComplete); + args.bundle = this.defaultBundleName; + } + this.loadByArgs(args); }); } @@ -309,16 +266,16 @@ oops.res.load("spine_path", sp.SkeletonData, (err: Error | null, sd: sp.Skeleton * @param onProgress 加载进度回调 * @param onComplete 加载完成回调 * @example -// 加载进度事件 -var onProgressCallback = (finished: number, total: number, item: any) => { - console.log("资源加载进度", finished, total); -} + // 加载进度事件 + var onProgressCallback = (finished: number, total: number, item: any) => { + console.log("资源加载进度", finished, total); + } -// 加载完成事件 -var onCompleteCallback = () => { - console.log("资源加载完成"); -} -oops.res.loadDir("game", onProgressCallback, onCompleteCallback); + // 加载完成事件 + var onCompleteCallback = () => { + console.log("资源加载完成"); + } + oops.res.loadDir("game", onProgressCallback, onCompleteCallback); */ loadDir(bundleName: string, dir: string, type: AssetType, onProgress: ProgressCallback, onComplete: CompleteCallback): void; loadDir(bundleName: string, dir: string, onProgress: ProgressCallback, onComplete: CompleteCallback): void; @@ -370,7 +327,9 @@ oops.res.loadDir("game", onProgressCallback, onCompleteCallback); * @param path 资源文件夹路径 * @param bundleName 远程资源包名 */ - releaseDir(path: string, bundleName: string = this.defaultBundleName) { + releaseDir(path: string, bundleName?: string) { + if (bundleName == undefined) bundleName = this.defaultBundleName; + const bundle: AssetManager.Bundle | null = assetManager.getBundle(bundleName); if (bundle) { var infos = bundle.getDirWithPath(path); @@ -416,50 +375,6 @@ oops.res.loadDir("game", onProgressCallback, onCompleteCallback); } } - private debugLogReleasedAsset(bundleName: string, asset: Asset) { - if (asset.refCount == 0) { - let path = this.getAssetPath(bundleName, asset.uuid); - let content: string = ""; - if (asset instanceof JsonAsset) { - content = "【释放资源】Json【路径】" + path; - } - else if (asset instanceof Prefab) { - content = "【释放资源】Prefab【路径】" + path; - } - else if (asset instanceof SpriteFrame) { - content = "【释放资源】SpriteFrame【路径】" + path; - } - else if (asset instanceof Texture2D) { - content = "【释放资源】Texture2D【路径】" + path; - } - else if (asset instanceof ImageAsset) { - content = "【释放资源】ImageAsset【路径】" + path; - } - else if (asset instanceof AudioClip) { - content = "【释放资源】AudioClip【路径】" + path; - } - else if (asset instanceof AnimationClip) { - content = "【释放资源】AnimationClip【路径】" + path; - } - else if (asset instanceof Font) { - content = "【释放资源】Font【路径】" + path; - } - else if (asset instanceof Material) { - content = "【释放资源】Material【路径】" + path; - } - else if (asset instanceof Mesh) { - content = "【释放资源】Mesh【路径】" + path; - } - else if (asset instanceof sp.SkeletonData) { - content = "【释放资源】Spine【路径】" + path; - } - else { - content = "【释放资源】未知【路径】" + path; - } - console.log(content); - } - } - /** * 获取资源 * @param path 资源路径 @@ -472,12 +387,7 @@ oops.res.loadDir("game", onProgressCallback, onCompleteCallback); } //#endregion - private parseLoadResArgs( - paths: Paths, - type?: AssetType | ProgressCallback | CompleteCallback, - onProgress?: AssetType | ProgressCallback | CompleteCallback, - onComplete?: ProgressCallback | CompleteCallback - ) { + private parseLoadResArgs(paths: Paths, type?: AssetType | ProgressCallback | CompleteCallback, onProgress?: AssetType | ProgressCallback | CompleteCallback, onComplete?: ProgressCallback | CompleteCallback) { let pathsOut: any = paths; let typeOut: any = type; let onProgressOut: any = onProgress; @@ -525,15 +435,12 @@ oops.res.loadDir("game", onProgressCallback, onCompleteCallback); private async loadByArgs(args: ILoadResArgs) { if (args.bundle) { let bundle = assetManager.bundles.get(args.bundle); - // 获取缓存中的资源包 - if (bundle) { - this.loadByBundleAndArgs(bundle, args); - } + // 自动加载资源包 - else { - bundle = await this.loadBundle(args.bundle); - if (bundle) this.loadByBundleAndArgs(bundle, args); - } + if (bundle == null) bundle = await this.loadBundle(args.bundle); + + // 加载指定资源包中的资源 + this.loadByBundleAndArgs(bundle, args); } // 默认资源包 else { @@ -548,6 +455,50 @@ oops.res.loadDir("game", onProgressCallback, onCompleteCallback); }) console.log(`当前资源总数:${assetManager.assets.count}`); } + + private debugLogReleasedAsset(bundleName: string, asset: Asset) { + if (asset.refCount == 0) { + let path = this.getAssetPath(bundleName, asset.uuid); + let content: string = ""; + if (asset instanceof JsonAsset) { + content = "【释放资源】Json【路径】" + path; + } + else if (asset instanceof Prefab) { + content = "【释放资源】Prefab【路径】" + path; + } + else if (asset instanceof SpriteFrame) { + content = "【释放资源】SpriteFrame【路径】" + path; + } + else if (asset instanceof Texture2D) { + content = "【释放资源】Texture2D【路径】" + path; + } + else if (asset instanceof ImageAsset) { + content = "【释放资源】ImageAsset【路径】" + path; + } + else if (asset instanceof AudioClip) { + content = "【释放资源】AudioClip【路径】" + path; + } + else if (asset instanceof AnimationClip) { + content = "【释放资源】AnimationClip【路径】" + path; + } + else if (asset instanceof Font) { + content = "【释放资源】Font【路径】" + path; + } + else if (asset instanceof Material) { + content = "【释放资源】Material【路径】" + path; + } + else if (asset instanceof Mesh) { + content = "【释放资源】Mesh【路径】" + path; + } + else if (asset instanceof sp.SkeletonData) { + content = "【释放资源】Spine【路径】" + path; + } + else { + content = "【释放资源】未知【路径】" + path; + } + console.log(content); + } + } } export const resLoader = new ResLoader(); \ No newline at end of file diff --git a/assets/core/common/loader/ZipLoader.ts b/assets/core/common/loader/ZipLoader.ts index cc7a803..6a7a11c 100644 --- a/assets/core/common/loader/ZipLoader.ts +++ b/assets/core/common/loader/ZipLoader.ts @@ -18,7 +18,7 @@ export class ZipLoader { */ static load(url: string): Promise { return new Promise(async (resolve, reject) => { - let asset = await resLoader.loadAsync(url, BufferAsset); + let asset = await resLoader.load(url, BufferAsset); var zip = await JSZip.loadAsync(asset.buffer()); this.zips.set(url, zip); resolve(zip); diff --git a/assets/core/common/storage/StorageSecurityCrypto.ts b/assets/core/common/storage/StorageSecurityCrypto.ts index c5e26a2..672bd05 100644 --- a/assets/core/common/storage/StorageSecurityCrypto.ts +++ b/assets/core/common/storage/StorageSecurityCrypto.ts @@ -12,25 +12,20 @@ // * 2、需要下载 CryptoES 加密库 // */ // export class StorageSecurityCrypto implements IStorageSecurity { -// private _key: string = null!; -// private _iv: string = null!; - // constructor() { -// const key = oops.config.game.localDataKey; -// const iv = oops.config.game.localDataIv; - +// let key = oops.config.game.localDataKey; +// let iv = oops.config.game.localDataIv; +// key = EncryptUtil.md5(key); +// iv = EncryptUtil.md5(iv); // EncryptUtil.initCrypto(key, iv); - -// this._key = EncryptUtil.md5(key); -// this._iv = EncryptUtil.md5(iv); // } // decrypt(str: string): string { -// return EncryptUtil.aesDecrypt(str, this._key, this._iv); +// return EncryptUtil.aesDecrypt(str); // } // encrypt(str: string): string { -// return EncryptUtil.aesEncrypt(str, this._key, this._iv); +// return EncryptUtil.aesEncrypt(str); // } // encryptKey(str: string): string { diff --git a/assets/core/common/storage/StorageSecuritySimple.ts b/assets/core/common/storage/StorageSecuritySimple.ts index 6747f1f..929f4d2 100644 --- a/assets/core/common/storage/StorageSecuritySimple.ts +++ b/assets/core/common/storage/StorageSecuritySimple.ts @@ -26,30 +26,22 @@ export class StorageSecuritySimple implements IStorageSecurity { * 加密字符串 */ encrypt(data: string): string { - if (!data) return ''; - return this.xorEncrypt(data); + let encryptedText = ''; + for (let i = 0; i < data.length; i++) { + let charCode = data.charCodeAt(i); + encryptedText += String.fromCharCode(charCode + this.secretkey.length); + } + return encryptedText; } /** 解密字符串 */ decrypt(encryptedData: string): string { - if (!encryptedData) return ''; - return this.xorDecrypt(encryptedData); - } - - /** 异或加密 */ - private xorEncrypt(data: string): string { - let result = ''; - for (let i = 0; i < data.length; i++) { - const keyChar = this.secretkey.charCodeAt(i % this.secretkey.length); - const dataChar = data.charCodeAt(i); - result += String.fromCharCode(dataChar ^ keyChar); + let decryptedText = ''; + for (let i = 0; i < encryptedData.length; i++) { + let charCode = encryptedData.charCodeAt(i); + decryptedText += String.fromCharCode(charCode - this.secretkey.length); } - return result; - } - - /** 异或解密 */ - private xorDecrypt(encryptedData: string): string { - return this.xorEncrypt(encryptedData); // 异或操作是可逆的 + return decryptedText; } encryptKey(str: string): string { diff --git a/assets/core/gui/layer/LayerGame.ts b/assets/core/gui/layer/LayerGame.ts index 0299ba4..388eedd 100644 --- a/assets/core/gui/layer/LayerGame.ts +++ b/assets/core/gui/layer/LayerGame.ts @@ -49,7 +49,7 @@ export class LayerGame extends Node { addAsync(prefab: string, config: GameElementConfig = {}): Promise { return new Promise(async (resolve, reject) => { let bundleName = config.bundle ? config.bundle : resLoader.defaultBundleName; - await resLoader.loadAsync(bundleName, prefab, Prefab); + await resLoader.load(bundleName, prefab, Prefab); let node = this.add(prefab, config); resolve(node); }); @@ -88,7 +88,7 @@ export class LayerGame extends Node { addPoolAsync(prefab: string, config: GameElementConfig = {}): Promise { return new Promise(async (resolve, reject) => { let bundleName = config.bundle ? config.bundle : resLoader.defaultBundleName; - await resLoader.loadAsync(bundleName, prefab, Prefab); + await resLoader.load(bundleName, prefab, Prefab); let node = this.addPool(prefab, config); resolve(node); }); diff --git a/assets/core/gui/layer/LayerUI.ts b/assets/core/gui/layer/LayerUI.ts index c209c13..802e7fa 100644 --- a/assets/core/gui/layer/LayerUI.ts +++ b/assets/core/gui/layer/LayerUI.ts @@ -92,7 +92,7 @@ export class LayerUI extends Node { let timerId = setTimeout(this.onLoadingTimeoutGui, oops.config.game.loadingTimeoutGui); // 优先加载配置的指定资源包中资源,如果没配置则加载默认资源包资源 - const res = await resLoader.loadAsync(state.config.bundle!, state.config.prefab, Prefab); + const res = await resLoader.load(state.config.bundle!, state.config.prefab, Prefab); if (res) { state.node = instantiate(res); diff --git a/assets/core/utils/EncryptUtil.ts b/assets/core/utils/EncryptUtil.ts index 222d8ae..597aa1c 100644 --- a/assets/core/utils/EncryptUtil.ts +++ b/assets/core/utils/EncryptUtil.ts @@ -1,11 +1,4 @@ -// /* -// * @Author: dgflash -// * @Date: 2022-09-02 09:28:00 -// * @LastEditors: dgflash -// * @LastEditTime: 2022-10-21 09:46:39 -// */ - -// import CryptoES from "crypto-es"; +// import { AES, MD5, Utf8, WordArray } from 'crypto-es'; // /** // * CryptoES 加密库封装 @@ -16,81 +9,47 @@ // * yarn add crypto-es // */ // export class EncryptUtil { -// private static key: string = null!; -// private static iv: CryptoES.lib.WordArray = null!; +// // 将key和iv存储为WordArray类型,这是CryptoES库需要的格式 +// private static key: WordArray; +// private static iv: WordArray; // /** // * MD5加密 // * @param msg 加密信息 // */ // static md5(msg: string): string { -// return CryptoES.MD5(msg).toString(); +// return MD5(msg).toString(); // } // /** 初始化加密库 */ // static initCrypto(key: string, iv: string) { -// this.key = key; -// this.iv = CryptoES.enc.Hex.parse(iv); +// this.key = Utf8.parse(key); +// this.iv = Utf8.parse(iv); // } // /** // * AES 加密 -// * @param msg 加密信息 -// * @param key aes加密的key -// * @param iv aes加密的iv +// * @param msg 待加密的明文 // */ -// static aesEncrypt(msg: string, key: string, iv: string): string { -// return CryptoES.AES.encrypt( -// msg, -// this.key, -// { -// iv: this.iv, -// format: this.JsonFormatter -// }, -// ).toString(); +// static aesEncrypt(msg: string): string { +// const encrypted = AES.encrypt(msg, this.key, { +// iv: this.iv +// }); + +// // 返回Base64格式的密文字符串 +// return encrypted.toString(); // } // /** // * AES 解密 -// * @param str 解密字符串 -// * @param key aes加密的key -// * @param iv aes加密的iv +// * @param cipherText 待解密的密文 // */ -// static aesDecrypt(str: string, key: string, iv: string): string { -// const decrypted = CryptoES.AES.decrypt( -// str, -// this.key, -// { -// iv: this.iv, -// format: this.JsonFormatter -// }, -// ); -// return decrypted.toString(CryptoES.enc.Utf8); -// } +// static aesDecrypt(cipherText: string): string { +// const decrypted = AES.decrypt(cipherText, this.key, { +// iv: this.iv +// }); -// private static JsonFormatter = { -// stringify: function (cipherParams: any) { -// const jsonObj: any = { ct: cipherParams.ciphertext.toString(CryptoES.enc.Base64) }; -// if (cipherParams.iv) { -// jsonObj.iv = cipherParams.iv.toString(); -// } -// if (cipherParams.salt) { -// jsonObj.s = cipherParams.salt.toString(); -// } -// return JSON.stringify(jsonObj); -// }, -// parse: function (jsonStr: any) { -// const jsonObj = JSON.parse(jsonStr); -// const cipherParams = CryptoES.lib.CipherParams.create( -// { ciphertext: CryptoES.enc.Base64.parse(jsonObj.ct) }, -// ); -// if (jsonObj.iv) { -// cipherParams.iv = CryptoES.enc.Hex.parse(jsonObj.iv) -// } -// if (jsonObj.s) { -// cipherParams.salt = CryptoES.enc.Hex.parse(jsonObj.s) -// } -// return cipherParams; -// }, -// }; +// // 将解密结果从WordArray转换为UTF-8字符串 +// return decrypted.toString(Utf8); +// } // } \ No newline at end of file diff --git a/assets/core/utils/JsonUtil.ts b/assets/core/utils/JsonUtil.ts index 621344f..3e638d8 100644 --- a/assets/core/utils/JsonUtil.ts +++ b/assets/core/utils/JsonUtil.ts @@ -46,7 +46,7 @@ export class JsonUtil { content = await ZipLoader.getJson(pathZip, `${name}.json`); } else { - content = await resLoader.loadAsync(url, JsonAsset); + content = await resLoader.load(url, JsonAsset); } if (content) { diff --git a/assets/core/utils/ViewUtil.ts b/assets/core/utils/ViewUtil.ts index 2cc3d0b..495959c 100644 --- a/assets/core/utils/ViewUtil.ts +++ b/assets/core/utils/ViewUtil.ts @@ -107,7 +107,7 @@ export class ViewUtil { */ static createPrefabNodeAsync(path: string, bundleName: string = resLoader.defaultBundleName): Promise { return new Promise(async (resolve, reject) => { - const p = await resLoader.loadAsync(bundleName, path, Prefab); + const p = await resLoader.load(bundleName, path, Prefab); if (p) { resolve(instantiate(p)); } diff --git a/assets/libs/animator-effect/2d/SpineFinishedRelease.ts b/assets/libs/animator-effect/2d/SpineFinishedRelease.ts index 367e1ee..e8b59a4 100644 --- a/assets/libs/animator-effect/2d/SpineFinishedRelease.ts +++ b/assets/libs/animator-effect/2d/SpineFinishedRelease.ts @@ -36,7 +36,7 @@ export class SpineFinishedRelease extends Component { } private async loadSkeletonData() { - let sd = await oops.res.loadAsync(this.resPath, sp.SkeletonData); + let sd = await oops.res.load(this.resPath, sp.SkeletonData); if (sd) { this.spine.skeletonData = sd; this.spine.setAnimation(0, "animation", false); diff --git a/assets/libs/animator-effect/EffectSingleCase.ts b/assets/libs/animator-effect/EffectSingleCase.ts index 6f3cf47..53c8d2c 100644 --- a/assets/libs/animator-effect/EffectSingleCase.ts +++ b/assets/libs/animator-effect/EffectSingleCase.ts @@ -87,7 +87,7 @@ export class EffectSingleCase { } this.res.set(path, bundleName); - await resLoader.loadAsync(bundleName, path, Prefab); + await resLoader.load(bundleName, path, Prefab); for (let i = 0; i < count; i++) { let node = ViewUtil.createPrefabNode(path, bundleName); @@ -111,11 +111,11 @@ export class EffectSingleCase { if (np == undefined) { if (params && params.bundleName) { this.res.set(path, params.bundleName); - await resLoader.loadAsync(params.bundleName, path, Prefab); + await resLoader.load(params.bundleName, path, Prefab); } else { this.res.set(path, resLoader.defaultBundleName); - await resLoader.loadAsync(path, Prefab); + await resLoader.load(path, Prefab); } const node = this.show(path, parent, params); diff --git a/assets/libs/gui/language/LanguagePack.ts b/assets/libs/gui/language/LanguagePack.ts index 5d23bce..e092556 100644 --- a/assets/libs/gui/language/LanguagePack.ts +++ b/assets/libs/gui/language/LanguagePack.ts @@ -73,7 +73,7 @@ export class LanguagePack { private loadJson(lang: string): Promise { return new Promise(async (resolve, reject) => { const path = `${LanguageData.path_json}/${lang}`; - const jsonAsset = await resLoader.loadAsync(path, JsonAsset); + const jsonAsset = await resLoader.load(path, JsonAsset); if (jsonAsset) { LanguageData.language.set(LanguageDataType.Json, jsonAsset.json); Logger.instance.logConfig(path, "下载语言包 json 资源"); @@ -83,7 +83,7 @@ export class LanguagePack { return; } - const font = await resLoader.loadAsync(path, TTFFont); + const font = await resLoader.load(path, TTFFont); if (font) { LanguageData.font = font; Logger.instance.logConfig(path, "下载语言包 ttf 资源"); diff --git a/assets/module/common/GameComponent.ts b/assets/module/common/GameComponent.ts index 08dac4d..dac129b 100644 --- a/assets/module/common/GameComponent.ts +++ b/assets/module/common/GameComponent.ts @@ -4,7 +4,7 @@ * @LastEditors: dgflash * @LastEditTime: 2022-12-13 11:36:00 */ -import { Asset, Button, Component, EventHandler, EventKeyboard, EventTouch, Input, Node, Prefab, Sprite, SpriteFrame, __private, _decorator, input, isValid } from "cc"; +import { Asset, Button, Component, EventHandler, EventKeyboard, EventTouch, Input, Node, Sprite, SpriteFrame, __private, _decorator, input, isValid } from "cc"; import { oops } from "../../core/Oops"; import { AudioEffect } from "../../core/common/audio/AudioEffect"; import { IAudioParams } from "../../core/common/audio/IAudio"; @@ -109,11 +109,7 @@ export class GameComponent extends Component { * @param bundleName 资源包名 */ createPrefabNodeAsync(path: string, bundleName: string = oops.res.defaultBundleName): Promise { - return new Promise(async (resolve, reject) => { - await this.loadAsync(bundleName, path, Prefab); - let node = ViewUtil.createPrefabNode(path, bundleName); - resolve(node); - }); + return ViewUtil.createPrefabNodeAsync(path, bundleName); } //#endregion @@ -197,42 +193,10 @@ export class GameComponent extends Component { * @param paths 资源路径 * @param type 资源类型 * @param onProgress 加载进度回调 - * @param onComplete 加载完成回调 */ - load(bundleName: string, paths: Paths, type: AssetType, onProgress: ProgressCallback, onComplete: CompleteCallback): void; - load(bundleName: string, paths: Paths, onProgress: ProgressCallback, onComplete: CompleteCallback): void; - load(bundleName: string, paths: Paths, onComplete?: CompleteCallback): void; - load(bundleName: string, paths: Paths, type: AssetType, onComplete?: CompleteCallback): void; - load(paths: Paths, type: AssetType, onProgress: ProgressCallback, onComplete: CompleteCallback): void; - load(paths: Paths, onProgress: ProgressCallback, onComplete: CompleteCallback): void; - load(paths: Paths, onComplete?: CompleteCallback): void; - load(paths: Paths, type: AssetType, onComplete?: CompleteCallback): void; - load( - bundleName: string, - paths?: Paths | AssetType | ProgressCallback | CompleteCallback, - type?: AssetType | ProgressCallback | CompleteCallback, - onProgress?: ProgressCallback | CompleteCallback, - onComplete?: CompleteCallback, - ) { + load(bundleName: string, paths: Paths | AssetType, type?: AssetType | ProgressCallback, onProgress?: ProgressCallback) { this.addPathToRecord(ResType.Load, bundleName, paths); - oops.res.load(bundleName, paths, type, onProgress, onComplete); - } - - /** - * 异步加载一个资源 - * @param bundleName 远程包名 - * @param paths 资源路径 - * @param type 资源类型 - */ - loadAsync(bundleName: string, paths: Paths, type: AssetType): Promise; - loadAsync(bundleName: string, paths: Paths): Promise; - loadAsync(paths: Paths, type: AssetType): Promise; - loadAsync(paths: Paths): Promise; - loadAsync(bundleName: string, - paths?: Paths | AssetType | ProgressCallback | CompleteCallback, - type?: AssetType | ProgressCallback | CompleteCallback): Promise { - this.addPathToRecord(ResType.Load, bundleName, paths); - return oops.res.loadAsync(bundleName, paths, type); + return oops.res.load(bundleName, paths, type, onProgress); } /** @@ -307,7 +271,7 @@ export class GameComponent extends Component { * @param bundle 资源包名 */ async setSprite(target: Sprite, path: string, bundle: string = resLoader.defaultBundleName) { - const spriteFrame = await this.loadAsync(bundle, path, SpriteFrame); + const spriteFrame = await this.load(bundle, path, SpriteFrame); if (!spriteFrame || !isValid(target)) { const rps = this.resPaths.get(ResType.Load); if (rps) {