/// <summary> private method for start play sound. </summary> private void PlaySound(AudioClip clip, float volume, ClipPriority priority = ClipPriority.Low) { if (MuteSound) { return; } AudioSourcePreset sourcePreset = SoundsSource.Find(s => !s.Source.isPlaying); if (sourcePreset == null) { sourcePreset = SoundsSource.Find(s => s.Priority < priority); } if (sourcePreset == null) { sourcePreset = SoundsSource.FindLast(s => s.Priority == priority); } if (sourcePreset == null) { return; } sourcePreset.Source.Stop(); sourcePreset.Source.clip = clip; sourcePreset.Source.volume = volume * SoundVolume; sourcePreset.Source.Play(); sourcePreset.Priority = priority; }
/// <summary> private method for stop play sound. </summary> private void StopSound(AudioClip clip) { if (MuteSound) { return; } AudioSourcePreset sourcePreset = SoundsSource.Find(s => s.Source.isPlaying && s.Source.clip == clip); if (sourcePreset != null) { sourcePreset.Source.Stop(); } }