Ejemplo n.º 1
0
        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); }).AddTo(this);

            AudioKit.Settings.VoiceVolume.Bind(volume => { VoicePlayer.SetVolume(volume); }).AddTo(this);

            AudioKit.Settings.IsMusicOn.Bind(musicOn =>
            {
                if (musicOn)
                {
                    if (CurrentMusicName.IsNotNullAndEmpty())
                    {
                        AudioKit.PlayMusic(CurrentMusicName);
                    }
                }
                else
                {
                    MusicPlayer.Stop();
                }
            }).AddTo(this);

            AudioKit.Settings.IsVoiceOn.Bind(voiceOn =>
            {
                if (voiceOn)
                {
                    if (CurrentVoiceName.IsNotNullAndEmpty())
                    {
                        AudioKit.PlayVoice(CurrentVoiceName);
                    }
                }
                else
                {
                    VoicePlayer.Stop();
                }
            }).AddTo(this);

            AudioKit.Settings.IsSoundOn.Bind(soundOn =>
            {
                if (soundOn)
                {
                }
                else
                {
                    ForEachAllSound(player => player.Stop());
                }
            }).AddTo(this);


            AudioKit.Settings.SoundVolume.Bind(soundVolume =>
            {
                ForEachAllSound(player => player.SetVolume(soundVolume));
            }).AddTo(this);
        }
Ejemplo n.º 2
0
 public void RemoveSoundPlayerFromPool(AudioPlayer audioPlayer)
 {
     mSoundPlayerInPlaying[audioPlayer.Name].Remove(audioPlayer);
 }