System.register(["cc"], function (_export, _context) { "use strict"; var _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, Node, AudioSource, AudioClip, resources, director, AudioMgr, _crd; _export("AudioMgr", void 0); return { setters: [function (_cc) { _cclegacy = _cc.cclegacy; __checkObsolete__ = _cc.__checkObsolete__; __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__; Node = _cc.Node; AudioSource = _cc.AudioSource; AudioClip = _cc.AudioClip; resources = _cc.resources; director = _cc.director; }], execute: function () { _crd = true; _cclegacy._RF.push({}, "6a056NydBdBYYrAqahbCCfe", "AudioMgr", undefined); //AudioMgr.ts /** * @en * this is a sington class for audio play, can be easily called from anywhere in you project. * @zh * 这是一个用于播放音频的单件类,可以很方便地在项目的任何地方调用。 */ __checkObsolete__(['Node', 'AudioSource', 'AudioClip', 'resources', 'director']); _export("AudioMgr", AudioMgr = class AudioMgr { static get inst() { if (this._inst == null) { this._inst = new AudioMgr(); } return this._inst; } // private _soundaudioSource: AudioSource; constructor() { this._soundAudioSource = void 0; this._musicAudioSource = void 0; this.muteMusic = false; this.muteSound = false; //@en create a node as audioMgr //@zh 创建一个节点作为 audioMgr var audioMgr = new Node(); audioMgr.name = '__audioMgr__'; //@en add to the scene. //@zh 添加节点到场景 director.getScene().addChild(audioMgr); //@en make it as a persistent node, so it won't be destroied when scene change. //@zh 标记为常驻节点,这样场景切换的时候就不会被销毁了 director.addPersistRootNode(audioMgr); //@en add AudioSource componrnt to play audios. //@zh 添加 AudioSource 组件,用于播放音频。 this._soundAudioSource = audioMgr.addComponent(AudioSource); this._musicAudioSource = audioMgr.addComponent(AudioSource); } get soundAudioSource() { return this._soundAudioSource; } get musicAudioSource() { return this._musicAudioSource; } /** * @en * play short audio, such as strikes,explosions * @zh * 播放短音频,比如 打击音效,爆炸音效等 * @param sound clip or url for the audio * @param volume */ playOneShot(sound, volume) { if (volume === void 0) { volume = 1.0; } if (sound instanceof AudioClip) { this._soundAudioSource.playOneShot(sound, (this.muteSound ? 0 : 1) * volume); } else { resources.load(sound, (err, clip) => { if (err) { console.log(err); } else { this._soundAudioSource.playOneShot(clip, (this.muteSound ? 0 : 1) * volume); } }); } } /** * @en * play long audio, such as the bg music * @zh * 播放长音频,比如 背景音乐 * @param sound clip or url for the sound * @param volume */ play(sound, isLoop, volume) { if (isLoop === void 0) { isLoop = true; } if (volume === void 0) { volume = 1.0; } if (sound instanceof AudioClip) { this.musicAudioSource.stop(); this.musicAudioSource.clip = sound; this.musicAudioSource.loop = isLoop; this.musicAudioSource.play(); this.musicAudioSource.volume = (this.muteMusic ? 0 : 1) * volume; } else { resources.load(sound, (err, clip) => { if (err) { console.log(err); } else { this.musicAudioSource.clip = clip; this.musicAudioSource.play(); this.musicAudioSource.volume = (this.muteMusic ? 0 : 1) * volume; } }); } } activeMusic(active) { this.musicAudioSource.volume = active ? 1 : 0; this.muteMusic = !active; } activeSound(active) { this.soundAudioSource.volume = active ? 1 : 0; this.muteSound = !active; } /** * stop the audio play */ stop() { this._soundAudioSource.stop(); this._musicAudioSource.stop(); } /** * pause the audio play */ pause() { this._soundAudioSource.pause(); this._musicAudioSource.pause(); } /** * resume the audio play */ resume() { this._soundAudioSource.play(); this._musicAudioSource.play(); } }); AudioMgr._inst = void 0; _cclegacy._RF.pop(); _crd = false; } }; }); //# sourceMappingURL=17c15c9f91cab21852afabf06f526d531a818ca5.js.map