Skip to content

Instantly share code, notes, and snippets.

@Tenebrous
Last active May 22, 2017 13:30
Show Gist options
  • Save Tenebrous/ffe91482fa9694c39b68699ea23c54c6 to your computer and use it in GitHub Desktop.
Save Tenebrous/ffe91482fa9694c39b68699ea23c54c6 to your computer and use it in GitHub Desktop.
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEditor;
[InitializeOnLoad]
public static class ShowFileExtensions
{
static ShowFileExtensions()
{
EditorApplication.projectWindowItemOnGUI += Draw;
}
static HashSet<string> _done = new HashSet<string>();
static float _lastY;
static void Draw( string pGuid, Rect pRect )
{
// if we've restarted drawing, clear list of paths we've done
if( pRect.y < _lastY )
_done.Clear();
var path = AssetDatabase.GUIDToAssetPath( pGuid );
// don't show extension if we've already shown it for this path
// which prevents us showing extensions on sub-assets
if( !_done.Add( path ) )
return;
_lastY = pRect.y;
var filename = Path.GetFileNameWithoutExtension( path );
var extension = Path.GetExtension( path );
if( pRect.height > 20 )
{
// icon mode
var size = EditorStyles.miniLabel.CalcSize( new GUIContent( extension ) );
pRect.x += pRect.width / 2 - size.x / 2;
pRect.width = size.x;
pRect.y += pRect.height - 2;
pRect.height = size.y;
EditorGUI.LabelField( pRect, extension, EditorStyles.miniLabel );
}
else
{
// single column mode
var size = EditorStyles.label.CalcSize( new GUIContent( filename ) );
pRect.x += size.x + 11;
pRect.width -= size.x + 11;
pRect.y += 1;
EditorGUI.LabelField( pRect, extension );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment