private void PlaySoundAndWait() { GrpVariation.IsWaitingForDelay = false; if (VarAudio.clip == null) // in case the warming sound is an "internet file" { return; } VarAudio.Play(); if (GrpVariation.useRandomStartTime) { var offset = Random.Range(GrpVariation.randomStartMinPercent, GrpVariation.randomStartMaxPercent) * 0.01f * VarAudio.clip.length; VarAudio.time = offset; } GrpVariation.LastTimePlayed = Time.time; // sound play worked! Duck music if a ducking sound. MasterAudio.DuckSoundGroup(ParentGroup.GameObjectName, VarAudio); _isPlayingBackward = GrpVariation.OriginalPitch < 0; _lastFrameClipTime = _isPlayingBackward ? VarAudio.clip.length + 1 : -1f; _waitMode = WaitForSoundFinishMode.WaitForEnd; }
/// <summary> /// This method allows you to unpause the audio being played by this Variation. /// </summary> public void Unpause() { if (!_isPaused) // do not unpause if not paused. { return; } if (!IsPlaying) { return; // do not unpause if not playing (stopped) } _isPaused = false; VarAudio.Play(); if (VariationUpdater != null) { VariationUpdater.enabled = true; VariationUpdater.Unpause(); } }
private IEnumerator DetectSoundFinished(float delaySound) { if (useIntroSilence && introSilenceMax > 0f) { var rndSilence = UnityEngine.Random.Range(introSilenceMin, introSilenceMax); isWaitingForDelay = true; if (MasterAudio.IgnoreTimeScale) { yield return(StartCoroutine(CoroutineHelper.WaitForActualSeconds(rndSilence))); } else { yield return(new WaitForSeconds(rndSilence)); } isWaitingForDelay = false; } if (delaySound > 0f) { isWaitingForDelay = true; if (MasterAudio.IgnoreTimeScale) { yield return(StartCoroutine(CoroutineHelper.WaitForActualSeconds(delaySound))); } else { yield return(new WaitForSeconds(delaySound)); } isWaitingForDelay = false; } if (curDetectEndMode != DetectEndMode.DetectEnd) { yield break; } VarAudio.Play(); lastTimePlayed = Time.time; // sound play worked! Duck music if a ducking sound. MasterAudio.DuckSoundGroup(ParentGroup.name, VarAudio); var clipLength = Math.Abs(VarAudio.clip.length / VarAudio.pitch); // wait for clip to play if (MasterAudio.IgnoreTimeScale) { yield return(StartCoroutine(CoroutineHelper.WaitForActualSeconds(clipLength))); } else { yield return(new WaitForSeconds(clipLength)); } if (HasActiveFXFilter && fxTailTime > 0f) { if (MasterAudio.IgnoreTimeScale) { yield return(StartCoroutine(CoroutineHelper.WaitForActualSeconds(fxTailTime))); } else { yield return(new WaitForSeconds(fxTailTime)); } } var playSnd = playSndParams; if (curDetectEndMode != DetectEndMode.DetectEnd) { yield break; } if (!VarAudio.loop || (playSndParams != null && playSndParams.isChainLoop)) { Stop(); } if (playSnd != null && playSnd.isChainLoop) { // check if loop count is over. if (ParentGroup.chainLoopMode == MasterAudioGroup.ChainedLoopLoopMode.NumberOfLoops && ParentGroup.ChainLoopCount >= ParentGroup.chainLoopNumLoops) { // done looping yield break; } var rndDelay = playSnd.delaySoundTime; if (ParentGroup.chainLoopDelayMin > 0f || ParentGroup.chainLoopDelayMax > 0f) { rndDelay = UnityEngine.Random.Range(ParentGroup.chainLoopDelayMin, ParentGroup.chainLoopDelayMax); } // cannot use "AndForget" methods! Chain loop needs to check the status. if (playSnd.attachToSource || playSnd.sourceTrans != null) { if (playSnd.attachToSource) { MasterAudio.PlaySound3DFollowTransform(playSnd.soundType, playSnd.sourceTrans, playSnd.volumePercentage, playSnd.pitch, rndDelay, null, true); } else { MasterAudio.PlaySound3DAtTransform(playSnd.soundType, playSnd.sourceTrans, playSnd.volumePercentage, playSnd.pitch, rndDelay, null, true); } } else { MasterAudio.PlaySound(playSnd.soundType, playSnd.volumePercentage, playSnd.pitch, rndDelay, null, true); } } }