/// <summary> /// This method allows you to pause the audio being played by this Variation. This is automatically called by MasterAudio.PauseSoundGroup and MasterAudio.PauseBus. /// </summary> public void Pause() { if (!MasterAudio.Instance.resourceClipsPauseDoNotUnload) { switch (audLocation) { case MasterAudio.AudioLocation.ResourceFile: Stop(); return; case MasterAudio.AudioLocation.Clip: if (!AudioUtil.AudioClipWillPreload(VarAudio.clip)) { Stop(); return; } break; } } _isPaused = true; VarAudio.Pause(); if (VariationUpdater.enabled) { VariationUpdater.Pause(); } curFadeMode = FadeMode.None; curPitchMode = PitchMode.None; }
/// <summary> /// This method allows you to fade the sound from this Variation to a specified volume over X seconds. /// </summary> /// <param name="newVolume">The target volume to fade to.</param> /// <param name="fadeTime">The time it will take to fully fade to the target volume.</param> public void FadeToVolume(float newVolume, float fadeTime) { if (newVolume < 0f || newVolume > 1f) { Debug.LogError("Illegal volume passed to FadeToVolume: '" + newVolume + "'. Legal volumes are between 0 and 1"); return; } if (fadeTime <= MasterAudio.InnerLoopCheckInterval) { VarAudio.volume = newVolume; // time really short, just do it at once. if (VarAudio.volume <= 0f) { Stop(); } return; } if (!VarAudio.clip.IsClipReadyToPlay()) { if (ParentGroup.LoggingEnabledForGroup) { MasterAudio.LogWarning("Cannot Fade Variation '" + name + "' because it is still loading."); } return; } if (VariationUpdater != null) { VariationUpdater.FadeOverTimeToVolume(newVolume, fadeTime); } }
private void SetOcclusion() { VariationUpdater.UpdateCachedObjects(); var doesGroupUseOcclusion = UsesOcclusion; if (!doesGroupUseOcclusion) { return; } // set occlusion default if (LowPassFilter == null) { _lpFilter = GetComponent <AudioLowPassFilter>(); if (_lpFilter == null) { _lpFilter = gameObject.AddComponent <AudioLowPassFilter>(); } } else { _lpFilter = GetComponent <AudioLowPassFilter>(); } // ReSharper disable once PossibleNullReferenceException LowPassFilter.cutoffFrequency = AudioUtil.MinCutoffFreq(VariationUpdater); }
private void FinishSetupToPlay() { if (!VarAudio.isPlaying && VarAudio.time > 0f) { // paused. Do nothing except Play } else if (useFades && (fadeInTime > 0f || fadeOutTime > 0f)) { fadeMaxVolume = _maxVol; if (fadeInTime > 0f) { VarAudio.volume = 0f; } if (VariationUpdater != null) { VariationUpdater.enabled = true; VariationUpdater.FadeInOut(); } } VarAudio.loop = AudioLoops; // restore original loop setting in case it got lost by loop setting code below for a previous play. if (_playSndParam.IsPlaying && (_playSndParam.IsChainLoop || _playSndParam.IsSingleSubscribedPlay)) { VarAudio.loop = false; } if (!_playSndParam.IsPlaying) { return; // has already been "stop" 'd. } ParentGroup.AddActiveAudioSourceId(InstanceId); if (VariationUpdater != null) { VariationUpdater.enabled = true; VariationUpdater.WaitForSoundFinish(_playSndParam.DelaySoundTime); } _attachToSource = false; var useClipAgePriority = MasterAudio.Instance.prioritizeOnDistance && (MasterAudio.Instance.useClipAgePriority || ParentGroup.useClipAgePriority); if (!_playSndParam.AttachToSource && !useClipAgePriority) { return; } _attachToSource = _playSndParam.AttachToSource; if (VariationUpdater != null) { VariationUpdater.FollowObject(_attachToSource, ObjectToFollow, useClipAgePriority); } }
/*! \cond PRIVATE */ /// <summary> /// Do not call this method. Used internally for ver specific operations. This will set params for "silent" or randomly skipped variations so that a Chained Loop may continue when no audio is played. /// </summary> public void DoNextChain(float volumePercentage, float?pitch, Transform transActor, bool attach) { EnableUpdater(false); SetPlaySoundParams(ParentGroup.GameObjectName, volumePercentage, volumePercentage, pitch, transActor, attach, 0f, true, false); VariationUpdater.MaybeChain(); VariationUpdater.StopWaitingForFinish(); }
/// <summary> /// This method allows you to stop the audio being played by this Variation. /// </summary> /// <param name="stopEndDetection">Do not ever pass this in.</param> /// <param name="skipLinked">Do not ever pass this in.</param> public void Stop(bool stopEndDetection = false, bool skipLinked = false) { var waitStopped = false; if (stopEndDetection || _isWaitingForDelay) { if (VariationUpdater != null) { VariationUpdater.StopWaitingForFinish(); // turn off the chain loop endless repeat waitStopped = true; } } if (!skipLinked) { PlayEndLinkedGroups(); } _objectToFollow = null; _objectToTriggerFrom = null; ParentGroup.RemoveActiveAudioSourceId(InstanceId); MasterAudio.StopTrackingOcclusionForSource(GameObj); VarAudio.Stop(); VarAudio.time = 0f; if (VariationUpdater != null) { VariationUpdater.StopFollowing(); VariationUpdater.StopFading(); } if (!waitStopped) { if (VariationUpdater != null) { VariationUpdater.StopWaitingForFinish(); } } _playSndParam.IsPlaying = false; if (SoundFinished != null) { var willAbort = _previousSoundFinishedFrame == AudioUtil.FrameCount; _previousSoundFinishedFrame = AudioUtil.FrameCount; if (!willAbort) { SoundFinished(); // parameters aren't used } SoundFinished = null; // clear it out so subscribers don't have to clean up } Trans.localPosition = Vector3.zero; MaybeUnloadClip(); }
/*! \endcond */ private void EnableUpdater(bool waitForSoundFinish = true) { if (VariationUpdater != null) { VariationUpdater.enabled = true; if (waitForSoundFinish) { VariationUpdater.WaitForSoundFinish(_playSndParam.DelaySoundTime); } } }
/*! \endcond */ private void EnableUpdater(bool waitForSoundFinish = true) { if (VariationUpdater != null) { VariationUpdater.enabled = true; VariationUpdater.Initialize(); if (waitForSoundFinish) { VariationUpdater.WaitForSoundFinish(); } } }
/// <summary> /// This method will fully fade out the sound from this Variation to zero using over X seconds. /// </summary> /// <param name="fadeTime">The time it will take to fully fade to the target volume.</param> public void FadeOutNow(float fadeTime) { if (MasterAudio.AppIsShuttingDown) { return; } if (IsPlaying && VariationUpdater != null) { VariationUpdater.FadeOutEarly(fadeTime); } }
/// <summary> /// This method allows you to stop the audio being played by this Variation. /// </summary> public void Stop(bool stopEndDetection = false) { var waitStopped = false; if (stopEndDetection || _isWaitingForDelay) { if (VariationUpdater != null) { VariationUpdater.StopWaitingForFinish(); // turn off the chain loop endless repeat waitStopped = true; } } _objectToFollow = null; _objectToTriggerFrom = null; ParentGroup.RemoveActiveAudioSourceId(InstanceId); VarAudio.Stop(); VarAudio.time = 0f; if (VariationUpdater != null) { VariationUpdater.StopFollowing(); VariationUpdater.StopFading(); } if (!waitStopped) { if (VariationUpdater != null) { VariationUpdater.StopWaitingForFinish(); } } _playSndParam.IsPlaying = false; if (SoundFinished != null) { var willAbort = _previousSoundFinishedFrame == Time.frameCount; _previousSoundFinishedFrame = Time.frameCount; if (!willAbort) { SoundFinished(); // parameters aren't used } SoundFinished = null; // clear it out so subscribers don't have to clean up } MaybeUnloadClip(); }
/// <summary> /// This method allows you to slowly change to a new pitch. /// </summary> /// <param name="pitchAddition">The pitch to add to the current pitch.</param> /// <param name="glideTime">The time it will take to change to that pitch.</param> /// <param name="completionCallback">(Optional) - a method to execute when the pitch glide has completed.</param> public void GlideByPitch(float pitchAddition, float glideTime, System.Action completionCallback = null) { if (pitchAddition == 0) // nothing to do { if (completionCallback != null) { completionCallback(); } return; } var targetPitch = VarAudio.pitch + pitchAddition; if (targetPitch < -3f) { targetPitch = -3f; } if (targetPitch > 3f) { targetPitch = 3f; } if (!VarAudio.clip.IsClipReadyToPlay()) { if (ParentGroup.LoggingEnabledForGroup) { MasterAudio.LogWarning("Cannot GlideToPitch Variation '" + name + "' because it is still loading."); } return; } if (glideTime <= MasterAudio.InnerLoopCheckInterval) { if (VarAudio.pitch != targetPitch) { VarAudio.pitch = targetPitch; // time really short, just do it at once. } if (completionCallback != null) { completionCallback(); } return; } if (VariationUpdater != null) { VariationUpdater.GlidePitch(targetPitch, glideTime, completionCallback); } }
/// <summary> /// This method allows you to pause the audio being played by this Variation. This is automatically called by MasterAudio.PauseSoundGroup and MasterAudio.PauseBus. /// </summary> public void Pause() { if (_audioOriginsThatCanUnload.Contains(audLocation) && !MasterAudio.Instance.resourceClipsPauseDoNotUnload) { Stop(); return; } VarAudio.Pause(); curFadeMode = FadeMode.None; if (VariationUpdater != null) { VariationUpdater.StopWaitingForFinish(); // necessary so that the clip can be unpaused. } }
/// <summary> /// This method allows you to pause the audio being played by this Variation. This is automatically called by MasterAudio.PauseSoundGroup and MasterAudio.PauseBus. /// </summary> public void Pause() { if (audLocation == MasterAudio.AudioLocation.ResourceFile && !MasterAudio.Instance.resourceClipsPauseDoNotUnload) { Stop(); return; } VarAudio.Pause(); curFadeMode = FadeMode.None; if (VariationUpdater != null) { VariationUpdater.StopWaitingForFinish(); // necessary so that the clip can be unpaused. } MaybeUnloadClip(); }
/// <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(); } }
/// <summary> /// This method allows you to fade the sound from this Variation to a specified volume over X seconds. /// </summary> /// <param name="newVolume">The target volume to fade to.</param> /// <param name="fadeTime">The time it will take to fully fade to the target volume.</param> public void FadeToVolume(float newVolume, float fadeTime) { if (newVolume < 0f || newVolume > 1f) { Debug.LogError("Illegal volume passed to FadeToVolume: '" + newVolume + "'. Legal volumes are between 0 and 1"); return; } if (fadeTime <= MasterAudio.InnerLoopCheckInterval) { VarAudio.volume = newVolume; // time really short, just do it at once. if (VarAudio.volume <= 0f) { Stop(); } return; } if (VariationUpdater != null) { VariationUpdater.FadeOverTimeToVolume(newVolume, fadeTime); } }
/// <summary> /// This method allows you to stop the audio being played by this Variation. /// </summary> /// <param name="stopEndDetection">Do not ever pass this in.</param> /// <param name="skipLinked">Do not ever pass this in.</param> public void Stop(bool stopEndDetection = false, bool skipLinked = false) { _isPaused = false; var waitStopped = false; if (stopEndDetection) { if (VariationUpdater != null) { VariationUpdater.StopWaitingForFinish(); // turn off the chain loop endless repeat waitStopped = true; } } if (!skipLinked) { PlayEndLinkedGroups(); } _objectToFollow = null; _objectToTriggerFrom = null; VarAudio.pitch = OriginalPitch; ParentGroup.RemoveActiveAudioSourceId(InstanceId); MasterAudio.StopTrackingOcclusionForSource(GameObj); VarAudio.Stop(); VarAudio.time = 0f; if (VariationUpdater != null) { VariationUpdater.StopFollowing(); VariationUpdater.StopFading(); VariationUpdater.StopPitchGliding(); } if (!waitStopped) { if (VariationUpdater != null) { VariationUpdater.StopWaitingForFinish(); } } _playSndParam.IsPlaying = false; if (SoundFinished != null) { var willAbort = _previousSoundFinishedFrame == AudioUtil.FrameCount; _previousSoundFinishedFrame = AudioUtil.FrameCount; if (!willAbort) { SoundFinished(); // parameters aren't used } MaybeCleanupFinishedDelegate(); } Trans.localPosition = Vector3.zero; MaybeUnloadClip(); if (!MasterAudio.IsWarming) // avoids breaking the Variation if warming sound is "Internet file". { DTMonoHelper.SetActive(GameObj, false); } }
/// <summary> /// This method allows you to stop the audio being played by this Variation. /// </summary> /// <param name="stopEndDetection">Do not ever pass this in.</param> /// <param name="skipLinked">Do not ever pass this in.</param> public void Stop(bool stopEndDetection = false, bool skipLinked = false) { if (IsPlaying && !_isStopRequested) { _isStopRequested = true; } _isPaused = false; var waitStopped = false; if (stopEndDetection) { if (VariationUpdater != null) { VariationUpdater.StopWaitingForFinish(); // turn off the chain loop endless repeat waitStopped = true; } } if (!skipLinked) { PlayEndLinkedGroups(); } _objectToFollow = null; _objectToTriggerFrom = null; VarAudio.pitch = OriginalPitch; ParentGroup.RemoveActiveAudioSourceId(InstanceId); MasterAudio.StopTrackingOcclusionForSource(GameObj); if (VariationUpdater != null) { VariationUpdater.StopFollowing(); VariationUpdater.StopFading(); VariationUpdater.StopPitchGliding(); } if (!waitStopped) { if (VariationUpdater != null) { VariationUpdater.StopWaitingForFinish(); } } _playSndParam.IsPlaying = false; if (SoundFinished != null) { var willAbort = _previousSoundFinishedFrame == AudioUtil.FrameCount; _previousSoundFinishedFrame = AudioUtil.FrameCount; if (!willAbort) { SoundFinished(); // parameters aren't used } MaybeCleanupFinishedDelegate(); } Trans.localPosition = Vector3.zero; switch (_loadStatus) { case MasterAudio.VariationLoadStatus.None: case MasterAudio.VariationLoadStatus.Loaded: case MasterAudio.VariationLoadStatus.LoadFailed: StopEndCleanup(); break; case MasterAudio.VariationLoadStatus.Loading: if (!_isUnloadAddressableCoroutineRunning) { StartCoroutine(WaitForLoadToUnloadClipAndDeactivate()); } break; } }