From ecfb1adf884439ddee6b8ad7c242e49f32cdde79 Mon Sep 17 00:00:00 2001 From: yasirkula Date: Tue, 10 Dec 2024 19:01:23 +0300 Subject: [PATCH] Added Utilities.DrawHeader function to reduce duplicate OnGUI code --- .../Editor/AssetUsageDetectorWindow.cs | 14 +++----------- Plugins/AssetUsageDetector/Editor/Utilities.cs | 9 +++++++++ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Plugins/AssetUsageDetector/Editor/AssetUsageDetectorWindow.cs b/Plugins/AssetUsageDetector/Editor/AssetUsageDetectorWindow.cs index 5d9faa4..9c41adc 100644 --- a/Plugins/AssetUsageDetector/Editor/AssetUsageDetectorWindow.cs +++ b/Plugins/AssetUsageDetector/Editor/AssetUsageDetectorWindow.cs @@ -502,10 +502,7 @@ namespace AssetUsageDetectorNamespace GUILayout.Space( 10f ); - Color c = GUI.backgroundColor; - GUI.backgroundColor = AssetUsageDetectorSettings.SettingsHeaderColor; - GUILayout.Box( "SEARCH IN", Utilities.BoxGUIStyle, Utilities.GL_EXPAND_WIDTH ); - GUI.backgroundColor = c; + Utilities.DrawHeader( "SEARCH IN" ); searchInAssetsFolder = WordWrappingToggleLeft( "Project window (Assets folder)", searchInAssetsFolder ); @@ -573,9 +570,7 @@ namespace AssetUsageDetectorNamespace GUILayout.Space( 10f ); - GUI.backgroundColor = AssetUsageDetectorSettings.SettingsHeaderColor; - GUILayout.Box( "SETTINGS", Utilities.BoxGUIStyle, Utilities.GL_EXPAND_WIDTH ); - GUI.backgroundColor = c; + Utilities.DrawHeader( "SETTINGS" ); #if ASSET_USAGE_ADDRESSABLES EditorGUI.BeginDisabledGroup( addressablesSupport ); @@ -664,10 +659,7 @@ namespace AssetUsageDetectorNamespace private void DrawObjectsToSearchSection() { - Color c = GUI.backgroundColor; - GUI.backgroundColor = AssetUsageDetectorSettings.SettingsHeaderColor; - GUILayout.Box( "SEARCHED OBJECTS", Utilities.BoxGUIStyle, Utilities.GL_EXPAND_WIDTH ); - GUI.backgroundColor = c; + Utilities.DrawHeader( "SEARCHED OBJECTS" ); Rect searchedObjectsHeaderRect = GUILayoutUtility.GetLastRect(); searchedObjectsHeaderRect.x += 5f; diff --git a/Plugins/AssetUsageDetector/Editor/Utilities.cs b/Plugins/AssetUsageDetector/Editor/Utilities.cs index 141bc31..024fb1d 100644 --- a/Plugins/AssetUsageDetector/Editor/Utilities.cs +++ b/Plugins/AssetUsageDetector/Editor/Utilities.cs @@ -446,6 +446,15 @@ namespace AssetUsageDetectorNamespace return stringBuilder.ToString(); } + // Draw header inside OnGUI + public static void DrawHeader( string label ) + { + Color c = GUI.backgroundColor; + GUI.backgroundColor = AssetUsageDetectorSettings.SettingsHeaderColor; + GUILayout.Box( label, BoxGUIStyle, GL_EXPAND_WIDTH ); + GUI.backgroundColor = c; + } + // Draw horizontal line inside OnGUI public static void DrawSeparatorLine() {