ShenNong/library/imports/58/58403fe7-d7a2-426b-9b19-84d3236731a8.js
2024-06-21 18:44:06 +08:00

216 lines
6.9 KiB
JavaScript

"use strict";
cc._RF.push(module, '58403/n16JCa5sZhNMjZzGo', 'AudioManager');
// Script/module/Music/AudioManager.ts
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AudioManager = void 0;
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var AudioManager = /** @class */ (function () {
function AudioManager() {
//背景音乐
this.audioGameBgm0 = null;
//跳跃
this.audioButtonClick = null;
//落地上
this.audioWarning = null;
//碰撞
this.audioWin = null;
}
AudioManager_1 = AudioManager;
AudioManager.playWarning = function () {
throw new Error('Method not implemented.');
};
AudioManager.prototype.ctor = function () {
this.mAudioMap = {};
/**
* 默认音量大小
* @type {number}
*/
this.bgMusicVolume = 0.1;
this.effectMusicVolume = 1;
this.mMusicSwitch = 1;
this.mEffectSwitch = 1;
};
AudioManager.prototype.play = function (audioSource, loop, callback, isBgMusic) {
if (isBgMusic && !this.mMusicSwitch)
return;
if (!isBgMusic && !this.mEffectSwitch)
return;
var volume = isBgMusic ? this.bgMusicVolume : this.effectMusicVolume;
if (cc.sys.isBrowser) {
if (audioSource == this.brickSound) {
volume = 0.1;
}
volume = 1;
var context = cc.audioEngine.play(audioSource, loop, volume);
if (callback) {
cc.audioEngine.setFinishCallback(context, function () {
callback.call(this);
}.bind(this));
}
// cc.wwx.OutPut.log('play audio effect isBrowser: ' + context.src);
this.mAudioMap[audioSource] = context;
return audioSource;
}
else {
return audioSource;
}
};
AudioManager.prototype.save = function () {
// cc.wwx.Storage.setItem(cc.wwx.Storage.Key_Setting_Music_Volume, this.mMusicSwitch);
// cc.wwx.Storage.setItem(cc.wwx.Storage.Key_Setting_Effect_Volume, this.mEffectSwitch);
};
Object.defineProperty(AudioManager, "Instance", {
get: function () {
if (this._instance == null) {
this._instance = new AudioManager_1();
}
return this._instance;
},
enumerable: false,
configurable: true
});
AudioManager.prototype.init = function () {
this.reward = false;
this.finish = false;
this.rewardCount = 0;
this.ctor();
this.preload();
};
AudioManager.prototype.preload = function () {
if (!(cc.sys.platform === cc.sys.WECHAT_GAME)) {
return;
}
var musics = [
this.audioGameBgm0,
];
musics.forEach(function (path) {
});
};
AudioManager.prototype.getAudioMusicSwitch = function () {
return this.mMusicSwitch;
};
AudioManager.prototype.getAudioEffectSwitch = function () {
return this.mEffectSwitch;
};
AudioManager.prototype.trunAudioSound = function (on) {
this.switchMusic(on);
this.switchEffect(on);
};
AudioManager.prototype.switchMusic = function (on) {
if (this.mMusicSwitch != (on ? 1 : 0)) {
this.mMusicSwitch = 1 - this.mMusicSwitch;
// this.save();
}
if (on) {
this.playMusicGame();
}
else {
this.stopMusic();
}
};
AudioManager.prototype.switchEffect = function (on) {
if (this.mEffectSwitch != (on ? 1 : 0)) {
this.mEffectSwitch = 1 - this.mEffectSwitch;
// this.save();
}
};
AudioManager.prototype.onHide = function () {
cc.audioEngine.pauseAll();
};
AudioManager.prototype.onShow = function () {
cc.audioEngine.resumeAll();
};
AudioManager.prototype.playMusic = function (key, callback, loop) {
loop = typeof loop == 'undefined' || loop ? true : false;
this.stopMusic();
this.mMusicKey = this.play(key, loop, callback, true);
};
/**
* 游戏背景音乐
*/
AudioManager.prototype.playMusicGame = function () {
this.playMusic(this.audioGameBgm0, {}, true);
};
/**
* 停止背景音乐播放
*/
AudioManager.prototype.stopMusic = function () {
// cc.wwx.OutPut.log('stopMusic audio effect wx: ' + this.mMusicKey);
var context = this.mAudioMap[this.mMusicKey];
if (typeof (context) != 'undefined') {
if (cc.sys.isBrowser) {
cc.audioEngine.stop(context);
}
else {
context.stop();
}
cc.audioEngine.stop(context);
}
};
//播放音效
AudioManager.prototype.playEffect = function (name, callback) {
if (this[name])
return this.play(this[name], false, callback, this.mEffectSwitch);
};
/*
* 游戏开始音效
*
*/
AudioManager.prototype.playGameStart = function () {
};
/*
* 失败的游戏结束
*/
AudioManager.prototype.playGameOver = function () {
};
/*
* 成功的游戏结束
*/
AudioManager.prototype.playGameResultFailed = function () {
};
/*
* 成功的游戏结束
*/
AudioManager.prototype.playGameResultSuccess = function () {
};
/**
* 报警的音效
*/
/**
* 按钮
*/
AudioManager.prototype.playAudioButton = function () {
return this.play(this.audioButtonClick, false, null, this.mEffectSwitch);
};
var AudioManager_1;
AudioManager._instance = null;
__decorate([
property(cc.AudioClip)
], AudioManager.prototype, "audioGameBgm0", void 0);
__decorate([
property(cc.AudioClip)
], AudioManager.prototype, "audioButtonClick", void 0);
__decorate([
property(cc.AudioClip)
], AudioManager.prototype, "audioWarning", void 0);
__decorate([
property(cc.AudioClip)
], AudioManager.prototype, "audioWin", void 0);
AudioManager = AudioManager_1 = __decorate([
ccclass('AudioManager')
], AudioManager);
return AudioManager;
}());
exports.AudioManager = AudioManager;
;
// export { AudioManager };
cc._RF.pop();