Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Requested Feature: Writer Audio lerp toggle (take 3) #1005

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions Assets/Fungus/Scripts/Components/WriterAudio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public class WriterAudio : MonoBehaviour, IWriterListener
[Tooltip("Sound effect to play on user input (e.g. a click)")]
[SerializeField] protected AudioClip inputSound;

[Tooltip("Lerp voice effect while playing. Enabled results in smoother volume transitions between different write sounds. Disable to keep writer volume constant.")]
[SerializeField] protected bool lerpWriterVolume = true;

protected float targetVolume = 0f;

// When true, a beep will be played on every written character glyph
Expand Down Expand Up @@ -219,8 +222,17 @@ protected virtual void Resume()

protected virtual void Update()
{
if(lastUsedAudioSource != null)
lastUsedAudioSource.volume = Mathf.MoveTowards(lastUsedAudioSource.volume, targetVolume, Time.deltaTime * 5f);
if (lastUsedAudioSource != null)
{
if (lerpWriterVolume)
{
lastUsedAudioSource.volume = Mathf.MoveTowards(lastUsedAudioSource.volume, targetVolume, Time.deltaTime * 5f);
}
else
{
lastUsedAudioSource.volume = targetVolume;
}
}
}

#region IWriterListener implementation
Expand Down
3 changes: 3 additions & 0 deletions Assets/Fungus/Scripts/Editor/WriterAudioEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class WriterAudioEditor : Editor
protected SerializedProperty soundEffectProp;
protected SerializedProperty inputSoundProp;
protected SerializedProperty useLegacyAudioLogicProp;
protected SerializedProperty lerpAudioProp;

protected virtual void OnEnable()
{
Expand All @@ -28,6 +29,7 @@ protected virtual void OnEnable()
beepSoundsProp = serializedObject.FindProperty("beepSounds");
soundEffectProp = serializedObject.FindProperty("soundEffect");
useLegacyAudioLogicProp = serializedObject.FindProperty("useLegacyAudioLogic");
lerpAudioProp = serializedObject.FindProperty("lerpWriterVolume");
}

public override void OnInspectorGUI()
Expand All @@ -37,6 +39,7 @@ public override void OnInspectorGUI()
EditorGUILayout.PropertyField(volumeProp);
EditorGUILayout.PropertyField(loopProp);
EditorGUILayout.PropertyField(useLegacyAudioLogicProp);
EditorGUILayout.PropertyField(lerpAudioProp);
if (useLegacyAudioLogicProp.boolValue)
{
EditorGUILayout.PropertyField(targetAudioSourceProp);
Expand Down