2fcf4edb-8c90-4540-b565-0c42a8260a7a.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. "use strict";
  2. cc._RF.push(module, '2fcf47bjJBFQLVlDEKoJgp6', 'AudioMgr');
  3. // scripts/Framework/AudioMgr.ts
  4. "use strict";
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. var CocosZ_1 = require("./CocosZ");
  7. var AudioMgr = /** @class */ (function () {
  8. function AudioMgr() {
  9. this._curMusicId = -1;
  10. this._curMusicClip = null;
  11. this._videoOn = false;
  12. this._guideAudioId = -1;
  13. this.audioIdList = [];
  14. }
  15. Object.defineProperty(AudioMgr, "inst", {
  16. get: function () {
  17. if (!AudioMgr._inst) {
  18. AudioMgr._inst = new AudioMgr();
  19. }
  20. return AudioMgr._inst;
  21. },
  22. enumerable: false,
  23. configurable: true
  24. });
  25. Object.defineProperty(AudioMgr.prototype, "videoOn", {
  26. get: function () {
  27. return this._videoOn;
  28. },
  29. set: function (value) {
  30. this._videoOn = value;
  31. },
  32. enumerable: false,
  33. configurable: true
  34. });
  35. Object.defineProperty(AudioMgr.prototype, "AudioOn", {
  36. get: function () {
  37. return CocosZ_1.cocosz.dataMgr.AudioOn;
  38. },
  39. set: function (value) {
  40. CocosZ_1.cocosz.dataMgr.AudioOn = value;
  41. if (value) {
  42. if (this._curMusicClip) {
  43. this._curMusicId = this._play(this._curMusicClip, true, 1);
  44. }
  45. }
  46. else {
  47. this.stopAll();
  48. }
  49. },
  50. enumerable: false,
  51. configurable: true
  52. });
  53. // audioList: Array<cc.AudioClip> = [];
  54. /**
  55. * 播放背景音乐
  56. * @param id
  57. */
  58. AudioMgr.prototype.playBgm = function (loop) {
  59. if (loop === void 0) { loop = true; }
  60. if (!this.AudioOn)
  61. return;
  62. var str = "bgm_ui";
  63. if (cc.director.getScene().name == "Home") {
  64. str = "bgm_ui";
  65. }
  66. else if (cc.director.getScene().name == "Game") {
  67. str = "bgm_6";
  68. }
  69. else {
  70. return;
  71. }
  72. var res_bgm = CocosZ_1.cocosz.resMgr.getRes(str, cc.AudioClip);
  73. if (res_bgm) {
  74. this.stopAll();
  75. setTimeout(function () { cc.audioEngine.playMusic(res_bgm, true); }, 0);
  76. }
  77. };
  78. /** 播放新手音效 */
  79. AudioMgr.prototype.playGuideAudio = function (name) {
  80. if (this._guideAudioId != -1) {
  81. cc.audioEngine.stop(this._guideAudioId);
  82. this._guideAudioId = -1;
  83. }
  84. this._guideAudioId = CocosZ_1.cocosz.audioMgr.playEffect(name);
  85. };
  86. /**
  87. * 播放音效
  88. * @param url 音频路径
  89. * @param loop 是否循环
  90. * @param volume 音量
  91. */
  92. AudioMgr.prototype.playEffect = function (url, loop, volume) {
  93. if (loop === void 0) { loop = false; }
  94. if (volume === void 0) { volume = 1; }
  95. if (this.videoOn || !this.AudioOn)
  96. return;
  97. var music = CocosZ_1.cocosz.resMgr.getRes(url, cc.AudioClip);
  98. if (music) {
  99. this.audioIdList[url] = cc.audioEngine.play(music, loop, volume);
  100. return this.audioIdList[url];
  101. }
  102. };
  103. /**
  104. * 播放音效
  105. * @param url 音频路径
  106. * @param loop 是否循环
  107. * @param volume 音量
  108. */
  109. AudioMgr.prototype.playClip = function (clip, loop, volume) {
  110. if (loop === void 0) { loop = false; }
  111. if (volume === void 0) { volume = 1; }
  112. if (this.videoOn || !this.AudioOn)
  113. return;
  114. if (clip && clip.isValid) {
  115. this.audioIdList[clip.name] = cc.audioEngine.play(clip, loop, volume);
  116. return this.audioIdList[clip.name];
  117. }
  118. };
  119. AudioMgr.prototype.stopEffect = function (url) {
  120. if (this.audioIdList[url] >= 0) {
  121. cc.audioEngine.stop(this.audioIdList[url]);
  122. this.audioIdList[url] = null;
  123. }
  124. };
  125. AudioMgr.prototype.checkEffect = function (url) {
  126. if (this.audioIdList[url]) {
  127. return true;
  128. }
  129. return false;
  130. };
  131. /**按钮音效 */
  132. AudioMgr.prototype.playBtnEffect = function () {
  133. var _this = this;
  134. return new Promise(function (resolve, reject) {
  135. _this.playEffect("btn");
  136. setTimeout(function () {
  137. resolve(1);
  138. }, 200);
  139. });
  140. };
  141. /**
  142. * 播放胜利音效
  143. */
  144. AudioMgr.prototype.playEffectWinner = function (volume) {
  145. var _this = this;
  146. if (volume === void 0) { volume = 1; }
  147. this.stopAll();
  148. setTimeout(function () {
  149. if (CocosZ_1.cocosz.gameMode != 6) {
  150. _this.playEffect("win");
  151. }
  152. else {
  153. _this.playEffect("zombie_win");
  154. }
  155. });
  156. };
  157. /**
  158. * 播放失败音效
  159. */
  160. AudioMgr.prototype.playEffectFailed = function (volume) {
  161. var _this = this;
  162. if (volume === void 0) { volume = 1; }
  163. this.stopAll();
  164. setTimeout(function () {
  165. if (CocosZ_1.cocosz.gameMode != 6) {
  166. _this.playEffect("fail");
  167. }
  168. else {
  169. _this.playEffect("zombie_fail");
  170. }
  171. });
  172. };
  173. /**
  174. * 暂停所有音效
  175. */
  176. AudioMgr.prototype.pauseAll = function () {
  177. cc.audioEngine.pauseAll();
  178. };
  179. AudioMgr.prototype.resumeAll = function () {
  180. // utils.delayCall(() => {
  181. if (!this._videoOn)
  182. cc.audioEngine.resumeAll();
  183. // }, 0)
  184. };
  185. AudioMgr.prototype.stopAll = function () {
  186. cc.audioEngine.stopAll();
  187. this.audioIdList = [];
  188. };
  189. AudioMgr.prototype._play = function (clip, loop, volume) {
  190. if (!this.AudioOn)
  191. return -1;
  192. return cc.audioEngine.play(clip, loop, volume);
  193. };
  194. return AudioMgr;
  195. }());
  196. exports.default = AudioMgr;
  197. cc._RF.pop();