public void OnSingletonInit() { Log.I("AudioManager OnSingletonInit"); RegisterEvents( AudioEvent.SoundSwitch, AudioEvent.MusicSwitch, AudioEvent.VoiceSwitch, AudioEvent.SetSoundVolume, AudioEvent.SetMusicVolume, AudioEvent.SetVoiceVolume, AudioEvent.PlayMusic, AudioEvent.PlaySound, AudioEvent.PlayVoice, AudioEvent.PlayNode, AudioEvent.AddRetainAudio, AudioEvent.RemoveRetainAudioAudio ); SafeObjectPool <AudioPlayer> .Instance.Init(10, 1); MusicPlayer = AudioPlayer.Allocate(); MusicPlayer.usedCache = false; VoicePlayer = AudioPlayer.Allocate(); VoicePlayer.usedCache = false; CheckAudioListener(); gameObject.transform.position = Vector3.zero; AudioKit.Settings.MusicVolume.Bind(volume => { MusicPlayer.SetVolume(volume); }) .DisposeWhenGameObjectDestroyed(this); AudioKit.Settings.VoiceVolume.Bind(volume => { VoicePlayer.SetVolume(volume); }) .DisposeWhenGameObjectDestroyed(this); AudioKit.Settings.IsMusicOn.Bind(musicOn => { if (musicOn) { if (CurrentMusicName.IsNotNullAndEmpty()) { AudioKit.PlayMusic(CurrentMusicName); } } else { MusicPlayer.Stop(); } }).DisposeWhenGameObjectDestroyed(this); AudioKit.Settings.IsVoiceOn.Bind(voiceOn => { if (voiceOn) { if (CurrentVoiceName.IsNotNullAndEmpty()) { AudioKit.PlayVoice(CurrentVoiceName); } } else { VoicePlayer.Stop(); } }).DisposeWhenGameObjectDestroyed(this); AudioKit.Settings.IsSoundOn.Bind(soundOn => { if (soundOn) { } else { ForEachAllSound(player => player.Stop()); } }).DisposeWhenGameObjectDestroyed(this); AudioKit.Settings.SoundVolume.Bind(soundVolume => { ForEachAllSound(player => player.SetVolume(soundVolume)); }).DisposeWhenGameObjectDestroyed(this); }
public static void PlayMusic(string musicName, bool loop = true, System.Action onBeganCallback = null, System.Action onEndCallback = null, bool allowMusicOff = true, float volume = -1f) { AudioKit.PlayMusic(musicName, loop, onBeganCallback, onEndCallback, allowMusicOff, volume); }
protected override void ProcessMsg(int key, QMsg msg) { switch (msg.EventID) { case (int)AudioEvent.SoundSwitch: var soundSwitchMsg = msg as AudioMsgWithBool; AudioKit.Settings.IsSoundOn.Value = soundSwitchMsg.on; break; case (int)AudioEvent.MusicSwitch: var musicSwitchMsg = msg as AudioMsgWithBool; AudioKit.Settings.IsMusicOn.Value = musicSwitchMsg.on; if (!AudioKit.Settings.IsMusicOn.Value) { AudioKit.StopMusic(); } break; case (int)AudioEvent.PlayMusic: Log.I("play music msg: {0}, is musicOn: {1}", AudioEvent.PlayMusic.ToString(), AudioKit.Settings.IsMusicOn.Value); var musicMsg = msg as AudioMusicMsg; AudioKit.PlayMusic(musicMsg.MusicName, musicMsg.Loop, musicMsg.onMusicBeganCallback, musicMsg.onMusicEndedCallback, musicMsg.allowMusicOff); break; case (int)AudioEvent.StopMusic: AudioKit.StopMusic(); break; case (int)AudioEvent.PlaySound: AudioSoundMsg audioSoundMsg = msg as AudioSoundMsg; PlaySound(audioSoundMsg); break; case (int)AudioEvent.PlayVoice: var voiceMsg = msg as AudioVoiceMsg; AudioKit.PlayVoice(voiceMsg.voiceName, voiceMsg.loop, voiceMsg.onVoiceBeganCallback, voiceMsg.onVoiceEndedCallback); break; case (int)AudioEvent.StopVoice: AudioKit.StopVoice(); break; case (int)AudioEvent.PlayNode: var msgPlayNode = (msg as AudioMsgWithNode).Node; StartCoroutine(msgPlayNode.Execute()); break; case (int)AudioEvent.AddRetainAudio: AddRetainAudioMsg addRetainAudioMsg = msg as AddRetainAudioMsg; AddRetainAudio(addRetainAudioMsg.AudioName); break; case (int)AudioEvent.RemoveRetainAudioAudio: RemoveRetainAudioMsg removeRetainAudioMsg = msg as RemoveRetainAudioMsg; RemoveRetainAudio(removeRetainAudioMsg.AudioName); break; case (int)AudioEvent.PauseMusic: AudioKit.PauseMusic(); break; case (int)AudioEvent.ResumeMusic: AudioKit.ResumeMusic(); break; } }
public static void PlayMusic(string musicName) { AudioKit.PlayMusic(musicName); }