mirror of
https://gitee.com/dgflash/oops-framework.git
synced 2026-07-06 07:44:25 +08:00
添加加载模块的注释
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
* @Author: dgflash
|
||||
* @Date: 2022-07-14 10:57:43
|
||||
* @LastEditors: dgflash
|
||||
* @LastEditTime: 2022-07-18 12:43:16
|
||||
* @LastEditTime: 2022-07-18 13:47:16
|
||||
*/
|
||||
import { ImageAsset, Node, Sprite, SpriteFrame, Texture2D, _decorator } from 'cc';
|
||||
import { IRemoteOptions, resLoader } from '../../../extensions/oops-framework/assets/core/common/loader/ResLoader';
|
||||
@@ -21,6 +21,7 @@ export class Main extends Root {
|
||||
sprite: Node = null!;
|
||||
|
||||
private url = "https://oops-1255342636.cos-website.ap-shanghai.myqcloud.com/oops-framework/assets/resources/native/00/0021cb5a-e4f0-4709-b0b6-5e21875720b7.3d6ea.png";
|
||||
// private cache: any = {};
|
||||
|
||||
btnLoader() {
|
||||
var opt: IRemoteOptions = { ext: ".png" };
|
||||
@@ -32,6 +33,7 @@ export class Main extends Root {
|
||||
var sprite = this.sprite.getComponent(Sprite) || this.sprite.addComponent(Sprite);
|
||||
sprite.spriteFrame = spriteFrame;
|
||||
data.addRef();
|
||||
// this.cache[data.nativeUrl] = spriteFrame;
|
||||
}
|
||||
resLoader.loadRemote<ImageAsset>(this.url, opt, onComplete);
|
||||
}
|
||||
@@ -51,7 +53,8 @@ export class Main extends Root {
|
||||
}
|
||||
|
||||
if (texture) {
|
||||
texture.image?.decRef();
|
||||
// delete this.cache[texture.image!.nativeUrl];
|
||||
texture.image!.decRef();
|
||||
texture.destroy();
|
||||
}
|
||||
spFrame.destroy();
|
||||
|
||||
@@ -15,6 +15,27 @@ interface ILoadResArgs<T extends Asset> {
|
||||
}
|
||||
|
||||
export default class ResLoader {
|
||||
/**
|
||||
* 加载远程资源
|
||||
* @param url 资源地址
|
||||
* @param options 资源参数,例:{ ext: ".png" }
|
||||
* @param onComplete
|
||||
*/
|
||||
public loadRemote<T extends Asset>(url: string, options: IRemoteOptions | null, onComplete?: CompleteCallback<T> | null): void;
|
||||
public loadRemote<T extends Asset>(url: string, onComplete?: CompleteCallback<T> | null): void;
|
||||
public loadRemote<T extends Asset>(url: string, ...args: any): void {
|
||||
var options: IRemoteOptions | null = null;
|
||||
var onComplete: CompleteCallback<T> | null = null;
|
||||
if (args.length == 2) {
|
||||
options = args[0];
|
||||
onComplete = args[1];
|
||||
}
|
||||
else {
|
||||
onComplete = args[0];
|
||||
}
|
||||
assetManager.loadRemote<T>(url, options, onComplete);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载资源包
|
||||
* @param url 资源地址
|
||||
@@ -32,6 +53,14 @@ export default class ResLoader {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载一个资源
|
||||
* @param bundleName 远程包名
|
||||
* @param paths 资源路径
|
||||
* @param type 资源类型
|
||||
* @param onProgress 加载进度回调
|
||||
* @param onComplete 加载完成回调
|
||||
*/
|
||||
public load<T extends Asset>(bundleName: string, paths: string | string[], type: AssetType<T> | null, onProgress: ProgressCallback | null, onComplete: CompleteCallback<T> | null): void;
|
||||
public load<T extends Asset>(bundleName: string, paths: string | string[], onProgress: ProgressCallback | null, onComplete: CompleteCallback<T> | null): void;
|
||||
public load<T extends Asset>(bundleName: string, paths: string | string[], onComplete?: CompleteCallback<T> | null): void;
|
||||
@@ -58,6 +87,14 @@ export default class ResLoader {
|
||||
this.loadByArgs(args);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载文件夹中的资源
|
||||
* @param bundleName 远程包名
|
||||
* @param dir 文件夹名
|
||||
* @param type 资源类型
|
||||
* @param onProgress 加载进度回调
|
||||
* @param onComplete 加载完成回调
|
||||
*/
|
||||
public loadDir<T extends Asset>(bundleName: string, dir: string, type: AssetType<T> | null, onProgress: ProgressCallback | null, onComplete: CompleteCallback<T[]> | null): void;
|
||||
public loadDir<T extends Asset>(bundleName: string, dir: string, onProgress: ProgressCallback | null, onComplete: CompleteCallback<T[]> | null): void;
|
||||
public loadDir<T extends Asset>(bundleName: string, dir: string, onComplete?: CompleteCallback<T[]> | null): void;
|
||||
@@ -85,21 +122,6 @@ export default class ResLoader {
|
||||
this.loadByArgs(args);
|
||||
}
|
||||
|
||||
public loadRemote<T extends Asset>(url: string, options: IRemoteOptions | null, onComplete?: CompleteCallback<T> | null): void;
|
||||
public loadRemote<T extends Asset>(url: string, onComplete?: CompleteCallback<T> | null): void;
|
||||
public loadRemote<T extends Asset>(url: string, ...args: any): void {
|
||||
var options: IRemoteOptions | null = null;
|
||||
var onComplete: CompleteCallback<T> | null = null;
|
||||
if (args.length == 2) {
|
||||
options = args[0];
|
||||
onComplete = args[1];
|
||||
}
|
||||
else {
|
||||
onComplete = args[0];
|
||||
}
|
||||
assetManager.loadRemote<T>(url, options, onComplete);
|
||||
}
|
||||
|
||||
/** 通过资源相对路径释放资源 */
|
||||
public release(path: string, bundleName: string = "resources") {
|
||||
var bundle = assetManager.getBundle(bundleName);
|
||||
|
||||
Reference in New Issue
Block a user