public AudioManager() { _AudioChannelPool = new AudioChannelPool(AUDIO_CHANNEL_COUNT); _Libraries = FindAudioLibraries(); AudioLog.Assert(_Libraries.Length > 0, "No audiolibraries found in root resources folder"); }
private AudioAsset ResolveAsset(AudioEvent audioEvent) { AudioAsset asset = null; for (int i = 0; i < _Libraries.Length; i++) { asset = _Libraries[i].Resolve(audioEvent.Identifier); if (asset) { break; } } #if DEBUG if (!asset) { AudioLog.Warning($"{audioEvent.Identifier} could not be found in any audio library."); } #endif return(asset); }
public static void ConfigureAudioSource(AudioSource audioSource, AudioAsset asset) { if (asset.ClipCount == 0) { AudioLog.Warning($"tried playing asset {asset.name} but it has no clips."); return; } float pitch = asset.GetPitch(); AudioClip clip = asset.GetClip(); if (clip == null) { AudioLog.Warning($"{asset.name} asset returned null as clip."); return; } audioSource.spatialBlend = asset.SpatialBlend; audioSource.dopplerLevel = asset.Doppler; audioSource.loop = asset.IsLooped; audioSource.panStereo = asset.Pan; audioSource.outputAudioMixerGroup = asset.AudioMixerGroup; audioSource.pitch = pitch; audioSource.clip = clip; audioSource.volume = asset.Volume; audioSource.maxDistance = asset.MaxDistance; audioSource.minDistance = asset.MinDistance; if (asset.RandomStartPosition) { audioSource.timeSamples = Random.Range(0, clip.samples - 1); } else { audioSource.timeSamples = pitch < 0 ? (clip.samples - 1) : 0; } }