- Home /
AssetPreview.GetMiniTypeThumbnail not working for custom scripts
Hi, I'm developing a Unity extension. I want to display custom script icons in the component list I created.
AssetPreview.GetMiniTypeThumbnail is working perfect for built-in unity icons such as Camera but it's returning an empty icon for custom scripts which have custom icons.
This displays a button with camera icon:
GUILayout.Button(AssetPreview.GetMiniTypeThumbnail(typeof(Camera)), GUILayout.ExpandWidth(false));
This displays an empty button :
GUILayout.Button(AssetPreview.GetMiniTypeThumbnail(typeof(AutoLinker)), GUILayout.ExpandWidth(false));
How can I display the icon for custom scripts?
No. It still doesn't work.
I use this line so, at least, the button shows a C# icon for custom scripts instead of showing an empty button.
var OriginalType = Original.GetType();
var Icon = AssetPreview.GetMiniTypeThumbnail(OriginalType) ?? EditorGUIUtility.IconContent("cs Script Icon").image;
Okay this might help for now, but would there have to be some way to at least get the GUID from the meta file?
You need to get the icon from the type's MonoScript. If you have an Object Instance, you can use MonoScript.FromMonoBehaviour or MonoScript.FromScriptableObject to get the MonoScript. If you don't have an instance, and you can't create one, the only safe way I know to find a MonoScript is to do something like this (it can be slow, so I'd suggest at least caching the results):
foreach (var script in MonoImporter.GetAllRuntimeMonoScripts())
{
if (script.GetClass() == typeof(T) )
{
//script is the MonoScript you're looking for.
}
}
Either way, this gets you the icon from the script: AssetPreview.GetMiniThumbnail(script);
.
Another way to do it, without MonoScripts, is AssetDatabase.GetCachedIcon(path);
but it only works with assets and you must know their paths.
Your answer
Follow this Question
Related Questions
Custom Asset Icons? 2 Answers
Better way to call function from another script from editor script? 1 Answer
Can I write a script to rename objects as I create them? 1 Answer
C# Singleton destructor not called in Editor 1 Answer
How can i convert a prefab instance to an ordinary game object? 2 Answers