I import models from custom binary format files in `AssetPostprocessor.OnPostprocessAllAssets()` and would like to build a more complex hierarchy around the mesh and place it in a prefab. But in this method I don't have a GameObject that I could have saved in a prefab and objects that I can construct don't seem to want to go into a prefab. Here is how I'm trying to do this:
Mesh dummy = (Mesh)AssetDatabase.LoadAssetAtPath(asset_path, typeof(Mesh));
if (!dummy) {
dummy = new Mesh();
dummy.name = name;
AssetDatabase.CreateAsset(dummy, asset_path);
}
// mesh for the editor
dummy.Clear();
// [ ... generate/import mesh here ...]
Object prefab = EditorUtility.CreateEmptyPrefab(base_path + ".prefab");
GameObject go = new GameObject( name, typeof(MeshFilter));
EditorUtility.ReplacePrefab( go, prefab, ReplacePrefabOptions.ConnectToPrefab );
AssetDatabase.SaveAssets();
AssetDatabase.Refresh(ImportAssetOptions.TryFastReimportFromMetaData);
Object.DestroyImmediate( go );
but the prefab remains empty. Is what I'm trying to do possible at all?
Some related answers:
-
http://answers.unity3d.com/questions/10610/how-can-i-create-a-custom-import-object
- this one sugests using `OnPostprocessAllAssets()` for custom importer
-
http://answers.unity3d.com/questions/1197/creating-a-complex-prefab-during-asset-postprocessing
- this one's about catching an imported model and wrapping it into a prefab hierarchy
But these don't seem enough to solve my problem.