ea470a0a-d1f3-4de3-b067-5caa1940adcc.js
3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
"use strict";
cc._RF.push(module, 'ea470oK0fNN47BnXKoZQK3M', 'AudioManager');
// script/common/gameplay/managers/AudioManager.ts
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AudioManager = void 0;
const BaseEvents_1 = require("../../event/BaseEvents");
const GameBasicSettings_1 = require("../settings/GameBasicSettings");
const ResUtils_1 = require("../../utils/ResUtils");
const simba_utils_1 = require("simba-utils");
var AudioManager;
(function (AudioManager) {
let _musicPathPrefix = "";
let _voicePathPrefix = "";
let _effectPathPrefix = "";
function init(musicPathPrefix = "", effectPathPrefix = "", voicePathPrefix = "") {
_musicPathPrefix = musicPathPrefix;
_voicePathPrefix = voicePathPrefix;
_effectPathPrefix = effectPathPrefix;
cc.audioEngine.setMusicVolume(GameBasicSettings_1.GameBasicSettings.musicVolume);
cc.audioEngine.setEffectsVolume(GameBasicSettings_1.GameBasicSettings.soundVolume);
BaseEvents_1.SettingEvents.MusicVolumeChange.on((volume) => {
cc.audioEngine.setMusicVolume(volume);
if (volume === 0) {
cc.audioEngine.pauseMusic();
}
else {
cc.audioEngine.resumeMusic();
}
});
BaseEvents_1.SettingEvents.SoundVolumeChange.on((volume) => {
cc.audioEngine.setEffectsVolume(volume);
});
}
AudioManager.init = init;
async function playMusic(path) {
if (path[0] !== "/")
path = _musicPathPrefix + path;
if (!GameBasicSettings_1.GameBasicSettings.musicVolume)
return;
try {
let clip = await ResUtils_1.ResUtils.loadRes(path, cc.AudioClip);
cc.audioEngine.playMusic(clip, true);
}
catch (e) {
console.error(e);
}
}
AudioManager.playMusic = playMusic;
function pauseMusic() {
cc.audioEngine.pauseMusic();
}
AudioManager.pauseMusic = pauseMusic;
function resumeMusic() {
cc.audioEngine.resumeMusic();
}
AudioManager.resumeMusic = resumeMusic;
function stopMusic() {
cc.audioEngine.stopMusic();
}
AudioManager.stopMusic = stopMusic;
async function playEffect(path, loopCount = 1) {
if (path[0] !== "/")
path = _effectPathPrefix + path;
if (!GameBasicSettings_1.GameBasicSettings.soundVolume)
return NaN;
try {
let clip = await ResUtils_1.ResUtils.loadRes(path, cc.AudioClip);
if (loopCount <= 0) {
return cc.audioEngine.playEffect(clip, true);
}
else {
for (let i = 0; i < loopCount; i++) {
let id = cc.audioEngine.playEffect(clip, false);
let time = cc.audioEngine.getDuration(id);
await simba_utils_1.delay(time);
}
return NaN;
}
}
catch (e) {
console.error(e);
}
}
AudioManager.playEffect = playEffect;
async function playVoice(path) {
if (path[0] !== "/")
path = _voicePathPrefix + path;
stopAllEffect();
try {
let clip = await ResUtils_1.ResUtils.loadRes(path, cc.AudioClip);
let id = cc.audioEngine.playEffect(clip, false);
let time = cc.audioEngine.getDuration(id);
await simba_utils_1.delay(time);
}
catch (e) {
console.error(e);
}
}
AudioManager.playVoice = playVoice;
function stopEffect(id) {
if (!isNaN(id)) {
cc.audioEngine.stopEffect(id);
}
}
AudioManager.stopEffect = stopEffect;
function stopAllEffect() {
cc.audioEngine.stopAllEffects();
}
AudioManager.stopAllEffect = stopAllEffect;
})(AudioManager = exports.AudioManager || (exports.AudioManager = {}));
cc._RF.pop();