Created
October 20, 2026 21:17
-
-
Save unitycoder/6fd2f5f390052c7718ac690044a6a115 to your computer and use it in GitHub Desktop.
Unity 7000 Alpha Project Window Row Height Fixer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // unity added mega-padding/margins to project window items.. can adjust them with this script. | |
| using System; | |
| using System.Collections.Generic; | |
| using System.Reflection; | |
| using UnityEditor; | |
| using UnityEngine; | |
| [InitializeOnLoad] | |
| internal static class CompactProjectWindowRows | |
| { | |
| private const string EnabledKey = "CompactProjectWindow.Enabled"; | |
| private const string HeightKey = "CompactProjectWindow.RowHeight"; | |
| private const BindingFlags Flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; | |
| private static readonly Type ProjectBrowserType = typeof(EditorWindow).Assembly.GetType("UnityEditor.ProjectBrowser"); | |
| private static readonly Dictionary<object, float> OriginalHeights = new Dictionary<object, float>(); | |
| private static double nextUpdate; | |
| private static bool warned; | |
| internal static bool Enabled { get; private set; } = EditorPrefs.GetBool(EnabledKey, false); | |
| internal static int RowHeight { get; private set; } = EditorPrefs.GetInt(HeightKey, 14); | |
| internal static bool Supported => ProjectBrowserType != null; | |
| static CompactProjectWindowRows() | |
| { | |
| EditorApplication.update += Update; | |
| AssemblyReloadEvents.beforeAssemblyReload += Restore; | |
| EditorApplication.quitting += Restore; | |
| } | |
| internal static void SetEnabled(bool value) | |
| { | |
| if (Enabled == value) | |
| return; | |
| Enabled = value; | |
| EditorPrefs.SetBool(EnabledKey, Enabled); | |
| if (Enabled) | |
| Apply(); | |
| else | |
| Restore(); | |
| } | |
| internal static void SetRowHeight(int value) | |
| { | |
| RowHeight = Mathf.Clamp(value, 12, 24); | |
| EditorPrefs.SetInt(HeightKey, RowHeight); | |
| if (Enabled) | |
| Apply(); | |
| } | |
| private static void Update() | |
| { | |
| if (!Enabled || EditorApplication.timeSinceStartup < nextUpdate) | |
| return; | |
| nextUpdate = EditorApplication.timeSinceStartup + 0.5; | |
| Apply(); | |
| } | |
| private static void Apply() | |
| { | |
| if (ProjectBrowserType == null) | |
| return; | |
| foreach (UnityEngine.Object obj in Resources.FindObjectsOfTypeAll(ProjectBrowserType)) | |
| { | |
| EditorWindow window = obj as EditorWindow; | |
| if (window == null) | |
| continue; | |
| bool changed = TryApplyTree(window, "m_AssetTree"); | |
| changed |= TryApplyTree(window, "m_FolderTree"); | |
| if (changed) | |
| window.Repaint(); | |
| } | |
| } | |
| private static bool TryApplyTree(EditorWindow browser, string fieldName) | |
| { | |
| try | |
| { | |
| FieldInfo treeField = ProjectBrowserType.GetField(fieldName, Flags); | |
| object tree = treeField?.GetValue(browser); | |
| object gui = tree?.GetType().GetProperty("gui", Flags)?.GetValue(tree, null); | |
| if (gui == null) | |
| return false; | |
| PropertyInfo lineHeight = gui.GetType().GetProperty("k_LineHeight", Flags); | |
| if (lineHeight == null || !lineHeight.CanRead || !lineHeight.CanWrite) | |
| return false; | |
| float current = (float)lineHeight.GetValue(gui, null); | |
| if (!OriginalHeights.ContainsKey(gui)) | |
| OriginalHeights.Add(gui, current); | |
| if (Mathf.Approximately(current, RowHeight)) | |
| return false; | |
| lineHeight.SetValue(gui, (float)RowHeight, null); | |
| return true; | |
| } | |
| catch (Exception ex) | |
| { | |
| if (!warned) | |
| { | |
| warned = true; | |
| Debug.LogWarning("Compact Project Window: Unity internals changed or could not be accessed. " + ex.Message); | |
| } | |
| return false; | |
| } | |
| } | |
| internal static void Restore() | |
| { | |
| foreach (KeyValuePair<object, float> entry in OriginalHeights) | |
| { | |
| try | |
| { | |
| PropertyInfo property = entry.Key.GetType().GetProperty("k_LineHeight", Flags); | |
| property?.SetValue(entry.Key, entry.Value, null); | |
| } | |
| catch (Exception) | |
| { | |
| // Ignore tree views that Unity has already destroyed. | |
| } | |
| } | |
| OriginalHeights.Clear(); | |
| if (ProjectBrowserType == null) | |
| return; | |
| foreach (UnityEngine.Object obj in Resources.FindObjectsOfTypeAll(ProjectBrowserType)) | |
| { | |
| if (obj is EditorWindow window) | |
| window.Repaint(); | |
| } | |
| } | |
| } | |
| internal sealed class CompactProjectWindowSettings : EditorWindow | |
| { | |
| [MenuItem("Tools/Compact Project Window")] | |
| private static void Open() | |
| { | |
| GetWindow<CompactProjectWindowSettings>("Compact Project"); | |
| } | |
| private void OnGUI() | |
| { | |
| EditorGUILayout.LabelField("Project Tree Spacing", EditorStyles.boldLabel); | |
| if (!CompactProjectWindowRows.Supported) | |
| { | |
| EditorGUILayout.HelpBox("Could not find UnityEditor.ProjectBrowser in this Unity version.", MessageType.Warning); | |
| return; | |
| } | |
| EditorGUI.BeginChangeCheck(); | |
| bool enabled = EditorGUILayout.Toggle("Enabled", CompactProjectWindowRows.Enabled); | |
| if (EditorGUI.EndChangeCheck()) | |
| CompactProjectWindowRows.SetEnabled(enabled); | |
| using (new EditorGUI.DisabledScope(!CompactProjectWindowRows.Enabled)) | |
| { | |
| EditorGUI.BeginChangeCheck(); | |
| int height = EditorGUILayout.IntSlider("Row height", CompactProjectWindowRows.RowHeight, 12, 24); | |
| if (EditorGUI.EndChangeCheck()) | |
| CompactProjectWindowRows.SetRowHeight(height); | |
| } | |
| if (GUILayout.Button("Restore Unity defaults")) | |
| CompactProjectWindowRows.SetEnabled(false); | |
| EditorGUILayout.Space(8); | |
| EditorGUILayout.HelpBox( | |
| "Applies to the folder tree in Two Column mode and the asset tree in One Column mode. " + | |
| "The right-hand asset list in Two Column mode uses a separate hard-coded 16px row height and is not changed. " + | |
| "Heights below 16px may clip icons. This relies on unsupported Unity internals.", | |
| MessageType.Info); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment