Exemple #1
0
    public bool PlayRMS(AudioChannel channel, Vector3 pos, float rms, float pitch)
    {
        float num  = rms;
        float num2 = pitch;

        rms *= volumeAdjust;
        rms  = ((rndVolumeMin != rndVolumeMax) ? (rms * Random.Range(rndVolumeMin, rndVolumeMax)) : (rms * rndVolumeMin));
        if (!CanPlay(rms))
        {
            return(false);
        }
        pitch = ((rndPitchMin != rndPitchMax) ? (pitch * Random.Range(rndPitchMin, rndPitchMax)) : (pitch * rndPitchMin));
        int         num3        = Random.Range(0, clips.Length);
        AudioClip   audioClip   = clips[num3];
        float       volumeScale = rms / clipsRms[num3];
        AudioSource audioSource = AudioSourcePool.Allocate(poolId, null, pos);

        audioSource.pitch = pitch;
        audioSource.outputAudioMixerGroup = AudioRouting.GetChannel(channel);
        audioSource.volume = 1f;
        audioSource.PlayOneShot(audioClip, volumeScale);
        float time = Time.time;

        if (blockTime > 0f)
        {
            blockUntil = Mathf.Max(blockUntil, time + blockTime);
        }
        if (maxVoices > 0)
        {
            polyphonyBlockUntil.Add(time + audioClip.length);
            playingLoudness.Add(rms);
        }
        return(true);
    }
Exemple #2
0
        private AudioSource AcquireAudioSource(Vector3 pos)
        {
            AudioSource audioSource = SoundSourcePool.instance.GetAudioSource();

            if (pos == Vector3.zero)
            {
                audioSource.transform.SetParent(base.transform, worldPositionStays: false);
                audioSource.transform.localPosition = Vector3.zero;
            }
            else
            {
                audioSource.transform.SetParent(null, worldPositionStays: false);
                audioSource.transform.localPosition = pos;
            }
            audioSource.outputAudioMixerGroup = AudioRouting.GetChannel(channel);
            ApplyAttenuation(audioSource);
            if (lowPass < 22000f)
            {
                SetLowPass(audioSource, lowPass);
            }
            return(audioSource);
        }
 private void Awake()
 {
     instance = this;
 }