觉醒时刻
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.
 
 
 

81 lines
2.5 KiB

/*
* @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))
}
}
}