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); }
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); }
public void Play(Transform transform) { AudioParams.Pitch pitch = null; if (randomPitch) { pitch = new AudioParams.Pitch(pitchVariation); } AudioParams.Repetition repetition = null; if (limitRepetition) { repetition = new AudioParams.Repetition(minRepeatTime); } AudioParams.Randomization randomization = null; if (randomize) { randomization = new AudioParams.Randomization(); } if (is2D) { AudioController.Instance.PlaySound2D(audioId, mixerGroup, volume, skipToNormalizedTime, pitch, repetition, randomization); } else { var source = AudioController.Instance.PlaySound3D(audioId, transform.position, mixerGroup, volume, skipToNormalizedTime, pitch, repetition, randomization); if (modified3DSoundParams) { source.Stop(); source.minDistance = minDistance; source.maxDistance = maxDistance; source.rolloffMode = AudioRolloffMode.Linear; source.spatialBlend = 1f; source.Play(); } } }