public override SoundInstance TestInEditor(ISoundPool soundPool) { AmbienceSoundInstance sound = Fetch(soundPool); if (sound != null) { if (_audioListener == null) { _audioListener = FindObjectOfType <AudioListener>(); } if (_audioListener != null) { sound.Play3D(_audioListener.transform.position); } else { sound.Play2D(); } OnPlayed(sound); return(sound); } return(null); }
/// <summary> /// Fetches and then plays a sound that will follow a transform around. /// </summary> /// <param name="followTransform">The transform to follow</param> public static AmbienceSoundInstance Play(this AmbienceSoundBank soundBank, Transform followTransform) { if (soundBank != null) { AmbienceSoundInstance sound = soundBank.Fetch(RuntimeSoundPool.Instance); sound.Play3D(followTransform); soundBank.OnPlayed(sound); return(sound); } return(null); }
/// <summary> /// Fetches and then plays a sound at a specific position. /// </summary> /// <param name="position">The world-space position of the sound emission</param> public static AmbienceSoundInstance Play(this AmbienceSoundBank soundBank, Vector3 position) { if (soundBank != null) { AmbienceSoundInstance sound = soundBank.Fetch(RuntimeSoundPool.Instance); sound.Play3D(position); soundBank.OnPlayed(sound); return(sound); } return(null); }
/// <summary> /// Fetches and then plays a non-spatial sound, ie. one that does not emit from a specific location and rolloff. /// </summary> /// <param name="soundBank">The sound bank used to set-up the sound instance</param> public static AmbienceSoundInstance Play(this AmbienceSoundBank soundBank) { if (soundBank != null) { AmbienceSoundInstance sound = soundBank.Fetch(RuntimeSoundPool.Instance); sound.Play2D(); soundBank.OnPlayed(sound); return(sound); } return(null); }
public AmbienceSoundInstance Fetch(ISoundPool soundPool) { if (!IsPlayable()) { return(null); } AmbienceSoundInstance sound = soundPool.FetchFromPool <AmbienceSoundInstance>(); sound.name = name; for (int i = 0; i < _effects.Length; i++) { if (!_effects[i].Sound.IsEmpty) { sound.AddEffect(_effects[i]); } } for (int i = 0; i < _loops.Length; i++) { if (!_loops[i].Sound.IsEmpty) { sound.AddLoop(_loops[i]); } } if (_outputMixer != null) { sound.SetMixerGroup(_outputMixer); } AddFilters(sound); return(sound); }