/// <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(); } } } }
private BattleSFXAudioSource GetSFXAudioSource() { BattleSFXAudioSource source = m_Listener.GetComponent <BattleSFXAudioSource>(); if (source == null) { source = m_Listener.gameObject.AddComponent <BattleSFXAudioSource>(); source.Init(audioMixerGroups); } return(source); }
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); } } }
/// <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; } } }
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); } } } } }