How to use custom file types as Unity assets

I would to know if it is possible to have following custom features reachable from creating some scripts that will extend Unity editor:

  • custom file extension / file type, that will be handled by editor
  • accessibility to thumbnail of that asset, that is displayed in project window
  • dragging this asset to the scene as a full prefab (hierarchy of game objects), so I can say the asset should be a prefab type in its inside.

In my case an asset should represent generally a gameobject with some child gameobjects, where main gameobject should have mesh renderer and mesh filter to display model and child gameobjects should contain only box colliders and rigid bodies components.

How to achieve that?

I know that according to Unity editor, each prefab parts (components) must have assets that are imported to the project.

It is possible to have one file, that Unity will deal with like pack of prefab that can be dropped into scene, and corresponding assets - in one file?

How generally start work with this issue? What classes / attributes of Unity API will be useful here? Some help will be appreciated :slight_smile:

Strictly speaking Unity doesn’t support custom asset/file types, but there are ways to fake it.

First of all look into AssetPostprocessor class and more specifically into OnPostprocessAllAssets (Unity - Scripting API: AssetPostprocessor.OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths, bool didDomainReload)). It gets called when any files change in project folder. I think that applies to custom files too. So what you can do is listed to OnPostprocessAllAssets and when that is called and there is your file-extension on the list then you generate your prefab from the file. So your file and prefab will be two separate assets in the project view, but that gets you close enough to having automated pipeline.

Some info regarding icons, although I’m not sure it answers your question: