/// <summary> /// Plays an audio clip from an existing pool. /// If no pool exists, one is created with default parameters. /// Audio sources in the pool are played in sequence and if the current audio to play is already playing, the audio is reset. /// Advanced customizations from PlayFXCustom aren't modified. /// </summary> /// <param name="clip"> The audio </param> public void PlayFX(AudioClip clip) { IndexedAudioSourceList audioList; if (!fxSourceDictionary.TryGetValue(clip, out audioList)) { audioList = new IndexedAudioSourceList(gameObject, clip, DEFAULT_FX_POOLSIZE); fxSourceDictionary.Add(clip, audioList); } AudioSource audioSource = audioList.Next(); audioSource.Play(); }
/// <summary> /// Creates a pool of audio clips for multiple simultaneous playbacks /// </summary> /// <param name="clip"> The audio clip to play </param> /// <param name="fxQnt"> The maximum ammount of AudioSources played from this clip at any given time </param> public void Load(AudioClip clip, int fxQnt = 0) { if (fxQnt <= 0) { fxQnt = defaultFxQnt; } IndexedAudioSourceList audioList; if (!fxSourceDictionary.TryGetValue(clip, out audioList)) { audioList = new IndexedAudioSourceList(this.gameObject, clip, fxQnt); fxSourceDictionary.Add(clip, audioList); } }
/// <summary> /// Creates a pool of audio clips for multiple simultaneous playbacks /// </summary> /// <param name="clip"> The audio clip to play </param> /// <param name="poolSize"> The maximum ammount of AudioSources played from this clip at any given time </param> public void LoadFX(AudioClip clip, int poolSize = DEFAULT_FX_POOLSIZE) { if (poolSize <= 0) { poolSize = DEFAULT_FX_POOLSIZE; } IndexedAudioSourceList audioList; if (!fxSourceDictionary.TryGetValue(clip, out audioList)) { audioList = new IndexedAudioSourceList(this.gameObject, clip, poolSize); fxSourceDictionary.Add(clip, audioList); } }
/// <summary> /// Plays an audio clip from an existing pool. /// If no pool exists, one is created. /// Audio sources in the pool are played in sequence and if the current audio to play is already playing, the audio is reset. /// </summary> /// <param name="clip"> The audio </param> /// <param name="fxQnt"> The size of the pool if no pool exists</param> public void Play(AudioClip clip, int fxQnt = 0) { if (fxQnt <= 0) { fxQnt = defaultFxQnt; } IndexedAudioSourceList audioList; if (!fxSourceDictionary.TryGetValue(clip, out audioList)) { audioList = new IndexedAudioSourceList(gameObject, clip, fxQnt); fxSourceDictionary.Add(clip, audioList); } AudioSource source = audioList.Next(); source.Play(); }
/// <summary> /// Plays an audio clip from an existing pool with advanced audio customizations. /// If no pool exists, one is created with deafult parameters. /// Audio sources in pool are played in sequence and if the current audio to play is already playing, the audio is reset. /// </summary> /// <param name="clip"></param> /// <param name="volume"></param> /// <param name="pitch"></param> /// <param name="pan"></param> /// <param name="priority"></param> public void PlayFXCustom(AudioClip clip, float volume = 1, float pitch = 1, float pan = 0, int priority = 128) { IndexedAudioSourceList audioList; if (!fxSourceDictionary.TryGetValue(clip, out audioList)) { audioList = new IndexedAudioSourceList(gameObject, clip, DEFAULT_FX_POOLSIZE); fxSourceDictionary.Add(clip, audioList); } AudioSource audioSource = audioList.Next(); audioSource.volume = volume; audioSource.pitch = pitch; audioSource.panStereo = pan; audioSource.priority = priority; audioSource.Play(); }
/// <summary> /// Plays an audio clip from an existing pool, only one sound can be playing at the same time. /// If no pool exists, one is created. /// Audio sources in the pool are played in sequence and if the current audio to play is already playing, the audio is reset. /// </summary> /// <param name="clip"> The audio </param> /// <param name="fxQnt"> The size of the pool if no pool exists</param> public void SoloPlay(AudioClip clip, int fxQnt = 1) { if (fxQnt <= 0) { fxQnt = defaultFxQnt; } IndexedAudioSourceList audioList; if (!fxSourceDictionary.TryGetValue(clip, out audioList)) { audioList = new IndexedAudioSourceList(gameObject, clip, fxQnt); fxSourceDictionary.Add(clip, audioList); } if (!audioList.Current().isPlaying) { audioList.Current().Play(); } }