12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- import { _EJsonRes } from "../Data/CommonDataType";
- import { EventName } from "../Event/EventName";
- import EventManager from "../Event/EventManager";
- import Tool from "../Tool/Tool";
- /**
- * 音频资源 - 数据层
- */
- export default class AudioResources {
- /**资源列表 */
- private static resources: Map<string, any> = new Map<string, any>();
- /**资源包 */
- private static bundle: cc.AssetManager.Bundle = null;
- /**加载音频资源 */
- public static loadAudioResources (audioRes: Array<string>, denominator: number, currentProgress: number, callback: Function) {
- Tool.log("加载音频资源");
- let complete = () => {
- Tool.log(this.resources);
- Tool.log("加载完毕");
- Tool.log("");
- if (callback == null) {
- // 发送初始加载完成 本地消息
- EventManager.sendEvent(EventName.Res.Res_LoadComplete);
- }
- else {
- callback();
- }
- }
- if (audioRes.length == 0) {
- complete();
- }
- else {
- cc.assetManager.loadBundle("res/audio", (err: Error, audio: cc.AssetManager.Bundle) => {
- this.bundle = audio;
- audio.load(audioRes, cc.Asset, (finish: number, total: number, item: cc.AssetManager.RequestItem) => {
- // 发送初始加载进度 本地消息
- EventManager.sendEvent(EventName.Res.Res_LoadProgress, (finish/total)*denominator + currentProgress);
- }, (err, assets: Array<cc.Asset>) => {
- Tool.log(err);
-
- for (let index in assets) {
- this.resources.set(assets[index].name, assets[index]);
- }
-
- complete();
- });
- });
- }
- }
- /**获得Audio资源 */
- public static getResources (name: string): any {
- let _name: string = name;
- if (name.includes("/") == true) {
- _name = name.substring(name.indexOf("/")+1);
- }
-
- if (this.resources.get(_name) != null) {
- return this.resources.get(_name);
- }
- else {
- return this.bundle.get(_name);
- }
- }
- }
|