private IEnumerator LoadResourceFileAsync(string resourceFileName, float maxVolume) { yield return(new WaitForSeconds(Time.deltaTime)); // this lets the thread continue without blocking; For some reason CoRoutine alone isn't enough. AudioResourceOptimizer.PopulateSourcesWithResourceClip(resourceFileName); FinishSetupToPlay(maxVolume); yield break; }
/// <summary> /// This method is called automatically from MasterAudio.PlaySound and MasterAudio.PlaySound3D. /// </summary> /// <param name="maxVolume">If fade in time is not zero on this Variation, max volume is the fully faded in clip's target volume. Otherwise this is not used.</param> public void Play(float?pitch, float maxVolume, PlaySoundParams playParams = null) { SoundFinished = null; // clear it out so subscribers don't have to clean up isWaitingForDelay = false; playSndParams = playParams; // compute pitch if (pitch.HasValue) { _audio.pitch = pitch.Value; } else if (useRandomPitch) { var randPitch = UnityEngine.Random.Range(randomPitchMin, randomPitchMax); switch (randomPitchMode) { case RandomPitchMode.AddToClipPitch: randPitch += OriginalPitch; break; } _audio.pitch = randPitch; } else // non random pitch { audio.pitch = OriginalPitch; } // set fade mode this.curFadeMode = FadeMode.None; curDetectEndMode = DetectEndMode.DetectEnd; StopAllCoroutines(); if (audLocation == MasterAudio.AudioLocation.Clip) { FinishSetupToPlay(); return; } _maxVol = maxVolume; AudioResourceOptimizer.PopulateSourcesWithResourceClip(resourceFileName, this); if (audLocation == MasterAudio.AudioLocation.ResourceFile) { FinishSetupToPlay(); } }