add assets_manager_set_fallback_load_asset

This commit is contained in:
lixianjing 2022-04-18 11:52:55 +08:00
parent f78d9344d6
commit 73377f4b2d
2 changed files with 31 additions and 0 deletions

View File

@ -544,6 +544,11 @@ asset_info_t* assets_manager_load_ex(assets_manager_t* am, asset_type_t type, ui
return am->custom_load_asset(am->custom_load_asset_ctx, type, subtype, name);
}
info = assets_manager_load_impl(am, type, subtype, name);
if (info == NULL && am->fallback_load_asset != NULL) {
info = am->fallback_load_asset(am->fallback_load_asset_ctx, type, subtype, name);
}
if (info != NULL) {
assets_manager_dispatch_event(am, EVT_ASSET_MANAGER_LOAD_ASSET, info);
}
@ -832,6 +837,16 @@ ret_t assets_manager_set_custom_load_asset(assets_manager_t* am,
return RET_OK;
}
ret_t assets_manager_set_fallback_load_asset(assets_manager_t* am,
assets_manager_load_asset_t fallback_load_asset,
void* ctx) {
return_value_if_fail(am != NULL, RET_BAD_PARAMS);
am->fallback_load_asset_ctx = ctx;
am->fallback_load_asset = fallback_load_asset;
return RET_OK;
}
ret_t assets_manager_destroy(assets_manager_t* am) {
return_value_if_fail(am != NULL, RET_BAD_PARAMS);
emitter_deinit(EMITTER(am));

View File

@ -85,6 +85,9 @@ struct _assets_manager_t {
void* custom_load_asset_ctx;
assets_manager_load_asset_t custom_load_asset;
void* fallback_load_asset_ctx;
assets_manager_load_asset_t fallback_load_asset;
void* custom_build_asset_dir_ctx;
assets_manager_build_asset_dir_t custom_build_asset_dir;
@ -331,6 +334,19 @@ ret_t assets_manager_set_custom_load_asset(assets_manager_t* am,
assets_manager_load_asset_t custom_load_asset,
void* ctx);
/**
* @method assets_manager_set_fallback_load_asset
*
*
* @param {assets_manager_t*} am asset manager对象
* @param {assets_manager_load_asset_t} fallback_load_asset
* @param {void*} ctx
*
* @return {ret_t} RET_OK表示成功
*/
ret_t assets_manager_set_fallback_load_asset(assets_manager_t* am,
assets_manager_load_asset_t fallback_load_asset,
void* ctx);
/**
* @method assets_manager_clear_cache
*