1. 废弃oops.res.loadAsync,功能与oops.res.load方法合并

2. 废弃oops.res.preloadAsync,功能与oops.res.preload方法合并
3. 废弃GameComponent.loadAsync,功能与GameComponent.load方法合并
4. 修复本地存储加密安卓平台报错问题
This commit is contained in:
dgflash
2025-09-26 17:43:32 +08:00
parent 29b59abf07
commit 654737c8b2
15 changed files with 168 additions and 307 deletions

View File

@@ -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);
}
}

View File

@@ -123,7 +123,7 @@ export class AudioMusic extends Node {
clip = await resLoader.loadRemote<AudioClip>(path, { ext: `.${extension}` });
}
else {
clip = await resLoader.loadAsync(params.bundle!, path, AudioClip);
clip = await resLoader.load(params.bundle!, path, AudioClip);
}
this._isLoading = false;

View File

@@ -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<T = Asset> = __private.__types_globals__Constructor<T> | null;
export type Paths = string | string[];
@@ -149,54 +149,40 @@ export class ResLoader {
* @param onProgress 加载进度回调
* @param onComplete 加载完成回调
*/
preload<T extends Asset>(bundleName: string, paths: Paths, type: AssetType<T>, onProgress: ProgressCallback, onComplete: CompleteCallback): void;
preload<T extends Asset>(bundleName: string, paths: Paths, onProgress: ProgressCallback, onComplete: CompleteCallback): void;
preload<T extends Asset>(bundleName: string, paths: Paths, onComplete?: CompleteCallback): void;
preload<T extends Asset>(bundleName: string, paths: Paths, type: AssetType<T>, onComplete?: CompleteCallback): void;
preload<T extends Asset>(paths: Paths, type: AssetType<T>, onProgress: ProgressCallback, onComplete: CompleteCallback): void;
preload<T extends Asset>(paths: Paths, onProgress: ProgressCallback, onComplete: CompleteCallback): void;
preload<T extends Asset>(paths: Paths, onComplete?: CompleteCallback): void;
preload<T extends Asset>(paths: Paths, type: AssetType<T>, onComplete?: CompleteCallback): void;
preload<T extends Asset>(bundleName: string, paths: Paths, type: AssetType<T>, onProgress: ProgressCallback): Promise<AssetManager.RequestItem>;
preload<T extends Asset>(bundleName: string, paths: Paths, onProgress: ProgressCallback): Promise<AssetManager.RequestItem>;
preload<T extends Asset>(bundleName: string, paths: Paths): Promise<AssetManager.RequestItem>;
preload<T extends Asset>(bundleName: string, paths: Paths, type: AssetType<T>): Promise<AssetManager.RequestItem>;
preload<T extends Asset>(paths: Paths, type: AssetType<T>, onProgress: ProgressCallback): Promise<AssetManager.RequestItem>;
preload<T extends Asset>(paths: Paths, onProgress: ProgressCallback): Promise<AssetManager.RequestItem>;
preload<T extends Asset>(paths: Paths): Promise<AssetManager.RequestItem>;
preload<T extends Asset>(paths: Paths, type: AssetType<T>): Promise<AssetManager.RequestItem>;
preload<T extends Asset>(
bundleName: string,
paths?: Paths | AssetType<T> | ProgressCallback | CompleteCallback,
type?: AssetType<T> | ProgressCallback | CompleteCallback,
onProgress?: ProgressCallback | CompleteCallback,
onComplete?: CompleteCallback,
paths?: Paths | AssetType<T> | ProgressCallback,
type?: AssetType<T> | ProgressCallback,
onProgress?: ProgressCallback
) {
let args: ILoadResArgs<Asset> | 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<T extends Asset>(bundleName: string, paths: Paths, type: AssetType<T>): Promise<AssetManager.RequestItem>;
preloadAsync<T extends Asset>(bundleName: string, paths: Paths): Promise<AssetManager.RequestItem>;
preloadAsync<T extends Asset>(paths: Paths, type: AssetType<T>): Promise<AssetManager.RequestItem>;
preloadAsync<T extends Asset>(paths: Paths): Promise<AssetManager.RequestItem>;
preloadAsync<T extends Asset>(bundleName: string,
paths?: Paths | AssetType<T> | ProgressCallback | CompleteCallback,
type?: AssetType<T> | ProgressCallback | CompleteCallback): Promise<AssetManager.RequestItem> {
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<Asset> | 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<T extends Asset>(bundleName: string, paths: Paths, type: AssetType<T>, onProgress: ProgressCallback, onComplete: CompleteCallback): void;
load<T extends Asset>(bundleName: string, paths: Paths, onProgress: ProgressCallback, onComplete: CompleteCallback): void;
load<T extends Asset>(bundleName: string, paths: Paths, onComplete?: CompleteCallback): void;
load<T extends Asset>(bundleName: string, paths: Paths, type: AssetType<T>, onComplete?: CompleteCallback): void;
load<T extends Asset>(paths: Paths, type: AssetType<T>, onProgress: ProgressCallback, onComplete: CompleteCallback): void;
load<T extends Asset>(paths: Paths, onProgress: ProgressCallback, onComplete: CompleteCallback): void;
load<T extends Asset>(paths: Paths, onComplete?: CompleteCallback): void;
load<T extends Asset>(paths: Paths, type: AssetType<T>, onComplete?: CompleteCallback): void;
load<T extends Asset>(
bundleName: string,
paths?: Paths | AssetType<T> | ProgressCallback | CompleteCallback,
type?: AssetType<T> | ProgressCallback | CompleteCallback,
onProgress?: ProgressCallback | CompleteCallback,
onComplete?: CompleteCallback,
) {
let args: ILoadResArgs<T> | 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<T extends Asset>(bundleName: string, paths: Paths, type: AssetType<T>): Promise<T>;
loadAsync<T extends Asset>(bundleName: string, paths: Paths): Promise<T>;
loadAsync<T extends Asset>(paths: Paths, type: AssetType<T>): Promise<T>;
loadAsync<T extends Asset>(paths: Paths): Promise<T>;
loadAsync<T extends Asset>(bundleName: string,
paths?: Paths | AssetType<T> | ProgressCallback | CompleteCallback,
type?: AssetType<T> | ProgressCallback | CompleteCallback): Promise<T> {
return new Promise((resolve, reject) => {
this.load(bundleName, paths, type, (err: Error | null, asset: T) => {
load<T extends Asset>(bundleName: string, paths: Paths | AssetType<T>, type?: AssetType<T> | ProgressCallback, onProgress?: ProgressCallback) {
return new Promise<T>((resolve, reject) => {
let onComplete = (err: Error | null, data: T) => {
if (err) {
warn(err.message);
resolve(null!);
return;
}
resolve(asset);
});
resolve(data);
}
let args: ILoadResArgs<T> | 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<T extends Asset>(bundleName: string, dir: string, type: AssetType<T>, onProgress: ProgressCallback, onComplete: CompleteCallback): void;
loadDir<T extends Asset>(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<T extends Asset>(
paths: Paths,
type?: AssetType<T> | ProgressCallback | CompleteCallback,
onProgress?: AssetType<T> | ProgressCallback | CompleteCallback,
onComplete?: ProgressCallback | CompleteCallback
) {
private parseLoadResArgs<T extends Asset>(paths: Paths, type?: AssetType<T> | ProgressCallback | CompleteCallback, onProgress?: AssetType<T> | 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<T extends Asset>(args: ILoadResArgs<T>) {
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();

View File

@@ -18,7 +18,7 @@ export class ZipLoader {
*/
static load(url: string): Promise<JSZip> {
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);

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -49,7 +49,7 @@ export class LayerGame extends Node {
addAsync(prefab: string, config: GameElementConfig = {}): Promise<Node> {
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<Node> {
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);
});

View File

@@ -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);

View File

@@ -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);
// }
// }

View File

@@ -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) {

View File

@@ -107,7 +107,7 @@ export class ViewUtil {
*/
static createPrefabNodeAsync(path: string, bundleName: string = resLoader.defaultBundleName): Promise<Node> {
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));
}

View File

@@ -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);

View File

@@ -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);

View File

@@ -73,7 +73,7 @@ export class LanguagePack {
private loadJson(lang: string): Promise<void> {
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 资源");

View File

@@ -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<Node> {
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<T extends Asset>(bundleName: string, paths: Paths, type: AssetType<T>, onProgress: ProgressCallback, onComplete: CompleteCallback): void;
load<T extends Asset>(bundleName: string, paths: Paths, onProgress: ProgressCallback, onComplete: CompleteCallback): void;
load<T extends Asset>(bundleName: string, paths: Paths, onComplete?: CompleteCallback): void;
load<T extends Asset>(bundleName: string, paths: Paths, type: AssetType<T>, onComplete?: CompleteCallback): void;
load<T extends Asset>(paths: Paths, type: AssetType<T>, onProgress: ProgressCallback, onComplete: CompleteCallback): void;
load<T extends Asset>(paths: Paths, onProgress: ProgressCallback, onComplete: CompleteCallback): void;
load<T extends Asset>(paths: Paths, onComplete?: CompleteCallback): void;
load<T extends Asset>(paths: Paths, type: AssetType<T>, onComplete?: CompleteCallback): void;
load<T extends Asset>(
bundleName: string,
paths?: Paths | AssetType<T> | ProgressCallback | CompleteCallback,
type?: AssetType<T> | ProgressCallback | CompleteCallback,
onProgress?: ProgressCallback | CompleteCallback,
onComplete?: CompleteCallback,
) {
load<T extends Asset>(bundleName: string, paths: Paths | AssetType<T>, type?: AssetType<T> | ProgressCallback, onProgress?: ProgressCallback) {
this.addPathToRecord(ResType.Load, bundleName, paths);
oops.res.load(bundleName, paths, type, onProgress, onComplete);
}
/**
* 异步加载一个资源
* @param bundleName 远程包名
* @param paths 资源路径
* @param type 资源类型
*/
loadAsync<T extends Asset>(bundleName: string, paths: Paths, type: AssetType<T>): Promise<T>;
loadAsync<T extends Asset>(bundleName: string, paths: Paths): Promise<T>;
loadAsync<T extends Asset>(paths: Paths, type: AssetType<T>): Promise<T>;
loadAsync<T extends Asset>(paths: Paths): Promise<T>;
loadAsync<T extends Asset>(bundleName: string,
paths?: Paths | AssetType<T> | ProgressCallback | CompleteCallback,
type?: AssetType<T> | ProgressCallback | CompleteCallback): Promise<T> {
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) {