예제 #1
0
    /// <summary>
    ///  Update the sound on the specified audio source
    /// </summary>
    public void UpdateSound(AudioParams.SoundPoolGroups soundPoolGroupTag, AudioParams.SoundPools soundPoolTag, GameObject caller, float volumeEffector)
    {
        int audioSourceKey = (soundPoolGroupTag.ToString() + soundPoolTag.ToString() + caller.GetInstanceID().ToString()).GetHashCode();

        if (createdAudioSourcesDictionnary.ContainsKey(audioSourceKey))
        {
            AudioSource modifiedAudioSource = createdAudioSourcesDictionnary[audioSourceKey].audioSource;
            modifiedAudioSource.volume *= volumeEffector;
        }
    }
예제 #2
0
    /// <summary>
    ///  Stop playing a sound on the specified audio source
    /// </summary>
    public void StopSound(AudioParams.SoundPoolGroups soundPoolGroupTag, AudioParams.SoundPools soundPoolTag, GameObject caller)
    {
        int audioSourceKey = (soundPoolGroupTag.ToString() + soundPoolTag.ToString() + caller.GetInstanceID().ToString()).GetHashCode();

        if (createdAudioSourcesDictionnary.ContainsKey(audioSourceKey))
        {
            Destroy(createdAudioSourcesDictionnary[audioSourceKey].audioSource);
            createdAudioSourcesDictionnary.Remove(audioSourceKey);
        }
    }
예제 #3
0
/// <summary>
///  Returns a sound pool with the defined tag
/// </summary>
    public SoundPool GetSoundPool(AudioParams.SoundPools soundPoolTag)
    {
        SoundPool foundSoundPool = soundPools.Find(currentSoundPool => currentSoundPool.Tag == soundPoolTag);

        if (foundSoundPool == null)
        {
            Debug.LogWarning("Sound Pool : " + soundPoolTag + " was not found !");
        }
        return(foundSoundPool);
    }
예제 #4
0
    /// <summary>
    ///  Play sound on the game object without interruption if already playing
    /// </summary>
    public void PlaySoundOverFlow(AudioParams.SoundPoolGroups soundPoolGroupTag, AudioParams.SoundPools soundPoolTag, GameObject caller)
    {
        int audioSourceKey = (soundPoolGroupTag.ToString() + soundPoolTag.ToString() + caller.GetInstanceID().ToString()).GetHashCode();

        if (!createdAudioSourcesDictionnary.ContainsKey(audioSourceKey))
        {
            //Debug.Log("FIRST CALL CREATING THE DICT !! key = " + audioSourceKey);
            SoundPoolGroup foundSoundPoolGroup = soundPoolGroups.FirstOrDefault(currentSoundPoolGroup => currentSoundPoolGroup.Tag == soundPoolGroupTag);
            if (foundSoundPoolGroup == null)
            {
                //Debug.LogWarning("Sound Pool Group : " + soundPoolGroupTag.ToString() + " was not found !");
                return;
            }
            else
            {
                SoundPool foundSoundPool = foundSoundPoolGroup.GetSoundPool(soundPoolTag);
                if (foundSoundPool != null)
                {
                    AudioSource newAudioSource = caller.AddComponent <AudioSource>();
                    newAudioSource = foundSoundPool.UpdateAudioSource(newAudioSource);
                    if (newAudioSource != null)
                    {
                        newAudioSource.Play();
                        createdAudioSourcesDictionnary.Add(audioSourceKey, new CreatedAudioSources(foundSoundPool, newAudioSource));
                    }
                }
            }
        }
        //here is the case where we already made this search but the audio source got destroyed between the privious call and this one
        else if (createdAudioSourcesDictionnary[audioSourceKey].audioSource == null)
        {
            //Debug.Log("RECREATING THE AUDIO SOURCE");
            AudioSource recreatedAudioSource = caller.AddComponent <AudioSource>();
            recreatedAudioSource = createdAudioSourcesDictionnary[audioSourceKey].soundPool
                                   .UpdateAudioSource(recreatedAudioSource);

            createdAudioSourcesDictionnary[audioSourceKey].audioSource = recreatedAudioSource;
            createdAudioSourcesDictionnary[audioSourceKey].audioSource.Play();
        }
        //here is the case where we already made tgis search and the audio source is still there
        else
        {
            //Debug.Log("ALREADY THERE");
            createdAudioSourcesDictionnary[audioSourceKey].audioSource =
                createdAudioSourcesDictionnary[audioSourceKey].soundPool
                .UpdateAudioSource(createdAudioSourcesDictionnary[audioSourceKey].audioSource);

            if (!createdAudioSourcesDictionnary[audioSourceKey].audioSource.isPlaying)
            {
                createdAudioSourcesDictionnary[audioSourceKey].audioSource.Play();
            }
        }
    }
