private void PlaySoundAndWait() { GrpVariation.IsWaitingForDelay = false; if (VarAudio.clip == null) // in case the warming sound is an "internet file" { return; } VarAudio.Play(); AudioUtil.ClipPlayed(VarAudio.clip, GrpVariation.GameObj); if (GrpVariation.useRandomStartTime) { var offset = Random.Range(GrpVariation.randomStartMinPercent, GrpVariation.randomStartMaxPercent) * 0.01f * VarAudio.clip.length; VarAudio.time = offset; } GrpVariation.LastTimePlayed = AudioUtil.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; }
private void PlaySoundAndWait() { if (VarAudio.clip == null) // in case the warming sound is an "internet file" { return; } double startTime = AudioSettings.dspTime; if (GrpVariation.PlaySoundParm.TimeToSchedulePlay.HasValue) { startTime = GrpVariation.PlaySoundParm.TimeToSchedulePlay.Value; } var delayTime = 0f; if (GrpVariation.useIntroSilence && GrpVariation.introSilenceMax > 0f) { var rndSilence = Random.Range(GrpVariation.introSilenceMin, GrpVariation.introSilenceMax); delayTime += rndSilence; } delayTime += GrpVariation.PlaySoundParm.DelaySoundTime; if (delayTime > 0f) { startTime += delayTime; } VarAudio.PlayScheduled(startTime); AudioUtil.ClipPlayed(VarAudio.clip, GrpVariation.GameObj); if (GrpVariation.useRandomStartTime) { VarAudio.time = ClipStartPosition; if (!VarAudio.loop) // don't stop it if it's going to loop. { var playableLength = AudioUtil.AdjustAudioClipDurationForPitch(ClipEndPosition - ClipStartPosition, VarAudio); _clipSchedEndTime = startTime + playableLength; VarAudio.SetScheduledEndTime(_clipSchedEndTime.Value); } } GrpVariation.LastTimePlayed = AudioUtil.Time; DuckIfNotSilent(); _isPlayingBackward = GrpVariation.OriginalPitch < 0; _lastFrameClipTime = _isPlayingBackward ? ClipEndPosition + 1 : -1f; _waitMode = WaitForSoundFinishMode.WaitForEnd; }