觉醒时刻
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
juexingshike/assets/FrameWork/Mgr/RemoteMgr.ts

51 lines
1.6 KiB

/*
* @Descripttion:
* @version: 1.0.0
* @Author: YeeChan
* @Date: 2020-07-23 16:59:58
*/
/**
* 远程资源管理
* 下载后的 cc.Asset 计数加1后 放入 数组存储,下次直接拿取
*/
export default class RemoteMgr {
private static remoteArrayTexture_custom: { [key: string]: cc.Texture2D; } = {}
/**
* 移除所有已加载的
*/
public static removeAllRemote_custom() {
for (let k in this.remoteArrayTexture_custom) {
this.remoteArrayTexture_custom[k].decRef();
}
this.remoteArrayTexture_custom = {};
}
/**
* 下载远程图片资源,成功后放入数组,计数自增
* @param url
* @param listener
*/
public static loadRemote_custom(url: string, listener: FMListener) {
let texture2D = this.remoteArrayTexture_custom[url];
if (texture2D) {
callFM_custom(listener, null, this.remoteArrayTexture_custom[url]);
} else {
cc.assetManager.loadRemote(url, (error, data) => {
if (error) {
callFM_custom(listener, error, null);
return;
} else {
if (!this.remoteArrayTexture_custom[url]) {
//@ts-ignore
this.remoteArrayTexture_custom[url] = data;
this.remoteArrayTexture_custom[url].addRef();//计数+1
}
callFM_custom(listener, null, this.remoteArrayTexture_custom[url]);
}
})
}
}
}