Exemplo n.º 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();
                    }
                }
            }
        }
Exemplo n.º 2
0
 private void InitAudioSource()
 {
     if (go == null || !UGUITools.GetActive(go))
     {
         return;
     }
     if (audioSource == null || !UGUITools.GetActive(audioSource))
     {
         audioSource = go.AddComponent <AudioSource>();
         audioSource.outputAudioMixerGroup = mixerGroup;
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// 停止当前播放的AudioClip
        /// </summary>
        public void StopAuidoClip()
        {
            InitListener();

            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.clip = null;
                source.Stop();
            }
        }
Exemplo n.º 4
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);
         }
     }
 }
Exemplo n.º 5
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;
                }
            }
        }
Exemplo n.º 6
0
 private void InitListener()
 {
     if (m_Listener == null || !UGUITools.GetActive(m_Listener))
     {
         Camera cam = Camera.main;
         if (cam == null)
         {
             cam = GameObject.FindObjectOfType(typeof(Camera)) as Camera;
         }
         if (cam != null)
         {
             m_Listener = cam.gameObject.GetComponent <AudioListener>();
             if (m_Listener == null)
             {
                 m_Listener = cam.gameObject.AddComponent <AudioListener>();
             }
         }
     }
 }
Exemplo n.º 7
0
        /// <summary>
        /// 播放音效
        /// </summary>
        /// <param name="clip"></param>
        /// <param name="is_loop"></param>
        /// <returns></returns>
        public void PlayAudio(AudioClip clip, bool is_loop = false, UnityAction cbFunc = null)
        {
            float volume = GlobalSettings.GetInstance().SFXVolume;

            if (clip != null && volume > 0.01f)
            {
                InitListener();

                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 (is_loop)
                    {
                        source.loop = true;
                        source.clip = clip;
                        source.Play();

                        return;
                    }

                    source.pitch = 1.0f;
                    if (!GlobalSettings.GetInstance().SFXMute)
                    {
                        source.PlayOneShot(clip, volume);

                        if (null != cbFunc)
                        {
                            xc.MainGame.GetGlobalMono().StartCoroutine(DelayedCallback(clip.length, cbFunc));
                        }
                    }
                }
            }
        }
Exemplo n.º 8
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);
                        }
                    }
                }
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// 停止正在播放的循环音效
        /// </summary>
        /// <param name="clip_name"></param>
        /// <returns></returns>
        public void StopLoopAudio(string clip_name)
        {
            if (m_Listener != null && m_Listener.enabled && UGUITools.GetActive(m_Listener.gameObject))
            {
                AudioSource source = m_Listener.GetComponent <AudioSource>();
                if (null == source)
                {
                    return;
                }

                AudioClip curClip = source.clip;
                if (null == curClip)
                {
                    return;
                }

                if (0 == curClip.name.CompareTo(clip_name))
                {
                    source.Stop();
                    source.loop = false;
                    source.clip = null;
                }
            }
        }