SoundManager.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. var t = require;
  2. var e = module;
  3. var i = exports;
  4. Object.defineProperty(i, "__esModule", {value: !0}), (i.AUDIO_DIR = void 0);
  5. const s = t("App"),
  6. o = t("SoundBg"),
  7. a = t("SoundEffects");
  8. i.AUDIO_DIR = "audio/";
  9. var {} = cc._decorator;
  10. class n {
  11. constructor() {
  12. (this.saveKey = "SoundManager"),
  13. (this.bgOn = !0),
  14. (this.effectOn = !0),
  15. (this.bgVolume = 0.3),
  16. (this.effectVolume = 0.5),
  17. (this.bg = new o.default()),
  18. (this.effect = new a.default());
  19. }
  20. playEffect(t) {
  21. return this.effectOn ? this.effect.play(t) : null;
  22. }
  23. playLoopEffect(t) {
  24. if (this.effectOn) return this.effect.loopPlay(t);
  25. }
  26. stopLoopEffect(t) {
  27. this.effect.stopLoopEffect(t);
  28. }
  29. playBg(t) {
  30. (this.currBg = t), this.bgOn && (this.bg.play(t), (this.isPlaying = !0));
  31. }
  32. stopBg() {
  33. this.bg.stop(), (this.isPlaying = !1);
  34. }
  35. setEffectOn(t) {
  36. (this.effectOn = t), this.saveData();
  37. }
  38. getEffectStatus() {
  39. return this.effectOn;
  40. }
  41. setBgOn(t) {
  42. (this.bgOn = t), this.bgOn ? this.currBg && this.playBg(this.currBg) : this.stopBg(), this.saveData();
  43. }
  44. getBgStatus() {
  45. return this.bgOn;
  46. }
  47. setBgVolume(t) {
  48. (t = Math.min(t, 1)), (t = Math.max(t, 0)), (this.bgVolume = t), this.bg.setVolume(this.bgVolume);
  49. }
  50. getBgVolume() {
  51. return this.bgVolume;
  52. }
  53. setEffectVolume(t) {
  54. (t = Math.min(t, 1)), (t = Math.max(t, 0)), (this.effectVolume = t), this.effect.setVolume(this.effectVolume);
  55. }
  56. getEffectVolume() {
  57. return this.effectVolume;
  58. }
  59. createMemento() {
  60. return {effectOn: this.effectOn, bgOn: this.bgOn};
  61. }
  62. setMemento(t) {
  63. t ? ((this.bgOn = t.bgOn), (this.effectOn = t.effectOn)) : ((this.bgOn = !0), (this.effectOn = !0)),
  64. this.bg.setVolume(this.bgVolume),
  65. this.effect.setVolume(this.effectVolume);
  66. }
  67. pauseMusic() {
  68. this.bg.stop();
  69. }
  70. resumeMusic() {
  71. this.bg && this.currBg && (this.stopBg(), this.playBg(this.currBg));
  72. }
  73. pauseEffect() {
  74. this.effect.pauseEffect();
  75. }
  76. resumeEffect() {
  77. this.effect.resumeEffect();
  78. }
  79. getBgPlayingStatus() {
  80. return this.isPlaying;
  81. }
  82. saveData() {
  83. s.default.SaveManage.save(this.saveKey);
  84. }
  85. }
  86. (i.default = n).CLEAR_TIME = 18e4;