From 26b4eec802dd8e3dcd8ed1500e69212d7598681f Mon Sep 17 00:00:00 2001 From: slabs37 Date: Sun, 21 Dec 2025 12:57:59 +0330 Subject: [PATCH] Add waveform on BG option made the waveform height configurable, and added putting waveform behind timeline instead of a separate window --- .../Editor/AnimationWindow/AnimEditor.cs | 34 ++++++++++++------- .../Swifter/AnimationWindowSettingsGUI.cs | 13 ++++++- .../Editor/Swifter/AudioControlsState.cs | 6 ++++ 3 files changed, 40 insertions(+), 13 deletions(-) diff --git a/Custom Animation Window Tryhard/Editor/AnimationWindow/AnimEditor.cs b/Custom Animation Window Tryhard/Editor/AnimationWindow/AnimEditor.cs index d52cfe9..1d64c96 100644 --- a/Custom Animation Window Tryhard/Editor/AnimationWindow/AnimEditor.cs +++ b/Custom Animation Window Tryhard/Editor/AnimationWindow/AnimEditor.cs @@ -228,13 +228,18 @@ public void OnAnimEditorGUI(EditorWindow parent, Rect position) { Rect? audioWaveformRect = null; if (state.audioControlsState.m_isAudioEnabled && !state.animatorIsOptimized && !m_State.disabled) { - audioWaveformRect = GUILayoutUtility.GetRect(contentWidth, 80); + if (state.audioControlsState.m_waveformBG && !m_State.showCurveEditor) { + // When the waveform is in the background we essentially don't need a window + audioWaveformRect = GUILayoutUtility.GetRect(contentWidth, 0); + } else { + audioWaveformRect = GUILayoutUtility.GetRect(contentWidth, state.audioControlsState.m_waveformHeight); + } } - + // Calling Waveform before main content in order to draw in bg if needed + AudioWaveformOnGUI(contentLayoutRect, audioWaveformRect); // MainContent must be done first since it resizes the Zoomable area. MainContentOnGUI(contentLayoutRect); TimeRulerOnGUI(timerulerRect); - AudioWaveformOnGUI(audioWaveformRect); EventLineOnGUI(eventsRect); GUILayout.EndVertical(); @@ -634,20 +639,25 @@ private void TimeRulerOnGUI(Rect timeRulerRect) { RenderOutOfRangeOverlay(timeRulerRectNoScrollbar); } - private void AudioWaveformOnGUI(Rect? audioWaveformRect) + private void AudioWaveformOnGUI(Rect contentLayoutRect, Rect? audioWaveformRect) { if (!audioWaveformRect.HasValue) { return; } - Rect guiRect = audioWaveformRect.Value; - - GUI.Box(guiRect, GUIContent.none); - Rect noSlidersRect = new Rect(guiRect.xMin, guiRect.yMin, guiRect.width - kSliderThickness, guiRect.height); - - m_State.timeArea.TimeRuler(noSlidersRect, m_State.frameRate, false, true, kDisabledRulerAlpha, m_State.timeFormat); // grid - m_AudioWaveformVisualizer.DrawWaveform(noSlidersRect); + Rect noSlidersRect; + if (state.audioControlsState.m_waveformBG && !m_State.showCurveEditor) { + noSlidersRect = new Rect(contentLayoutRect.xMin, contentLayoutRect.yMax-state.audioControlsState.m_waveformHeight, contentLayoutRect.width - kSliderThickness, state.audioControlsState.m_waveformHeight); + m_AudioWaveformVisualizer.DrawWaveform(noSlidersRect); + } else { + Rect guiRect = audioWaveformRect.Value; + GUI.Box(guiRect, GUIContent.none); + + noSlidersRect = new Rect(guiRect.xMin, guiRect.yMin, guiRect.width - kSliderThickness, guiRect.height); + m_State.timeArea.TimeRuler(noSlidersRect, m_State.frameRate, false, true, kDisabledRulerAlpha, m_State.timeFormat); // grid + m_AudioWaveformVisualizer.DrawWaveform(noSlidersRect); + } if (state.audioControlsState.m_bpmGuideEnabled) { m_AudioWaveformVisualizer.DrawBPMGuide(noSlidersRect); @@ -1299,4 +1309,4 @@ private void InitializeAudioTools() m_AnimationWindowSettingsGUI = new AnimationWindowSettingsGUI(); } } -} +} \ No newline at end of file diff --git a/Custom Animation Window Tryhard/Editor/Swifter/AnimationWindowSettingsGUI.cs b/Custom Animation Window Tryhard/Editor/Swifter/AnimationWindowSettingsGUI.cs index 4f87aab..ab62089 100644 --- a/Custom Animation Window Tryhard/Editor/Swifter/AnimationWindowSettingsGUI.cs +++ b/Custom Animation Window Tryhard/Editor/Swifter/AnimationWindowSettingsGUI.cs @@ -41,7 +41,10 @@ class AnimationWindowSettingsGUI new GUIContent("BPM", "The beats per minute of the audio."); private static GUIContent s_WaveformColorField = new GUIContent("Waveform Color", "The color of the waveform for the audio visualization."); - + private static GUIContent s_WaveformHeightField = + new GUIContent("Waveform Height", "The height of the waveform for the audio visualization."); + private static GUIContent s_WaveformBGField = + new GUIContent("Waveform In Background", "Whether the audio visualization is drawn in the background of timeline."); private static GUIContent s_BpmGuideField = new GUIContent("BPM Guide Enabled", "Whether to enable BPM guides."); private static GUIContent s_BeatPrecisionField = @@ -164,6 +167,14 @@ private void AudioControlsOnGUI(AudioControlsState audioControls) audioControls.m_waveformColor = EditorGUILayout.ColorField(s_WaveformColorField, audioControls.m_waveformColor); EndHorizontal(); + BeginHorizontal(); + audioControls.m_waveformHeight = EditorGUILayout.IntField(s_WaveformHeightField, audioControls.m_waveformHeight); + EndHorizontal(); + + BeginHorizontal(); + audioControls.m_waveformBG = EditorGUILayout.Toggle(s_WaveformBGField, audioControls.m_waveformBG); + EndHorizontal(); + BeginHorizontal(); audioControls.m_latencyMilliseconds = EditorGUILayout.IntField(s_LatencyCompensationField, audioControls.m_latencyMilliseconds); EndHorizontal(); diff --git a/Custom Animation Window Tryhard/Editor/Swifter/AudioControlsState.cs b/Custom Animation Window Tryhard/Editor/Swifter/AudioControlsState.cs index 0f2801c..93cd04f 100644 --- a/Custom Animation Window Tryhard/Editor/Swifter/AudioControlsState.cs +++ b/Custom Animation Window Tryhard/Editor/Swifter/AudioControlsState.cs @@ -7,6 +7,8 @@ public class AudioControlsState : PlayerPrefsSerializer { [SerializeField] public bool m_isAudioEnabled = false; [SerializeField] public Color m_waveformColor = new Color(0, 0.4f, 0.5f, 1); + [SerializeField] public int m_waveformHeight = 80; + [SerializeField] public bool m_waveformBG = false; [SerializeField] public bool m_bpmGuideEnabled = false; [SerializeField] public float m_bpm = 60f; [SerializeField] public Color m_bpmGuideColor = new Color(1, 1, 1, 0.4f); @@ -41,6 +43,8 @@ public override void Load() m_audioClip = AssetDatabase.LoadAssetAtPath(path); } m_waveformColor = LoadColor("waveformColor", new Color(0, 0.4f, 0.5f, 1)); + m_waveformHeight = LoadInt("waveformHeight", 80); + m_waveformBG = LoadBool("waveformBG"); m_bpmGuideEnabled = LoadBool("bpmGuideEnabled"); m_bpm = Mathf.Max(1, LoadFloat("bpm", 60)); m_bpmGuideColor = LoadColor("bpmGuideColor", new Color(1, 1, 1, 0.6f)); @@ -58,6 +62,8 @@ public override void Save() SaveString("audioClipPath", path); } SaveColor("waveformColor", m_waveformColor); + SaveFloat("waveformHeight", m_waveformHeight); + SaveBool("waveformBG", m_waveformBG); SaveBool("bpmGuideEnabled", m_bpmGuideEnabled); SaveFloat("bpm", m_bpm); SaveColor("bpmGuideColor", m_bpmGuideColor);