示例#1
0
        /// <summary>
        /// 播放音效
        /// </summary>
        void PlaySound(AudioSoundMsg soundMsg)
        {
            if (SoundOn.Value)
            {
                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);
                });
            }
        }
示例#2
0
        protected override void ProcessMsg(int key, QMsg msg)
        {
            switch (msg.EventID)
            {
            case (int)AudioEvent.SoundSwitch:
                AudioMsgWithBool soundSwitchMsg = msg as AudioMsgWithBool;
                SoundOn.Value = soundSwitchMsg.on;
                break;

            case (int)AudioEvent.MusicSwitch:
                AudioMsgWithBool musicSwitchMsg = msg as AudioMsgWithBool;
                IsMusicOn = musicSwitchMsg.on;
                if (!IsMusicOn)
                {
                    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;

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

            case (int)AudioEvent.ResumeMusic:
                ResumeMusic();
                break;
            }
        }