"use strict"; cc._RF.push(module, '58403/n16JCa5sZhNMjZzGo', 'AudioManager'); // Script/module/Music/AudioManager.ts "use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); 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 }); var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property; var AudioManager = /** @class */ (function (_super) { __extends(AudioManager, _super); function AudioManager() { var _this = _super !== null && _super.apply(this, arguments) || this; //背景音乐 _this.audioGameBgm0 = null; _this.baishao_audio = null; _this.cha_audio = null; _this.chixiaodou_audio = null; _this.danggui_audio = null; _this.danshen_audio = null; _this.dazao_audio = null; _this.gancao_audio = null; _this.ganjiang_audio = null; _this.gouqi_audio = null; _this.jingjie_audio = null; _this.jinju_audio = null; _this.lizhi_audio = null; _this.lizi_audio = null; _this.longyan_audio = null; _this.moli_audio = null; _this.muchai_audio = null; _this.mudan_audio = null; _this.mulan_audio = null; _this.pugongying_audio = null; _this.putao_audio = null; _this.renshen_audio = null; _this.taozi_audio = null; _this.zhuye_audio = null; return _this; } AudioManager_1 = AudioManager; AudioManager.prototype.onLoad = function () { if (AudioManager_1._instance == null) { AudioManager_1._instance = this; cc.game.addPersistRootNode(this.node); } else { return; } this.reward = false; this.finish = false; this.rewardCount = 0; this.ctor(); this.preload(); }; 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); }; // static get Instance() // { // if (this._instance == null) // { // this._instance = new AudioManager(); // } // return this._instance; // } 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.playEffect = function (name, callback) { if (this[name]) return this.play(this[name], false, callback, this.mEffectSwitch); }; 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.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; __decorate([ property(cc.AudioClip) ], AudioManager.prototype, "audioGameBgm0", void 0); __decorate([ property(cc.AudioClip) ], AudioManager.prototype, "baishao_audio", void 0); __decorate([ property(cc.AudioClip) ], AudioManager.prototype, "cha_audio", void 0); __decorate([ property(cc.AudioClip) ], AudioManager.prototype, "chixiaodou_audio", void 0); __decorate([ property(cc.AudioClip) ], AudioManager.prototype, "danggui_audio", void 0); __decorate([ property(cc.AudioClip) ], AudioManager.prototype, "danshen_audio", void 0); __decorate([ property(cc.AudioClip) ], AudioManager.prototype, "dazao_audio", void 0); __decorate([ property(cc.AudioClip) ], AudioManager.prototype, "gancao_audio", void 0); __decorate([ property(cc.AudioClip) ], AudioManager.prototype, "ganjiang_audio", void 0); __decorate([ property(cc.AudioClip) ], AudioManager.prototype, "gouqi_audio", void 0); __decorate([ property(cc.AudioClip) ], AudioManager.prototype, "jingjie_audio", void 0); __decorate([ property(cc.AudioClip) ], AudioManager.prototype, "jinju_audio", void 0); __decorate([ property(cc.AudioClip) ], AudioManager.prototype, "lizhi_audio", void 0); __decorate([ property(cc.AudioClip) ], AudioManager.prototype, "lizi_audio", void 0); __decorate([ property(cc.AudioClip) ], AudioManager.prototype, "longyan_audio", void 0); __decorate([ property(cc.AudioClip) ], AudioManager.prototype, "moli_audio", void 0); __decorate([ property(cc.AudioClip) ], AudioManager.prototype, "muchai_audio", void 0); __decorate([ property(cc.AudioClip) ], AudioManager.prototype, "mudan_audio", void 0); __decorate([ property(cc.AudioClip) ], AudioManager.prototype, "mulan_audio", void 0); __decorate([ property(cc.AudioClip) ], AudioManager.prototype, "pugongying_audio", void 0); __decorate([ property(cc.AudioClip) ], AudioManager.prototype, "putao_audio", void 0); __decorate([ property(cc.AudioClip) ], AudioManager.prototype, "renshen_audio", void 0); __decorate([ property(cc.AudioClip) ], AudioManager.prototype, "taozi_audio", void 0); __decorate([ property(cc.AudioClip) ], AudioManager.prototype, "zhuye_audio", void 0); AudioManager = AudioManager_1 = __decorate([ ccclass ], AudioManager); return AudioManager; }(cc.Component)); exports.default = AudioManager; ; // export { AudioManager }; cc._RF.pop();