示例#1
0
    public AudioSource PlaySound3D(string soundId, Vector3 position, MixerGroup mixerGroup = MixerGroup.None, float volume = 1f, float skipToTime = 0f, AudioParams.Pitch pitch           = null,
                                   AudioParams.Repetition repetition = null, AudioParams.Randomization randomization       = null, AudioParams.Distortion distortion = null, bool looping = false)
    {
        if (repetition != null)
        {
            if (RepetitionIsTooFrequent(soundId, repetition.minRepetitionFrequency, repetition.entryId))
            {
                return(null);
            }
        }

        string randomVariationId = soundId;

        if (randomization != null)
        {
            randomVariationId = GetRandomVariationOfSound(soundId, randomization.noRepeating);
        }

        var source = CreateAudioSourceForSound(randomVariationId, position, looping, mixerGroup);

        if (source != null)
        {
            source.volume = volume;
            source.time   = source.clip.length * skipToTime;

            if (pitch != null)
            {
                source.pitch = pitch.pitch;
            }

            if (distortion != null)
            {
                if (distortion.muffled)
                {
                    MuffleSource(source);
                }
            }
        }

        activeSFX.Add(source);
        return(source);
    }
示例#2
0
    public AudioSource PlaySound2D(string soundId, MixerGroup mixerGroup = MixerGroup.None, float volume                 = 1f, float skipToTime = 0f, AudioParams.Pitch pitch = null,
                                   AudioParams.Repetition repetition     = null, AudioParams.Randomization randomization = null, AudioParams.Distortion distortion = null, bool looping = false)
    {
        var source = PlaySound3D(soundId, Vector3.zero, mixerGroup, volume, skipToTime, pitch, repetition, randomization, distortion, looping);

        if (source != null)
        {
            source.spatialBlend = 0f;
        }

        return(source);
    }