I was wondering, is there a way to render an asset preview for a custom tile?
I suppose I could create a custom inspector, override RenderStaticPreview, take the tile’s sprite’s texture (which would be tricky as it’s a Multiple sprite) and multiply every pixel by the tile’s color, but I think there should be an easier way since Unity already does all that for default tiles.
Also, why not make a preview render automatically for any custom tile that derives from Tile, without the need of a custom incpector (it has a Sprite, what else do you need?) ?
This is especially annoying because in my project I have a custom inspector for the Tile class, so I don’t have default previews at all, and it becomes a lot harder to navigate in the assets.

1 Like
Ok, here’s what I did for now. But this really should be a default feature.
public override Texture2D RenderStaticPreview(string assetPath, Object[] subAssets, int width, int height)
{
Tile tile = AssetDatabase.LoadAssetAtPath<Tile>(assetPath);
if (tile.sprite != null)
{
Texture2D spritePreview = AssetPreview.GetAssetPreview(tile.sprite); // Get sprite texture
Color[] pixels = spritePreview.GetPixels();
for (int i = 0; i < pixels.Length; i++)
{
pixels[i] = pixels[i] * tile.color; // Tint
}
spritePreview.SetPixels(pixels);
spritePreview.Apply();
Texture2D preview = new Texture2D(width, height);
EditorUtility.CopySerialized(spritePreview, preview); // Returning the original texture causes an editor crash
return preview;
}
return null;
}
10 Likes