示例#1
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);
                });
            }
        }
示例#2
0
        /// <summary>
        /// 播放音乐
        /// </summary>
        void PlayMusic(AudioMusicMsg musicMsg)
        {
            if (!MusicOn && musicMsg.allowMusicOff)
            {
                musicMsg.onMusicBeganCallback.InvokeGracefully();

                musicMsg.onMusicEndedCallback.InvokeGracefully();
                return;
            }

            Log.I(">>>>>> Start Play Music");

            // TODO: 需要按照这个顺序去 之后查一下原因
            //需要先注册事件,然后再play
            mMainUnit.SetOnStartListener(delegate(AudioUnit musicUnit)
            {
                musicMsg.onMusicBeganCallback.InvokeGracefully();

                //调用完就置为null,否则应用层每注册一个而没有注销,都会调用
                mMainUnit.SetOnStartListener(null);
            });

            mMainUnit.SetAudio(gameObject, musicMsg.MusicName, musicMsg.Loop);

            mMainUnit.SetOnFinishListener(delegate(AudioUnit musicUnit)
            {
                musicMsg.onMusicEndedCallback.InvokeGracefully();

                //调用完就置为null,否则应用层每注册一个而没有注销,都会调用
                mMainUnit.SetOnFinishListener(null);
            });
        }
示例#3
0
        public AudioUnit PlaySound(bool loop = false, System.Action <AudioUnit> callBack = null, int customEventID = -1)
        {
            if (string.IsNullOrEmpty(name))
            {
                return(null);
            }

            AudioUnit unit = SafeObjectPool <AudioUnit> .Instance.Allocate();

            unit.SetAudio(gameObject, name, loop);
            unit.SetOnFinishListener(callBack);
            unit.customEventID = customEventID;
            return(unit);
        }
示例#4
0
        /// <summary>
        /// 播放语音
        /// </summary>
        void PlayVoice(AudioVoiceMsg msg)
        {
            mVoiceUnit.SetOnStartListener(delegate(AudioUnit musicUnit)
            {
                SetVolume(mMainUnit, VolumeLevel.Min);

                msg.onVoiceBeganCallback.InvokeGracefully();

                mVoiceUnit.SetOnStartListener(null);
            });

            mVoiceUnit.SetAudio(gameObject, msg.voiceName, msg.loop);

            mVoiceUnit.SetOnFinishListener(delegate(AudioUnit musicUnit)
            {
                SetVolume(mMainUnit, VolumeLevel.Max);

                msg.onVoiceEndedCallback.InvokeGracefully();

                mVoiceUnit.SetOnFinishListener(null);
            });
        }
示例#5
0
        /// <summary>
        /// 播放音效
        /// </summary>
        void PlaySound(AudioMsgPlaySound msg)
        {
            AudioUnit unit = ObjectPool <AudioUnit> .Instance.Allocate();

            unit.SetOnStartListener(delegate(AudioUnit soundUnit)
            {
                if (null != msg.onSoundBeganCallback)
                {
                    msg.onSoundBeganCallback();
                }
                unit.SetOnStartListener(null);
            });

            unit.SetAudio(gameObject, msg.soundName, false);

            unit.SetOnFinishListener(delegate(AudioUnit soundUnit)
            {
                if (null != msg.onSoundEndedCallback)
                {
                    msg.onSoundEndedCallback();
                }
                unit.SetOnFinishListener(null);
            });
        }