The ScriptedImporter class is a welcome change. However, I’d like to have assets with a particular extension to have an associated icon - instead of the default Unity3D one. Is that possible?
It would be nice to have that wrapped into the ScriptedImporter attribute similar to this …
// Custom importer for *.foo files
[ScriptedImporter(1, "foo", "Assets/Path/To/Foo/Icon.png")]
public class FooImporter : ScriptedImporter
{
// Importer details ...
}
Hmmm … I have a ScriptedImporterEditor inherited class set up for such a thing but RenderStaticPreview is not invoked on it, even if I have overridden HasPreviewGUI to return true. Looking the web there seems to be some difficultly getting this to work. Does anyone know of a working example?
Quick update: If you make your “Main Asset” in your scripted import a type that is previewable (like, say, a texture) then that will be used as an icon. That’s not quite what I’d like but it is something that can work if your imported object (that you want treated as a prefab) falls into the category of supporting a preview.
You can click the icon in the inspector, and change what texture to use there. I think that sets the new icon on every asset of the same type. I might be wrong, though.
Some time ago, Unity provided an overload to AddObjectToAsset that lets you pass in an icon.
So try something like this …
var icon = Texture2D.blackTexture; // Choose your icon here
ctx.AddObjectToAsset(localPath, rootObject, icon); // Pass your icon here
ctx.SetMainObject(rootObject); // your root object's icon is used in the project hierarchy
necroing this, sorry but i didn’t see the 1st question answered…
I use gimp with .xcf files.
They are unknown to unity and i don’t plan to make an XCF importer. I’d just like to have an (gimp) icon for the .xcf extension in the project window.
/// <summary>
/// A custom scripted importer that handles importing ".lua" files as text assets.
/// </summary>
[ScriptedImporter(1, "xcf")]
public class GimpImporter : ScriptedImporter {
public override void OnImportAsset(AssetImportContext ctx)
{
TextAsset desc = new TextAsset("Fichier .XCF à ouvrir avec Gimp");
Texture2D icon = Resources.Load<Texture2D>("The_GIMP_icon");
Object nada = new Object();
ctx.AddObjectToAsset("Fichier Gimp",desc, icon);
}
}
With the same method i will make more visual icons for unknown unity types
This is much more sexy ( and visual ) than those blank squares^^