Skip to content

Instantly share code, notes, and snippets.

@autch
Last active October 13, 2024 13:06
Show Gist options
  • Save autch/3b34d3bba04c5374875e5c2f2490487c to your computer and use it in GitHub Desktop.
Save autch/3b34d3bba04c5374875e5c2f2490487c to your computer and use it in GitHub Desktop.
/*
* このスクリプトを Assets/Editor/ 以下に置く。
* また PSD のアイコンに使う画像を Assets/Editor/PSD.png として置く。
*/
using UnityEditor;
using UnityEngine;
// code stolen from: https://discussions.unity.com/t/editor-changing-an-items-icon-in-the-project-window/552493/6
[UnityEditor.InitializeOnLoad]
public class ProjectIcons : Editor {
static ProjectIcons () {
EditorApplication.projectWindowItemOnGUI += MyCallback();
}
[MenuItem( "EDITORS/ProjectIcons/Enable" )]
private static void EnableIcons () {
EditorApplication.projectWindowItemOnGUI -= ProjectIcons.MyCallback();
EditorApplication.projectWindowItemOnGUI += ProjectIcons.MyCallback();
}
[MenuItem( "EDITORS/ProjectIcons/Disable" )]
private static void DisableIcons () {
EditorApplication.projectWindowItemOnGUI -= ProjectIcons.MyCallback();
}
static EditorApplication.ProjectWindowItemCallback MyCallback () {
EditorApplication.ProjectWindowItemCallback myCallback = IconGUI;
return myCallback;
}
private static void IconGUI ( string s, Rect r ) {
var fileName = AssetDatabase.GUIDToAssetPath( s );
var index = fileName.LastIndexOf( '.' );
if ( index == -1 ) return;
var fileType = fileName[(index + 1)..];
switch ( fileType ) {
case "psd":
r.x += r.width - r.width / 3;
r.y += r.height - r.height / 3 - EditorGUIUtility.singleLineHeight;
r.width /= 3;
r.height /= 3;
GUI.DrawTexture( r, (Texture2D) AssetDatabase.LoadAssetAtPath( "Assets/Editor/PSD.png", typeof( Texture2D ) ) );
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment