4using System.Collections;
11 private static void OnPostprocessAllAssets(
string[] importedAssets,
string[] deletedAssets,
string[] movedAssets,
string[] movedFromPath)
13 foreach(
string path
in importedAssets.Where(x => x.EndsWith(
".stl")))
15 string dir = Path.GetDirectoryName(path).Replace(
"\\",
"/");
16 string name = Path.GetFileNameWithoutExtension(path);
18 Mesh[] meshes = pb_Stl_Importer.Import(path);
23 GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
24 Material defaultDiffuse = cube.GetComponent<MeshRenderer>().sharedMaterial;
25 GameObject.DestroyImmediate(cube);
27 string prefab_path =
string.Format(
"{0}/{1}.prefab", dir, name);
30 GameObject prefab_source = (GameObject) AssetDatabase.LoadAssetAtPath(prefab_path, typeof(GameObject));
32 GameObject prefab_source = AssetDatabase.LoadAssetAtPath<GameObject>(prefab_path);
34 GameObject prefab =
new GameObject();
36 if(prefab_source ==
null)
37 prefab_source = PrefabUtility.CreatePrefab(prefab_path, prefab);
38 GameObject.DestroyImmediate(prefab);
40 Object[] children = AssetDatabase.LoadAllAssetsAtPath(prefab_path);
42 for(
int i = 0; i < children.Length; i++)
44 if(AssetDatabase.IsSubAsset(children[i]))
45 GameObject.DestroyImmediate(children[i],
true);
48 for(
int i = 0; i < meshes.Length; i++)
49 AssetDatabase.AddObjectToAsset(meshes[i], prefab_source);
51 children = AssetDatabase.LoadAllAssetsAtPath(prefab_path);
52 GameObject render =
new GameObject();
54 for(
int i = 0; i < children.Length; i++)
56 Mesh m = children[i] as Mesh;
57 if(m ==
null)
continue;
58 GameObject child =
new GameObject();
59 child.name =
string.Format(
"{0} ({1})", name, i);
61 child.AddComponent<MeshFilter>().sharedMesh = m;
62 child.AddComponent<MeshRenderer>().sharedMaterial = defaultDiffuse;
63 child.transform.SetParent(render.transform,
false);
66 PrefabUtility.ReplacePrefab(render, prefab_source, ReplacePrefabOptions.ReplaceNameBased);
68 GameObject.DestroyImmediate(render);
74 string dir = Path.GetDirectoryName(path).Replace(
"\\",
"/");
75 string name = Path.GetFileNameWithoutExtension(path);
77 Mesh[] meshes = pb_Stl_Importer.Import(path);
82 for(
int i = 0; i < meshes.Length; i++)
83 AssetDatabase.CreateAsset(meshes[i],
string.Format(
"{0}/{1}{2}.asset", dir, name, i));
86 [MenuItem(
"Tools/Force Import &d")]
89 foreach(
Object o
in Selection.objects)
static void CreateMeshAssetWithPath(string path)