Пример #1
0
 public void Play(AudioClip clip, SoundSettings settings, float volumeModifier = 1.0f)
 {
     Assert.IsTrue(sourcesBySettings.ContainsKey(settings), $"Sound settings {settings.name} are not initialized and clip: {clip.name} won't play!");
     if (sourcesBySettings.TryGetValue(settings, out AudioSource source))
     {
         source.PlayOneShot(clip, volumeModifier);
     }
 }
Пример #2
0
        public void PlayAtPoint(AudioClip clip, SoundSettings settings, Vector3 position, float volumeModifier = 1.0f)
        {
            Assert.IsTrue(sourcesBySettings.ContainsKey(settings), $"Sound settings {settings.name} are not initialized and clip: {clip.name} won't play!");
            if (sourcesBySettings.TryGetValue(settings, out AudioSource source))
            {
                AudioSource pointSource = Instantiate(source, soundContainer);
                pointSource.transform.position = position;
                pointSource.volume            *= volumeModifier;
                pointSource.clip = clip;
                pointSource.Play();

                Destroy(pointSource.gameObject, clip.length * (Time.timeScale >= 0.01f ? Time.timeScale : 0.01f));
            }
        }
Пример #3
0
 private AudioSource ApplySettings(AudioSource source, SoundSettings settings)
 {
     source.transform.parent = soundContainer;
     return(settings.Apply(source));
 }