20cf03cb-52d3-4fbb-8290-d3f499227e46.js 2.55 KB
"use strict";
cc._RF.push(module, '20cf0PLUtNPu4KQ0/SZIn5G', 'SoundManager');
// scripts/component/SoundManager.ts

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SoundManager = void 0;
var Global_1 = require("../Global");
var SaveDataManager_1 = require("./SaveDataManager");
var SoundManager = /** @class */ (function () {
    function SoundManager() {
        this._cdMap = new Map();
    }
    Object.defineProperty(SoundManager, "ins", {
        get: function () {
            if (this._ins == null) {
                this._ins = new SoundManager();
            }
            return this._ins;
        },
        enumerable: false,
        configurable: true
    });
    SoundManager.prototype.update = function (dt) {
        this._cdMap.forEach(function (value, key, map) {
            if (value > 0) {
                value -= dt;
            }
            if (value < 0) {
                value = 0;
            }
            map.set(key, value);
        }, this);
    };
    SoundManager.prototype.playEffect = function (clipName) {
        if (!SaveDataManager_1.SaveDataManager.ins.runtimeData.SEMute) {
            if (clipName == Global_1.SoundName.HIT || clipName == Global_1.SoundName.BREAK) {
                //检查cd 
                if (this._cdMap.has(clipName) && this._cdMap.get(clipName) > 0) {
                    return;
                }
                else {
                    var cd = (clipName == Global_1.SoundName.HIT ? 0.1 : 0.6);
                    this._cdMap.set(clipName, cd);
                }
            }
            var clip = cc.resources.get('soundEffect/' + clipName, cc.AudioClip);
            if (clip) {
                cc.audioEngine.playEffect(clip, false);
            }
            else {
                cc.warn('can not find audio clip:', clipName);
            }
        }
    };
    SoundManager.prototype.playMusic = function () {
        if (!SaveDataManager_1.SaveDataManager.ins.runtimeData.musicMute) {
            var clip = cc.resources.get('soundEffect/' + Global_1.SoundName.BGM, cc.AudioClip);
            if (clip && !cc.audioEngine.isMusicPlaying()) {
                cc.audioEngine.playMusic(clip, true);
            }
            // else {
            //     cc.warn('can not find audio clip: BGM');
            // }
        }
    };
    SoundManager.prototype.stopMusic = function () {
        if (cc.audioEngine.isMusicPlaying()) {
            cc.audioEngine.stopMusic();
        }
    };
    SoundManager._ins = null;
    return SoundManager;
}());
exports.SoundManager = SoundManager;

cc._RF.pop();