Link_wtf
Member
Registered: 2014-03-14
Posts: 16

Topic

I'm working on a level editor and I'd like to generate previews for each of our brushes. I was wondering how you managed to generate a preview from a prefab.

Is there a API in Unity to do it? Or do you use a custom approach?

Thanks in advance.

Lea Hayes
Rotorz Limited
From: United Kingdom
Registered: 2014-03-04
Posts: 638

Response 1

Originally I was using an internal editor-only Unity API to draw asset previews which was eventually exposed as AssetPreview.GetAssetPreview.

Due to various difficulties I ended up rolling my own thumbnail rendering which is accomplished by setting up a "mini scene" and rendering to a render texture. When I say "mini scene" what I mean is that an instance of the prefab is created along with a camera and light source; these objects are placed onto an unused layer and the camera is blind to everything except this unused layer thus avoiding the rendering of anything else in the scene. To avoid dirtying the scene the appropriate hideFlags value is used.

To avoid unnecessary performance issues the thumbnails are cached which gets refreshed whenever changes to the asset file are detected or whenever the user uses the "Refresh Preview" menu item on the brush.

I hope that this helps with your question!

Link_wtf
Member
Registered: 2014-03-14
Posts: 16

Response 2

This look like a great solution, thank you very much :)