import { ConstValue } from "../Data/ConstValue" ; import { GameDataManager } from "./GameDataManager" ; export class AudioManager { private static instance : AudioManager = null ; private bgm : string = "" ; public static getInstance ( ) { if ( this . instance == null ) { this . instance = new AudioManager ( ) ; } return this . instance ; } public playSound ( soundName , loop ? , volume ? ) { if ( GameDataManager . getInstance ( ) . getGameData ( ) . worldInfo . settingInfo . closeAudio ) { return ; } let path = ConstValue . AUDIO_DIR + soundName ; cc . loader . loadRes ( path , cc . AudioClip , function ( err , clip ) { if ( err ) { cc . error ( err ) ; return ; } var audioID = cc . audioEngine . play ( clip , loop ? loop : false , volume ? volume : 1 ) ; } ) ; } public stopAll ( ) { cc . audioEngine . stopAll ( ) ; } public pauseAll ( ) { cc . audioEngine . pauseAll ( ) ; } public resumeAll ( ) { cc . audioEngine . resumeAll ( ) ; } public playBGM ( soundName ) { if ( this . bgm == soundName ) { return ; } this . bgm = soundName ; if ( GameDataManager . getInstance ( ) . getGameData ( ) . worldInfo . settingInfo . closeAudio ) { return ; } cc . audioEngine . stopMusic ( ) ; let path = ConstValue . AUDIO_DIR + soundName ; cc . loader . loadRes ( path , cc . AudioClip , function ( err , clip ) { if ( err ) { cc . error ( err ) ; return ; } cc . audioEngine . playMusic ( clip , true ) ; } ) ; } public resumeBGM ( ) { cc . audioEngine . stopMusic ( ) ; let path = ConstValue . AUDIO_DIR + this . bgm ; cc . loader . loadRes ( path , cc . AudioClip , function ( err , clip ) { if ( err ) { cc . error ( err ) ; return ; } cc . audioEngine . playMusic ( clip , true ) ; } ) ; } }