我智商爆棚
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.

82 lines
2.5 KiB

4 weeks ago
/*
* @Descripttion:
* @version: 1.0.0
* @Author: YeeChan
* @Date: 2020-07-23 16:59:58
*/
import { FMListener, callFM_custom, handleFM_custom } from "../Interface/FMInterface";
import { LogUtils } from "../Util/LogUtils";
/**
* https://docs.cocos.com/creator/manual/zh/scripting/asset-bundle.html
* bundle 便
* cc.assetManager.loadBundle
* Bundle
*/
export default class BundleMgr {
/**
*
* @param bundleName
* @param listener
*/
public static loadBundleByName_custom(bundleName: string, listener: FMListener) {
LogUtils.info_custom("加载资源包 " + bundleName);
cc.assetManager.loadBundle(bundleName, function (err: Error, bundle: cc.AssetManager.Bundle) {
console.log(bundle)
callFM_custom(listener, err, bundle);
});
}
/**
*
* @param bundleName
*/
public static getBundle_custom(bundleName: string): cc.AssetManager.Bundle {
return cc.assetManager.getBundle(bundleName);
}
/**
*
*
* @param bundleName
* @param releaseAll true
*/
public static removeBundle_custom(bundleName: string, releaseAll: boolean = true) {
let bundle = this.getBundle_custom(bundleName);
if (bundle && releaseAll) {
//释放所有属于 Asset Bundle 的资源
bundle.releaseAll();
}
cc.assetManager.removeBundle(bundle);
}
/**
*
* @param bundleName
* @param sceneName
* @param listener
*/
public static runScene_custom(bundleName: string, sceneName: string, listener: FMListener = null) {
let bundle = this.getBundle_custom(bundleName);
if (bundle) {
bundle.loadScene(sceneName, function (error, scene) {
if (listener) {
callFM_custom(listener);
}
cc.director.runScene(scene);
});
} else {
this.loadBundleByName_custom(bundleName, handleFM_custom((err: Error, bundle: cc.AssetManager.Bundle) => {
bundle.loadScene(sceneName, function (error, scene) {
if (listener) {
callFM_custom(listener);
}
cc.director.runScene(scene);
});
}, this))
}
}
}