I have written code to force the name display in the Project Window to be overridden. It be disabled on renaming and sub-assets. I think it’s pretty flawed, so please let me know if you can improve it.
I’m sure Unity developers could come up with a far smarter implementation in less than a few minutes if they wanted to…
using System;
using System.IO;
using System.Reflection;
using UnityEditor;
using UnityEngine;
[InitializeOnLoad]
public static class ProjectWindowShowFullAssetName {
static GUIStyle style;
static GUIContent assetGUIContent;
static Color32 backgroundColor;
static Color32 selectedFrameColor;
static ProjectWindowShowFullAssetName() {
EditorApplication.projectWindowItemInstanceOnGUI -= Draw;
EditorApplication.projectWindowItemInstanceOnGUI += Draw;
style = new GUIStyle {
fontSize = 10,
wordWrap = true,
alignment = TextAnchor.UpperCenter,
margin = new RectOffset(0,0,0,0),
};
assetGUIContent = new GUIContent();
if (EditorGUIUtility.isProSkin) {
backgroundColor = new Color32(51, 51, 51, 255);
selectedFrameColor = new Color32(44, 93, 135, 255);
} else {
backgroundColor = new Color32(190, 190, 190, 255);
selectedFrameColor = new Color32(58, 114, 176, 255);
}
}
static int lastFrameCount;
static bool isRenaming;
static void Draw(int instanceID, Rect selectionrect ) {
if (lastFrameCount != Time.frameCount) {
isRenaming = IsRenaming();
lastFrameCount = Time.frameCount;
}
if (isRenaming) return;
if (selectionrect.height <= 20) return;
if (AssetDatabase.IsSubAsset(instanceID)) return;
var path = AssetDatabase.GetAssetPath(instanceID);
if (string.IsNullOrWhiteSpace(path)) return;
var assetName = Path.GetFileNameWithoutExtension(path);
var icon = AssetDatabase.GetCachedIcon(path);
var nameRect = new Rect(selectionrect.x, selectionrect.yMax - 12, selectionrect.width, 12);
bool selected = false;
assetGUIContent.text = assetName;
foreach (var assetguid in Selection.instanceIDs) {
if (assetguid == instanceID) {
selected = true;
break;
}
}
if (EditorGUIUtility.isProSkin) {
style.normal.textColor = Color.white;
} else {
style.normal.textColor = selected ? Color.white : Color.black;
}
var selectedFrameRect = new Rect(nameRect.x - 6, nameRect.y - 1, nameRect.width + 12, style.CalcHeight(assetGUIContent, nameRect.width) + 3);
EditorGUI.DrawRect(selectedFrameRect, selected ? selectedFrameColor : backgroundColor);
EditorGUI.DrawRect(new Rect(selectedFrameRect.xMax - 1, selectedFrameRect.y, 1, selectedFrameRect.height), backgroundColor);
GUI.Label(nameRect, assetName, style);
if (icon) {
var iconRect = new Rect(nameRect.x, nameRect.y - 15, 14, 14);
EditorGUI.DrawRect(iconRect, new Color(0, 0, 0, 0.5f));
GUI.DrawTexture(iconRect, icon);
}
}
static private Assembly asm;
static private EditorWindow projectBrowserWindow;
static private Type typeProjectBrowser;
static bool IsRenaming() {
if (asm == null) asm = Assembly.Load("UnityEditor.dll");
var flag = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance;
if(typeProjectBrowser == null) typeProjectBrowser = asm.GetType("UnityEditor.ProjectBrowser");
if(projectBrowserWindow == null) projectBrowserWindow = EditorWindow.GetWindow(typeProjectBrowser,false,null,false);
var m_ListAreaState = projectBrowserWindow.GetType().GetField("m_ListAreaState", flag).GetValue(projectBrowserWindow);
var m_RenameOverlay = m_ListAreaState.GetType().GetField("m_RenameOverlay", flag).GetValue(m_ListAreaState);
return (bool)m_RenameOverlay.GetType().GetField("m_IsRenaming", flag).GetValue(m_RenameOverlay);
}
}