Exemplo n.º 1
0
        /// <summary>
        /// 播放音效
        /// </summary>
        void PlaySound(AudioSoundMsg soundMsg)
        {
            if (AudioKit.Settings.IsSoundOn.Value)
            {
                var unit = SafeObjectPool <AudioPlayer> .Instance.Allocate();

                unit.SetOnStartListener(soundUnit =>
                {
                    soundMsg.onSoundBeganCallback.InvokeGracefully();

                    unit.SetVolume(soundMsg.Volume);

                    soundUnit.SetOnStartListener(null);
                });

                unit.SetAudio(gameObject, soundMsg.SoundName, false);

                unit.SetOnFinishListener(soundUnit =>
                {
                    soundMsg.onSoundEndedCallback.InvokeGracefully();

                    soundUnit.SetOnFinishListener(null);
                });
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 播放音效
        /// </summary>
        void PlaySound(AudioSoundMsg soundMsg)
        {
            if (IsSoundOn)
            {
                AudioUnit unit = SafeObjectPool <AudioUnit> .Instance.Allocate();


                unit.SetOnStartListener(delegate(AudioUnit soundUnit)
                {
                    soundMsg.onSoundBeganCallback.InvokeGracefully();

                    unit.SetVolume(soundMsg.Volume);

                    unit.SetOnStartListener(null);
                });

                unit.SetAudio(gameObject, soundMsg.SoundName, false);

                unit.SetOnFinishListener(delegate(AudioUnit soundUnit)
                {
                    soundMsg.onSoundEndedCallback.InvokeGracefully();

                    unit.SetOnFinishListener(null);
                });
            }
        }
Exemplo n.º 3
0
        protected override void ProcessMsg(int key, QMsg msg)
        {
            switch (msg.msgId)
            {
            case (int)AudioEvent.SoundSwitch:
                AudioMsgWithBool soundSwitchMsg = msg as AudioMsgWithBool;
                SoundOn = soundSwitchMsg.on;
                break;

            case (int)AudioEvent.MusicSwitch:
                AudioMsgWithBool musicSwitchMsg = msg as AudioMsgWithBool;
                MusicOn = musicSwitchMsg.on;
                if (!MusicOn)
                {
                    StopMusic();
                }
                break;

            case (int)AudioEvent.PlayMusic:
                Debug.LogFormat("play music msg: {0}, is musicOn: ", AudioEvent.PlayMusic.ToString(), MusicOn);
                PlayMusic(msg as AudioMusicMsg);
                break;

            case (int)AudioEvent.StopMusic:
                StopMusic();
                break;

            case (int)AudioEvent.PlaySound:
                AudioSoundMsg audioSoundMsg = msg as AudioSoundMsg;
                PlaySound(audioSoundMsg);
                break;

            case (int)AudioEvent.PlayVoice:
                PlayVoice(msg as AudioVoiceMsg);
                break;

            case (int)AudioEvent.StopVoice:
                StopVoice();
                break;

            case (int)AudioEvent.PlayNode:
                IAction 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;
            }
        }
Exemplo n.º 4
0
        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;
            }
        }