private void PlayOneShoot(SFXConfig sfx) { if (Time.time - sfx.lastPlayTimestamp >= sfx.restTime) { if (sfx.mode == SFXMode.Single) { AudioManager.Instance.PlayOneShoot2D(sfx.clip, GetVolume(sfx), sfx.delay, sfx.destroyOnLoad); } else if (sfx.mode == SFXMode.RandomBox) { if (sfx.dontRepeatRandomBox) { if (sfx.randomBoxIndex < 0) { sfx.randomBoxIndex = Random.Range(0, sfx.clips.Length); } else { sfx.randomBoxIndex = (sfx.randomBoxIndex + 1) >= sfx.clips.Length ? 0 : (sfx.randomBoxIndex + 1); } } else { sfx.randomBoxIndex = Random.Range(0, sfx.clips.Length); } AudioClip clip = sfx.clips[sfx.randomBoxIndex]; AudioManager.Instance.PlayOneShoot2D(clip, GetVolume(sfx), sfx.delay, sfx.destroyOnLoad); } sfx.lastPlayTimestamp = Time.time; } }
private void PlayStopableOneShoot(string name, SFXConfig sfx) { if (sfx.mode == SFXMode.Single) { AudioManager.Instance.PlayStopableOneShot(name, sfx.clip, GetVolume(sfx), sfx.delay, sfx.destroyOnLoad); } else if (sfx.mode == SFXMode.RandomBox) { AudioClip clip = sfx.clips[Random.Range(0, sfx.clips.Length)]; AudioManager.Instance.PlayStopableOneShot(name, clip, GetVolume(sfx), sfx.delay, sfx.destroyOnLoad); } }
private void PlayLoop(string name, SFXConfig sfx) { if (Time.time - sfx.lastPlayTimestamp >= sfx.restTime) { if (sfx.mode == SFXMode.Single) { AudioManager.Instance.PlayLoop2D(name, sfx.clip, GetVolume(sfx), sfx.delay, sfx.destroyOnLoad); } else if (sfx.mode == SFXMode.RandomBox) { AudioClip clip = sfx.clips[Random.Range(0, sfx.clips.Length)]; AudioManager.Instance.PlayLoop2D(name, clip, GetVolume(sfx), sfx.delay, sfx.destroyOnLoad); } sfx.lastPlayTimestamp = Time.time; } }
public ConstructedAudio(AudioSource csrc, SFXConfig sfx) { this.csrc = csrc; this.sfx = sfx; }
private float GetVolume(SFXConfig sfx) { return(sfx.volume * (sfx.type == SFXType.FX ? sfxVolume : ambientVolume)); }