示例#1
0
        /// <summary>
        /// 播放/暂停音效
        /// </summary>
        /// <param name="play"></param>
        public void PauseSFX(bool pause)
        {
            if (m_Listener != null && m_Listener.enabled && UGUITools.GetActive(m_Listener.gameObject))
            {
                AudioSource source = m_Listener.GetComponent <AudioSource>();
                if (source == null)
                {
                    source = m_Listener.gameObject.AddComponent <AudioSource>();
                }

                if (!pause)
                {
                    source.Play();
                }
                else
                {
                    source.Pause();
                }

                BattleSFXAudioSource battleSFXAudioSource = GetSFXAudioSource();
                if (source != null)
                {
                    if (!pause)
                    {
                        battleSFXAudioSource.Play();
                    }
                    else
                    {
                        battleSFXAudioSource.Pause();
                    }
                }
            }
        }
示例#2
0
        private BattleSFXAudioSource GetSFXAudioSource()
        {
            BattleSFXAudioSource source = m_Listener.GetComponent <BattleSFXAudioSource>();

            if (source == null)
            {
                source = m_Listener.gameObject.AddComponent <BattleSFXAudioSource>();
                source.Init(audioMixerGroups);
            }
            return(source);
        }
示例#3
0
 public void StopBattleSFX(uint id)
 {
     if (id == 0)
     {
         return;
     }
     InitListener();
     if (m_Listener != null && m_Listener.enabled && UGUITools.GetActive(m_Listener.gameObject))
     {
         BattleSFXAudioSource source = GetSFXAudioSource();
         if (source != null)
         {
             source.StopSound(id);
         }
     }
 }
示例#4
0
        /// <summary>
        /// 设置音效的音量
        /// </summary>
        /// <param name="volume"></param>
        public void SetSFXVolume(float volume)
        {
            if (m_Listener != null && m_Listener.enabled && UGUITools.GetActive(m_Listener.gameObject))
            {
                AudioSource source = m_Listener.GetComponent <AudioSource>();
                if (source == null)
                {
                    source = m_Listener.gameObject.AddComponent <AudioSource>();
                }
                source.volume = volume;

                BattleSFXAudioSource battleSFXAudioSource = GetSFXAudioSource();
                if (source != null)
                {
                    battleSFXAudioSource.Volume = volume;
                }
            }
        }
示例#5
0
        private void PlayBattleSFX(AudioClip clip, SoundType type, uint id)
        {
            float volume = GlobalSettings.GetInstance().SFXVolume;

            if (clip != null && !GlobalSettings.GetInstance().SFXMute&& volume > 0.01f)
            {
                InitListener();

                if (m_Listener != null && m_Listener.enabled && UGUITools.GetActive(m_Listener.gameObject))
                {
                    BattleSFXAudioSource source = GetSFXAudioSource();
                    if (source != null)
                    {
                        bool playSuccess = source.PlaySound(clip, type, id);
                        if (!playSuccess)
                        {
                            PlayAudio(clip);
                            DestroySFX(id, clip.length);
                        }
                    }
                }
            }
        }