Пример #1
0
    public AudioSource PlaySound(SoundList sound, float volume = 1.0f, float timeToLoop = 0.0f)
    {
        //return null;
        AudioSource emitterAvailable = null;

        foreach (AudioSource emitter in emitters)
        {
            if (!emitter.isPlaying)
            {
                emitterAvailable = emitter;
            }
        }

        if (emitterAvailable != null)
        {
            emitterAvailable.loop   = false;
            emitterAvailable.volume = volume;
            Debug.Log(sound.ToString());
            switch (sound)
            {
            case SoundList.PAS:
                int indexWalk = Random.Range(0, listPasSounds.Count);
                emitterAvailable.clip = listPasSounds[indexWalk];
                emitterAvailable.outputAudioMixerGroup = audioMixer.FindMatchingGroups("Marche")[0];
                break;

            case SoundList.BUISSON:
                int indexBuisson = Random.Range(0, listBuissonSounds.Count);
                emitterAvailable.clip = listBuissonSounds[indexBuisson];
                emitterAvailable.outputAudioMixerGroup = audioMixer.FindMatchingGroups("Buisson")[0];
                break;

            case SoundList.LOUP_CRI:
                emitterAvailable.clip = loupCriClip;
                emitterAvailable.outputAudioMixerGroup = audioMixer.FindMatchingGroups("Cri")[0];
                break;

            case SoundList.LOUP_GROGNEMENT:
                emitterAvailable.clip = loupGrognementClip;
                emitterAvailable.outputAudioMixerGroup = audioMixer.FindMatchingGroups("Grognement")[0];
                break;

            case SoundList.CLIC:
                emitterAvailable.clip = clicClip;
                emitterAvailable.outputAudioMixerGroup = audioMixer.FindMatchingGroups("Clic")[0];
                break;

            case SoundList.DIALOGUE:
                emitterAvailable.clip = dialogueClip;
                emitterAvailable.outputAudioMixerGroup = audioMixer.FindMatchingGroups("Dialogue")[0];
                break;

            case SoundList.FEUILLAGE:
                int indexFeuillage = Random.Range(0, listFeuillageSounds.Count);
                emitterAvailable.clip = listFeuillageSounds[indexFeuillage];
                emitterAvailable.outputAudioMixerGroup = audioMixer.FindMatchingGroups("Feuillage")[0];
                break;

            case SoundList.GRAB:
                emitterAvailable.clip = grabClip;
                emitterAvailable.outputAudioMixerGroup = audioMixer.FindMatchingGroups("Ramasser")[0];
                break;
            }

            if (timeToLoop > 0.0f)
            {
                emitterAvailable.loop = true;
                LoopedSound newLoopSound = new LoopedSound
                {
                    audioSource   = emitterAvailable,
                    timeUntilStop = Utility.StartTimer(timeToLoop)
                };
                loopedSoundList.Add(newLoopSound);
            }

            emitterAvailable.Play();
            return(emitterAvailable);
        }
        else
        {
            return(null);
        }
    }
Пример #2
0
    public AudioSource PlaySound(SoundList sound, float timeToLoop = 0.0f)
    {
        AudioSource emitterAvailable = null;

        foreach (AudioSource emitter in emitters)
        {
            if (!emitter.isPlaying)
            {
                emitterAvailable = emitter;
            }
        }

        if (emitterAvailable != null)
        {
            emitterAvailable.loop = false;
            Debug.Log(sound.ToString());
            switch (sound)
            {
            case SoundList.WALK:
                int indexWalk = Random.Range(0, listWalkSounds.Count);
                emitterAvailable.clip = listWalkSounds[indexWalk];
                emitterAvailable.outputAudioMixerGroup = audioMixer.FindMatchingGroups("Effects")[0];
                break;

            case SoundList.CLOCK:
                emitterAvailable.clip = clockClip;
                emitterAvailable.outputAudioMixerGroup = audioMixer.FindMatchingGroups("Effects")[0];
                break;

            case SoundList.DEATH:
                emitterAvailable.clip = deathClip;
                emitterAvailable.outputAudioMixerGroup = audioMixer.FindMatchingGroups("Effects")[0];
                break;

            case SoundList.ITEM_PICKUP:
                emitterAvailable.clip = getItemClip;
                emitterAvailable.outputAudioMixerGroup = audioMixer.FindMatchingGroups("Effects")[0];
                break;

            case SoundList.GUN_FIRE:
                emitterAvailable.clip = gunFireClip;
                emitterAvailable.outputAudioMixerGroup = audioMixer.FindMatchingGroups("Effects")[0];

                break;

            case SoundList.DEMON_NOISE:
                int indexNoise = Random.Range(0, listDemonNoiseSounds.Count);
                emitterAvailable.clip = listDemonNoiseSounds[indexNoise];
                emitterAvailable.outputAudioMixerGroup = audioMixer.FindMatchingGroups("Effects")[0];
                break;

            case SoundList.DEMON_DEATH:
                emitterAvailable.clip = DemonDeath;
                emitterAvailable.outputAudioMixerGroup = audioMixer.FindMatchingGroups("Effects")[0];
                break;

            case SoundList.NEKO_NOISE:
                emitterAvailable.clip = nekoNoiseClip;
                emitterAvailable.outputAudioMixerGroup = audioMixer.FindMatchingGroups("Effects")[0];
                break;

            case SoundList.SPACE_NEKO_DEATH:
                emitterAvailable.clip = spaceNekoNoiseClip;
                emitterAvailable.outputAudioMixerGroup = audioMixer.FindMatchingGroups("Effects")[0];
                break;

            case SoundList.STAIRS:
                emitterAvailable.clip = stairsClip;
                emitterAvailable.outputAudioMixerGroup = audioMixer.FindMatchingGroups("Effects")[0];
                break;
            }

            if (timeToLoop > 0.0f)
            {
                emitterAvailable.loop = true;
                LoopedSound newLoopSound = new LoopedSound
                {
                    audioSource   = emitterAvailable,
                    timeUntilStop = Utility.StartTimer(timeToLoop)
                };
                loopedSoundList.Add(newLoopSound);
            }

            emitterAvailable.Play();
            return(emitterAvailable);
        }
        else
        {
            Debug.Log("no emitter available");
            return(null);
        }
    }