Exemplo n.º 1
0
    /// <summary>
    /// Plays the clip at tile's location, on the channel group chanGroup. Pitch ranges from -freqRange to +freqRange in semitones.
    /// Volume ranges from -volRange to No change in decibels.
    /// </summary>
    /// <param name="clip">Sound to Play.</param>
    /// <param name="tile">Tile's location to play at. If null, plays at camera's position.</param>
    /// <param name="chanGroup">Chan group to play the sound on.</param>
    /// <param name="freqRange">Frequency range in semitones.</param>
    /// <param name="volRange">Volume range in decibels.</param>
    public void PlaySoundAt(SoundClip clip, Tile tile, string chanGroup = "master", float freqRange = 0f, float volRange = 0f, float cooldownTime = 0.1f)
    {
        if (clip == null || !clip.CanPlay())
        {
            return;
        }

        clip.SetCooldown(cooldownTime);
        ChannelGroup channelGroup;

        if (AudioManager.channelGroups.TryGetValue(chanGroup, out channelGroup) == false)
        {
            channelGroup = AudioManager.channelGroups["master"];
        }

        FMOD.System soundSystem = AudioManager.SoundSystem;
        Channel     channel;

        soundSystem.playSound(clip.Get(), channelGroup, true, out channel);
        if (tile != null)
        {
            VECTOR tilePos = GetVectorFrom(tile);
            channel.set3DAttributes(ref tilePos, ref zero, ref zero);
        }

        if (!freqRange.AreEqual(0f))
        {
            float pitch = Mathf.Pow(1.059f, Random.Range(-freqRange, freqRange));
            channel.setPitch(pitch);
        }

        if (!volRange.AreEqual(0f))
        {
            float curVol;
            channel.getVolume(out curVol);
            float volChange = Random.Range(-volRange, 0f);
            channel.setVolume(curVol * DecibelsToVolume(volChange));
        }

        channel.set3DLevel(SettingsKeyHolder.LocationalSound ? 0.75f : 0f);
        channel.setPaused(false);
    }