mirror of
https://gitee.com/dgflash/oops-plugin-framework.git
synced 2026-09-03 04:03:46 +08:00
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:
@@ -37,37 +37,36 @@ export class ResLoader {
|
||||
defaultBundleName: string = "resources";
|
||||
|
||||
/** 下载时的最大并发数 - 项目设置 -> 项目数据 -> 资源下载并发数,设置默认值;初始值为15 */
|
||||
get maxConcurrency(): number {
|
||||
get maxConcurrency() {
|
||||
return assetManager.downloader.maxConcurrency;
|
||||
}
|
||||
set maxConcurrency(value: number) {
|
||||
set maxConcurrency(value) {
|
||||
assetManager.downloader.maxConcurrency = value;
|
||||
}
|
||||
|
||||
/** 下载时每帧可以启动的最大请求数 - 默认值为15 */
|
||||
get maxRequestsPerFrame(): number {
|
||||
get maxRequestsPerFrame() {
|
||||
return assetManager.downloader.maxRequestsPerFrame;
|
||||
}
|
||||
set maxRequestsPerFrame(value: number) {
|
||||
set maxRequestsPerFrame(value) {
|
||||
assetManager.downloader.maxRequestsPerFrame = value;
|
||||
}
|
||||
|
||||
/** 失败重试次数 - 默认值为0 */
|
||||
get maxRetryCount(): number {
|
||||
get maxRetryCount() {
|
||||
return assetManager.downloader.maxRetryCount;
|
||||
}
|
||||
set maxRetryCount(value: number) {
|
||||
set maxRetryCount(value) {
|
||||
assetManager.downloader.maxRetryCount = value;
|
||||
}
|
||||
|
||||
/** 重试的间隔时间,单位为毫秒 - 默认值为2000毫秒 */
|
||||
get retryInterval(): number {
|
||||
get retryInterval() {
|
||||
return assetManager.downloader.retryInterval;
|
||||
}
|
||||
set retryInterval(value: number) {
|
||||
set retryInterval(value) {
|
||||
assetManager.downloader.retryInterval = value;
|
||||
}
|
||||
//#endregion
|
||||
|
||||
//#region 加载远程资源
|
||||
/**
|
||||
@@ -79,10 +78,10 @@ export class ResLoader {
|
||||
var data = await oops.res.loadRemote<ImageAsset>(this.url, opt);
|
||||
const texture = new Texture2D();
|
||||
texture.image = data;
|
||||
|
||||
|
||||
const spriteFrame = new SpriteFrame();
|
||||
spriteFrame.texture = texture;
|
||||
|
||||
|
||||
var sprite = this.sprite.addComponent(Sprite);
|
||||
sprite.spriteFrame = spriteFrame;
|
||||
*/
|
||||
@@ -231,10 +230,12 @@ export class ResLoader {
|
||||
* @param bundleName 远程包名
|
||||
* @param paths 资源路径
|
||||
* @param type 资源类型
|
||||
* @param onProgress 加载进度回调
|
||||
* @param onComplete 加载完成回调
|
||||
* @example
|
||||
const sd = await oops.res.load("spine_path", sp.SkeletonData);
|
||||
*/
|
||||
load<T extends Asset>(bundleName: string, paths: Paths | AssetType<T>, type?: AssetType<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) {
|
||||
@@ -246,37 +247,17 @@ export class ResLoader {
|
||||
|
||||
let args: ILoadResArgs<T> | null = null;
|
||||
if (typeof paths === "string" || paths instanceof Array) {
|
||||
args = this.parseLoadResArgs(paths, type, onComplete);
|
||||
args = this.parseLoadResArgs(paths, type, onProgress, onComplete);
|
||||
args.bundle = bundleName;
|
||||
}
|
||||
else {
|
||||
args = this.parseLoadResArgs(bundleName, paths, onComplete);
|
||||
args = this.parseLoadResArgs(bundleName, paths, type, onComplete);
|
||||
args.bundle = this.defaultBundleName;
|
||||
}
|
||||
this.loadByArgs(args);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载指定资源包中的多个任意类型资源
|
||||
* @param bundleName 远程包名
|
||||
* @param paths 资源路径
|
||||
* @param onProgress 加载进度回调
|
||||
* @param onComplete 加载完成回调
|
||||
*/
|
||||
loadAny<T extends Asset>(bundleName: string | string[], paths: string[] | ProgressCallback, onProgress?: ProgressCallback | CompleteCallback, onComplete?: CompleteCallback): void {
|
||||
let args: ILoadResArgs<T> | null = null;
|
||||
if (typeof bundleName === "string" && paths instanceof Array) {
|
||||
args = this.parseLoadResArgs(paths, onProgress, onComplete);
|
||||
args.bundle = bundleName;
|
||||
}
|
||||
else {
|
||||
args = this.parseLoadResArgs(bundleName, paths, onProgress);
|
||||
args.bundle = this.defaultBundleName;
|
||||
}
|
||||
this.loadByArgs(args);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载文件夹中的资源
|
||||
* @param bundleName 远程包名
|
||||
@@ -289,7 +270,7 @@ export class ResLoader {
|
||||
var onProgressCallback = (finished: number, total: number, item: any) => {
|
||||
console.log("资源加载进度", finished, total);
|
||||
}
|
||||
|
||||
|
||||
// 加载完成事件
|
||||
var onCompleteCallback = () => {
|
||||
console.log("资源加载完成");
|
||||
@@ -336,7 +317,7 @@ export class ResLoader {
|
||||
if (bundle) {
|
||||
const asset = bundle.get(path);
|
||||
if (asset) {
|
||||
this.releasePrefabtDepsRecursively(asset);
|
||||
this.releasePrefabtDepsRecursively(bundleName, asset);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -354,7 +335,7 @@ export class ResLoader {
|
||||
var infos = bundle.getDirWithPath(path);
|
||||
if (infos) {
|
||||
infos.map((info) => {
|
||||
this.releasePrefabtDepsRecursively(info.uuid);
|
||||
this.releasePrefabtDepsRecursively(bundleName, info.uuid);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -378,25 +359,20 @@ export class ResLoader {
|
||||
}
|
||||
|
||||
/** 释放预制依赖资源 */
|
||||
private releasePrefabtDepsRecursively(uuid: string | Asset) {
|
||||
let asset: Asset | null | undefined;
|
||||
private releasePrefabtDepsRecursively(bundleName: string, uuid: string | Asset) {
|
||||
if (uuid instanceof Asset) {
|
||||
asset = uuid;
|
||||
uuid.decRef();
|
||||
// assetManager.releaseAsset(uuid);
|
||||
// this.debugLogReleasedAsset(bundleName, uuid);
|
||||
}
|
||||
else {
|
||||
asset = assetManager.assets.get(uuid);
|
||||
if (asset) asset.decRef();
|
||||
const asset = assetManager.assets.get(uuid);
|
||||
if (asset) {
|
||||
asset.decRef();
|
||||
// assetManager.releaseAsset(asset);
|
||||
// this.debugLogReleasedAsset(bundleName, asset);
|
||||
}
|
||||
}
|
||||
|
||||
// 释放预制引用资源
|
||||
// if (asset instanceof Prefab) {
|
||||
// const uuids: string[] = assetManager.dependUtil.getDepsRecursively(asset.uuid)!;
|
||||
// uuids.forEach(uuid => {
|
||||
// const asset = assetManager.assets.get(uuid);
|
||||
// if (asset) asset.decRef();
|
||||
// });
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// import { oops } from "../../Oops";
|
||||
// import { EncryptUtil } from "../../utils/EncryptUtil";
|
||||
// import { IStorageSecurity } from "./StorageManager";
|
||||
|
||||
@@ -11,13 +12,12 @@
|
||||
// * 2、需要下载 CryptoES 加密库
|
||||
// */
|
||||
// export class StorageSecurityCrypto implements IStorageSecurity {
|
||||
// key: string = null!;
|
||||
// iv: string = null!;
|
||||
|
||||
// init() {
|
||||
// this.key = EncryptUtil.md5(this.key);
|
||||
// this.iv = EncryptUtil.md5(this.iv);
|
||||
// EncryptUtil.initCrypto(this.key, this.iv);
|
||||
// constructor() {
|
||||
// let key = oops.config.game.localDataKey;
|
||||
// let iv = oops.config.game.localDataIv;
|
||||
// key = EncryptUtil.md5(key);
|
||||
// iv = EncryptUtil.md5(iv);
|
||||
// EncryptUtil.initCrypto(key, iv);
|
||||
// }
|
||||
|
||||
// decrypt(str: string): string {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* @LastEditors: dgflash
|
||||
* @LastEditTime: 2025-08-15 10:06:47
|
||||
*/
|
||||
import { Node, NodePool, Vec3, warn } from "cc";
|
||||
import { Node, NodePool, Prefab, Vec3, warn } from "cc";
|
||||
import { resLoader } from "../../common/loader/ResLoader";
|
||||
import { ViewUtil } from "../../utils/ViewUtil";
|
||||
import { LayerCustomType } from "./LayerEnum";
|
||||
@@ -22,50 +22,74 @@ export class LayerGame extends Node {
|
||||
LayerHelper.setFullScreen(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加游戏元素
|
||||
* @param prefab 资源地址
|
||||
* @param config 游戏元素自定义配置
|
||||
*/
|
||||
add(prefab: string, config: GameElementConfig = {}): Node {
|
||||
let params = this.setParams(prefab, config, false);
|
||||
let node = ViewUtil.createPrefabNode(prefab, params.config.bundle);
|
||||
if (node) {
|
||||
// 设置自定义属性
|
||||
this.setNode(node, config);
|
||||
|
||||
let lge = node.addComponent(LayerGameElement);
|
||||
lge.params = params;
|
||||
params.nodes.push(node);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载资源并添加游戏元素
|
||||
* @param prefab 资源地址
|
||||
* @param config 游戏元素自定义配置
|
||||
*/
|
||||
add(prefab: string, config: GameElementConfig = {}): Promise<Node> {
|
||||
addAsync(prefab: string, config: GameElementConfig = {}): Promise<Node> {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let params = this.setParams(prefab, config, false);
|
||||
let node = await ViewUtil.createPrefabNodeAsync(prefab, params.config.bundle);
|
||||
if (node) {
|
||||
// 设置自定义属性
|
||||
this.setNode(node, config);
|
||||
|
||||
let lge = node.addComponent(LayerGameElement);
|
||||
lge.params = params;
|
||||
params.nodes.push(node);
|
||||
}
|
||||
let bundleName = config.bundle ? config.bundle : resLoader.defaultBundleName;
|
||||
await resLoader.load(bundleName, prefab, Prefab);
|
||||
let node = this.add(prefab, config);
|
||||
resolve(node);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加游戏元素 - 支持对象池
|
||||
* @param prefab 资源地址
|
||||
* @param config 游戏元素自定义配置
|
||||
*/
|
||||
addPool(prefab: string, config: GameElementConfig = {}): Node {
|
||||
let params = this.setParams(prefab, config, true);
|
||||
let node: Node = null!;
|
||||
if (params.pool.size() > 0) {
|
||||
node = params.pool.get()!;
|
||||
}
|
||||
else {
|
||||
node = ViewUtil.createPrefabNode(prefab, params.config.bundle);
|
||||
node.addComponent(LayerGameElement);
|
||||
}
|
||||
|
||||
// 设置自定义属性
|
||||
this.setNode(node, config);
|
||||
|
||||
let lge = node.getComponent(LayerGameElement)!;
|
||||
lge.params = params;
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载资源并添加游戏元素 - 支持对象池
|
||||
* @param prefab 资源地址
|
||||
* @param config 游戏元素自定义配置
|
||||
*/
|
||||
addPool(prefab: string, config: GameElementConfig = {}): Promise<Node> {
|
||||
addPoolAsync(prefab: string, config: GameElementConfig = {}): Promise<Node> {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let params = this.setParams(prefab, config, true);
|
||||
let node: Node = null!;
|
||||
if (params.pool.size() > 0) {
|
||||
node = params.pool.get()!;
|
||||
}
|
||||
else {
|
||||
node = await ViewUtil.createPrefabNodeAsync(prefab, params.config.bundle);
|
||||
node.addComponent(LayerGameElement);
|
||||
}
|
||||
|
||||
// 设置自定义属性
|
||||
this.setNode(node, config);
|
||||
|
||||
let lge = node.getComponent(LayerGameElement)!;
|
||||
lge.params = params;
|
||||
|
||||
let bundleName = config.bundle ? config.bundle : resLoader.defaultBundleName;
|
||||
await resLoader.load(bundleName, prefab, Prefab);
|
||||
let node = this.addPool(prefab, config);
|
||||
resolve(node);
|
||||
});
|
||||
}
|
||||
@@ -99,7 +123,7 @@ export class LayerGame extends Node {
|
||||
resLoader.release(lge.params.config.prefab!, lge.params.config.bundle);
|
||||
}
|
||||
}
|
||||
node.destroy();
|
||||
node.removeFromParent();
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -125,7 +149,6 @@ export class LayerGame extends Node {
|
||||
}
|
||||
this.elements.set(uuid, params);
|
||||
}
|
||||
params.config.bundle = bundleName;
|
||||
return params;
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 资源");
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user