예제 #5
0
    /// <summary>
    ///  Play sound on the game object with modified volume
    /// </summary>
    public void PlaySoundModified(AudioParams.SoundPoolGroups soundPoolGroupTag, AudioParams.SoundPools soundPoolTag, GameObject caller, float volumeEffector)
    {
        int audioSourceKey = (soundPoolGroupTag.ToString() + soundPoolTag.ToString() + caller.GetInstanceID().ToString()).GetHashCode();

        if (!createdAudioSourcesDictionnary.ContainsKey(audioSourceKey))
        {
            SoundPoolGroup foundSoundPoolGroup = soundPoolGroups.FirstOrDefault(currentSoundPoolGroup => currentSoundPoolGroup.Tag == soundPoolGroupTag);
            if (foundSoundPoolGroup == null)
            {
                return;
            }
            else
            {
                SoundPool foundSoundPool = foundSoundPoolGroup.GetSoundPool(soundPoolTag);
                if (foundSoundPool != null)
                {
                    AudioSource newAudioSource = caller.AddComponent <AudioSource>();
                    newAudioSource = foundSoundPool.UpdateAudioSource(newAudioSource);
                    if (newAudioSource != null)
                    {
                        createdAudioSourcesDictionnary.Add(audioSourceKey, new CreatedAudioSources(foundSoundPool, newAudioSource));
                        AudioSource modifiedAudioSource = newAudioSource;
                        modifiedAudioSource.volume *= volumeEffector;
                        modifiedAudioSource.Play();
                    }
                }
            }
        }
        //here is the case where we already made this search but the audio source got destroyed between the privious call and this one
        else if (createdAudioSourcesDictionnary[audioSourceKey].audioSource == null)
        {
            AudioSource recreatedAudioSource = caller.AddComponent <AudioSource>();
            recreatedAudioSource = createdAudioSourcesDictionnary[audioSourceKey].soundPool
                                   .UpdateAudioSource(recreatedAudioSource);

            createdAudioSourcesDictionnary[audioSourceKey].audioSource = recreatedAudioSource;
            AudioSource modifiedAudioSource = recreatedAudioSource;
            modifiedAudioSource.volume *= volumeEffector;
            modifiedAudioSource.Play();
        }
        //here is the case where we already made tgis search and the audio source is still there
        else
        {
            createdAudioSourcesDictionnary[audioSourceKey].audioSource =
                createdAudioSourcesDictionnary[audioSourceKey].soundPool
                .UpdateAudioSource(createdAudioSourcesDictionnary[audioSourceKey].audioSource);

            AudioSource modifiedAudioSource = createdAudioSourcesDictionnary[audioSourceKey].audioSource;
            modifiedAudioSource.volume *= volumeEffector;
            modifiedAudioSource.Play();
        }
    }
예제 #6
0
    /// <summary>
    ///  Play sound if the specified animation is on and returns true if the sound has been played
    /// </summary>
    public bool PlaySoundWithAnimation(AudioParams.SoundPoolGroups soundPoolGroupTag, AudioParams.SoundPools soundPoolTag, GameObject caller, string animationName, bool test)
    {
        Animator animator = caller.GetComponent <Animator>();

        if (!test && animator.GetCurrentAnimatorStateInfo(0).IsName(animationName))
        {
            PlaySound(soundPoolGroupTag, soundPoolTag, caller);
            test = true;
        }
        return(test);
    }
예제 #7
0
    private IEnumerator PlaySoundOnceCoroutine(AudioParams.SoundPoolGroups soundPoolGroupTag, AudioParams.SoundPools soundPoolTag, GameObject caller)
    {
        SoundPoolGroup foundSoundPoolGroup = soundPoolGroups.FirstOrDefault(currentSoundPoolGroup => currentSoundPoolGroup.Tag == soundPoolGroupTag);

        if (foundSoundPoolGroup == null)
        {
            yield return(null);
        }
        else
        {
            SoundPool foundSoundPool = foundSoundPoolGroup.GetSoundPool(soundPoolTag);
            if (foundSoundPool != null)
            {
                AudioSource newAudioSource = caller.AddComponent <AudioSource>();
                newAudioSource = foundSoundPool.UpdateAudioSource(newAudioSource);
                if (newAudioSource != null)
                {
                    newAudioSource.PlayOneShot(newAudioSource.clip);
                    yield return(new WaitWhile(() => newAudioSource != null && newAudioSource.isPlaying));

                    Destroy(newAudioSource);
                }
            }
        }
    }
예제 #8
0
 /// <summary>
 ///  Play sound on the game object once then destroy audio source
 /// </summary>
 public void PlaySoundOnce(AudioParams.SoundPoolGroups soundPoolGroupTag, AudioParams.SoundPools soundPoolTag, GameObject caller)
 {
     StartCoroutine(PlaySoundOnceCoroutine(soundPoolGroupTag, soundPoolTag, caller));
 }
예제 #9
0
 public virtual void StopSoundOnManager(AudioParams.SoundPoolGroups enemyName, AudioParams.SoundPools soundEffectName)
 {
     audioManager.StopSound(enemyName, soundEffectName, audioManager.gameObject);
 }
예제 #10
0
 public virtual void StopSoundOnManager(AudioParams.SoundPoolGroups enemyName, AudioParams.SoundPools soundEffectName, float volumeEffector)
 {
     audioManager.UpdateSound(enemyName, soundEffectName, audioManager.gameObject, volumeEffector);
 }
예제 #11
0
 public virtual void PlaySoundModifiedOnManager(AudioParams.SoundPoolGroups enemyName, AudioParams.SoundPools soundEffectName, float volumeEffector)
 {
     audioManager.PlaySoundModified(enemyName, soundEffectName, audioManager.gameObject, volumeEffector);
 }
예제 #12
0
 public virtual bool PlaySoundWithAnimationOnManager(AudioParams.SoundPoolGroups enemyName, AudioParams.SoundPools soundEffectName, string animationName, bool test)
 {
     return(audioManager.PlaySoundWithAnimation(enemyName, soundEffectName, audioManager.gameObject, animationName, test));
 }
예제 #13
0
 //************Play Once
 public virtual void PlaySoundOnce(AudioParams.SoundPoolGroups enemyName, AudioParams.SoundPools soundEffectName)
 {
     audioManager.PlaySoundOnce(enemyName, soundEffectName, gameObject);
 }