|
@@ -14,11 +14,11 @@ export class LoaderMgr {
|
|
|
// todo 根据场景来清除资源缓存(什么场景加载的资源就保存到什么场景资源配置上。
|
|
// todo 根据场景来清除资源缓存(什么场景加载的资源就保存到什么场景资源配置上。
|
|
|
// 可能存在的问题:两个场景公用的资源可能会被释放,之后重新加载,可能会有问题
|
|
// 可能存在的问题:两个场景公用的资源可能会被释放,之后重新加载,可能会有问题
|
|
|
// )
|
|
// )
|
|
|
- public SetBundle(bundle) {
|
|
|
|
|
|
|
+ public setBundle(bundle) {
|
|
|
bundle && (this._bundle = bundle);
|
|
bundle && (this._bundle = bundle);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public GetBundle() {
|
|
|
|
|
|
|
+ public getBundle() {
|
|
|
return this._bundle || cc.resources;
|
|
return this._bundle || cc.resources;
|
|
|
}
|
|
}
|
|
|
/*============================================================================================================*/
|
|
/*============================================================================================================*/
|
|
@@ -26,11 +26,11 @@ export class LoaderMgr {
|
|
|
* 异步加载资源
|
|
* 异步加载资源
|
|
|
*/
|
|
*/
|
|
|
/*============================================================================================================*/
|
|
/*============================================================================================================*/
|
|
|
- public LoadAsset(relative_path: string, complete_callback) {
|
|
|
|
|
- let loader = this.GetBundle();
|
|
|
|
|
|
|
+ public loadAsset(relative_path: string, complete_callback) {
|
|
|
|
|
+ let loader = this.getBundle();
|
|
|
loader.load(relative_path, (error, asset) => {
|
|
loader.load(relative_path, (error, asset) => {
|
|
|
if (error) {
|
|
if (error) {
|
|
|
- error('xx.LoadAsset failed ... and path = ' + relative_path, '===error:', JSON.stringify(error));
|
|
|
|
|
|
|
+ error('xx.loadAsset failed ... and path = ' + relative_path, '===error:', JSON.stringify(error));
|
|
|
return;
|
|
return;
|
|
|
} else {
|
|
} else {
|
|
|
complete_callback && complete_callback(asset);
|
|
complete_callback && complete_callback(asset);
|
|
@@ -43,11 +43,11 @@ export class LoaderMgr {
|
|
|
* 根据类型异步加载
|
|
* 根据类型异步加载
|
|
|
*/
|
|
*/
|
|
|
/*============================================================================================================*/
|
|
/*============================================================================================================*/
|
|
|
- public LoadAssetByType(relative_path: string, asset_type, complete_callback?: Function) {
|
|
|
|
|
|
|
+ public loadAssetByType(relative_path: string, asset_type, complete_callback?: Function) {
|
|
|
return new Promise((resolve: (data) => void, reject) => {
|
|
return new Promise((resolve: (data) => void, reject) => {
|
|
|
- this.GetBundle().load(relative_path, asset_type, (error, asset) => {
|
|
|
|
|
|
|
+ this.getBundle().load(relative_path, asset_type, (error, asset) => {
|
|
|
if (error) {
|
|
if (error) {
|
|
|
- error('xx.LoadAssetByType failed ... and path = ' + relative_path, '==error:', JSON.stringify(error));
|
|
|
|
|
|
|
+ error('xx.loadAssetByType failed ... and path = ' + relative_path, '==error:', JSON.stringify(error));
|
|
|
reject();
|
|
reject();
|
|
|
return;
|
|
return;
|
|
|
} else {
|
|
} else {
|
|
@@ -64,9 +64,9 @@ export class LoaderMgr {
|
|
|
* @param type 资源类型,如果为空,则返回所有类型文件地址
|
|
* @param type 资源类型,如果为空,则返回所有类型文件地址
|
|
|
*/
|
|
*/
|
|
|
/*============================================================================================================*/
|
|
/*============================================================================================================*/
|
|
|
- public GetDirUrlsRecursion(path, type) {
|
|
|
|
|
|
|
+ public getDirUrlsRecursion(path, type) {
|
|
|
let urls = [];
|
|
let urls = [];
|
|
|
- this.GetBundle().getDirWithPath(path, type, urls);
|
|
|
|
|
|
|
+ this.getBundle().getDirWithPath(path, type, urls);
|
|
|
let arr_path = [];
|
|
let arr_path = [];
|
|
|
for (let i = 0; i < urls.length; i++) {
|
|
for (let i = 0; i < urls.length; i++) {
|
|
|
const element = urls[i].path;
|
|
const element = urls[i].path;
|
|
@@ -80,7 +80,7 @@ export class LoaderMgr {
|
|
|
* 通过config构造uuid数组加载
|
|
* 通过config构造uuid数组加载
|
|
|
*/
|
|
*/
|
|
|
/*============================================================================================================*/
|
|
/*============================================================================================================*/
|
|
|
- public LoadByConfigUseUuids(assets_config, progress_callback, complete_callback) {
|
|
|
|
|
|
|
+ public loadByConfigUseUuids(assets_config, progress_callback, complete_callback) {
|
|
|
// let uuids = [];
|
|
// let uuids = [];
|
|
|
// let urls = [];
|
|
// let urls = [];
|
|
|
// let len = assets_config.length;
|
|
// let len = assets_config.length;
|
|
@@ -88,7 +88,7 @@ export class LoaderMgr {
|
|
|
// let config = assets_config[i];
|
|
// let config = assets_config[i];
|
|
|
// let path = config.path;
|
|
// let path = config.path;
|
|
|
// let type = config.type;
|
|
// let type = config.type;
|
|
|
- // let _uuids = this.GetBundle().getDirWithPath(path, type, urls);
|
|
|
|
|
|
|
+ // let _uuids = this.getBundle().getDirWithPath(path, type, urls);
|
|
|
// uuids = uuids.concat(_uuids);
|
|
// uuids = uuids.concat(_uuids);
|
|
|
// }
|
|
// }
|
|
|
|
|
|
|
@@ -97,7 +97,7 @@ export class LoaderMgr {
|
|
|
// let DoWithAssetItemOnProgress = function (completed_count, total_count, item) {
|
|
// let DoWithAssetItemOnProgress = function (completed_count, total_count, item) {
|
|
|
// let asset = item.content;
|
|
// let asset = item.content;
|
|
|
// if (asset instanceof JsonAsset) {
|
|
// if (asset instanceof JsonAsset) {
|
|
|
- // xx.Dict.LoadByAsset(asset);
|
|
|
|
|
|
|
+ // xx.Dict.loadByAsset(asset);
|
|
|
// }
|
|
// }
|
|
|
// progress_callback && progress_callback(completed_count, total_count);
|
|
// progress_callback && progress_callback(completed_count, total_count);
|
|
|
// };
|
|
// };
|
|
@@ -109,7 +109,7 @@ export class LoaderMgr {
|
|
|
// loader._loadResUuids(uuids, DoWithAssetItemOnProgress, DoWithAssetOnComplete, urls);
|
|
// loader._loadResUuids(uuids, DoWithAssetItemOnProgress, DoWithAssetOnComplete, urls);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public LoadAssetsByConfig(assets_config, progress_callback, complete_callback) {
|
|
|
|
|
|
|
+ public loadAssetsByConfig(assets_config, progress_callback, complete_callback) {
|
|
|
let total_count = 0;
|
|
let total_count = 0;
|
|
|
let complete_count = 0;
|
|
let complete_count = 0;
|
|
|
for (let i = 0; i < assets_config.length; i++) {
|
|
for (let i = 0; i < assets_config.length; i++) {
|
|
@@ -118,13 +118,13 @@ export class LoaderMgr {
|
|
|
let type = config.type;
|
|
let type = config.type;
|
|
|
|
|
|
|
|
let urls = [];
|
|
let urls = [];
|
|
|
- this.GetBundle().getDirWithPath(path, type, urls);
|
|
|
|
|
|
|
+ this.getBundle().getDirWithPath(path, type, urls);
|
|
|
total_count += urls.length;
|
|
total_count += urls.length;
|
|
|
cc.log('预加载资源:%o', urls);
|
|
cc.log('预加载资源:%o', urls);
|
|
|
let callback = config.cb;
|
|
let callback = config.cb;
|
|
|
for (let i = 0; i < urls.length; i++) {
|
|
for (let i = 0; i < urls.length; i++) {
|
|
|
let path = urls[i].path;
|
|
let path = urls[i].path;
|
|
|
- this.GetBundle().load(path, type, function (err, spriteFrame) {
|
|
|
|
|
|
|
+ this.getBundle().load(path, type, function (err, spriteFrame) {
|
|
|
if (err) {
|
|
if (err) {
|
|
|
cc.error(err.message || err);
|
|
cc.error(err.message || err);
|
|
|
return;
|
|
return;
|
|
@@ -145,15 +145,15 @@ export class LoaderMgr {
|
|
|
/**
|
|
/**
|
|
|
*/
|
|
*/
|
|
|
/*============================================================================================================*/
|
|
/*============================================================================================================*/
|
|
|
- public ReleaseResByPathAndType(path = '', type) {
|
|
|
|
|
|
|
+ public releaseResByPathAndType(path = '', type) {
|
|
|
if (!path || !type) return;
|
|
if (!path || !type) return;
|
|
|
|
|
|
|
|
- let urls = this.GetDirUrlsRecursion(path, type);
|
|
|
|
|
|
|
+ let urls = this.getDirUrlsRecursion(path, type);
|
|
|
let len = urls.length;
|
|
let len = urls.length;
|
|
|
for (let i = 0; i < len; ++i) {
|
|
for (let i = 0; i < len; ++i) {
|
|
|
let url = urls[i];
|
|
let url = urls[i];
|
|
|
- let atlas = this.GetBundle().getRes(url, type);
|
|
|
|
|
- let deps = this.GetBundle().getDependsRecursively(atlas);
|
|
|
|
|
|
|
+ let atlas = this.getBundle().getRes(url, type);
|
|
|
|
|
+ let deps = this.getBundle().getDependsRecursively(atlas);
|
|
|
// assetManager.releaseAsset(deps);
|
|
// assetManager.releaseAsset(deps);
|
|
|
}
|
|
}
|
|
|
cc.sys.garbageCollect();
|
|
cc.sys.garbageCollect();
|
|
@@ -164,12 +164,12 @@ export class LoaderMgr {
|
|
|
* 同步获取已经预加载的图集中的spriteframe 此接口进入游戏后生效
|
|
* 同步获取已经预加载的图集中的spriteframe 此接口进入游戏后生效
|
|
|
*/
|
|
*/
|
|
|
/*============================================================================================================*/
|
|
/*============================================================================================================*/
|
|
|
- public GetSpriteFrameFromAtlas(sprite_frame_name, path = '/Atlas') {
|
|
|
|
|
- let urls = this.GetDirUrlsRecursion(path, cc.SpriteAtlas);
|
|
|
|
|
|
|
+ public getSpriteFrameFromAtlas(sprite_frame_name, path = '/Atlas') {
|
|
|
|
|
+ let urls = this.getDirUrlsRecursion(path, cc.SpriteAtlas);
|
|
|
let len = urls.length;
|
|
let len = urls.length;
|
|
|
for (let i = 0; i < len; i++) {
|
|
for (let i = 0; i < len; i++) {
|
|
|
let url = urls[i];
|
|
let url = urls[i];
|
|
|
- let atlas: any = this.GetBundle().getRes(url, cc.SpriteAtlas);//resources.get
|
|
|
|
|
|
|
+ let atlas: any = this.getBundle().getRes(url, cc.SpriteAtlas);//resources.get
|
|
|
if (atlas) {
|
|
if (atlas) {
|
|
|
let sf = atlas.getSpriteFrame(sprite_frame_name);
|
|
let sf = atlas.getSpriteFrame(sprite_frame_name);
|
|
|
if (sf) return sf;
|
|
if (sf) return sf;
|
|
@@ -183,8 +183,8 @@ export class LoaderMgr {
|
|
|
* @param {string} sprite_frame_path 资源相对于resource下的路径
|
|
* @param {string} sprite_frame_path 资源相对于resource下的路径
|
|
|
*/
|
|
*/
|
|
|
/*============================================================================================================*/
|
|
/*============================================================================================================*/
|
|
|
- public GetSpriteFrame(sprite_frame_path) {
|
|
|
|
|
- let res = this.GetBundle().getRes(sprite_frame_path, cc.SpriteFrame);
|
|
|
|
|
|
|
+ public getSpriteFrame(sprite_frame_path) {
|
|
|
|
|
+ let res = this.getBundle().getRes(sprite_frame_path, cc.SpriteFrame);
|
|
|
return res;
|
|
return res;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -193,8 +193,8 @@ export class LoaderMgr {
|
|
|
* SpriteFrame有一个_uuid的属性,根据uuid去loader里面查找路径加载路径
|
|
* SpriteFrame有一个_uuid的属性,根据uuid去loader里面查找路径加载路径
|
|
|
*/
|
|
*/
|
|
|
/*============================================================================================================*/
|
|
/*============================================================================================================*/
|
|
|
- public ParseUuidToUrl(uuid) {
|
|
|
|
|
- let path_to_uuid = this.GetBundle()._pathToUuid;
|
|
|
|
|
|
|
+ public parseUuidToUrl(uuid) {
|
|
|
|
|
+ let path_to_uuid = this.getBundle()._pathToUuid;
|
|
|
for (let key in path_to_uuid) {
|
|
for (let key in path_to_uuid) {
|
|
|
let entrys = path_to_uuid[key];
|
|
let entrys = path_to_uuid[key];
|
|
|
if (entrys instanceof Array) {
|
|
if (entrys instanceof Array) {
|
|
@@ -212,7 +212,7 @@ export class LoaderMgr {
|
|
|
return '';
|
|
return '';
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public LoadRemoteTexture(url, role_id, callback) {
|
|
|
|
|
|
|
+ public loadRemoteTexture(url, role_id, callback) {
|
|
|
if (this._profile_res[role_id]) {
|
|
if (this._profile_res[role_id]) {
|
|
|
let spf = this._profile_res[role_id];
|
|
let spf = this._profile_res[role_id];
|
|
|
callback && callback(role_id, spf);
|
|
callback && callback(role_id, spf);
|
|
@@ -222,7 +222,7 @@ export class LoaderMgr {
|
|
|
|
|
|
|
|
if (!cc.sys.isNative) return;
|
|
if (!cc.sys.isNative) return;
|
|
|
|
|
|
|
|
- this.GetBundle().load({ url: url, type: 'png' }, (err, tex) => {
|
|
|
|
|
|
|
+ this.getBundle().load({ url: url, type: 'png' }, (err, tex) => {
|
|
|
cc.log('===get_texture:', role_id);
|
|
cc.log('===get_texture:', role_id);
|
|
|
if (err) {
|
|
if (err) {
|
|
|
cc.log('===err:', err);
|
|
cc.log('===err:', err);
|
|
@@ -237,7 +237,7 @@ export class LoaderMgr {
|
|
|
* - sprite_frame_name:要获取的纹理名字
|
|
* - sprite_frame_name:要获取的纹理名字
|
|
|
* - arr_atlas:图集列表
|
|
* - arr_atlas:图集列表
|
|
|
*/
|
|
*/
|
|
|
- public GetSpriteFrameByArrAlst(sprite_frame_name: string, arr_atlas: Array<cc.SpriteAtlas>): cc.SpriteFrame {
|
|
|
|
|
|
|
+ public getSpriteFrameByArrAlst(sprite_frame_name: string, arr_atlas: Array<cc.SpriteAtlas>): cc.SpriteFrame {
|
|
|
let count = arr_atlas.length;
|
|
let count = arr_atlas.length;
|
|
|
for (let i = 0; i < count; i++) {
|
|
for (let i = 0; i < count; i++) {
|
|
|
let _atlas = arr_atlas[i];
|
|
let _atlas = arr_atlas[i];
|