Tanoda
pb_Stl_Menu.cs
Go to the documentation of this file.
1using UnityEngine;
2using UnityEditor;
3using System.Collections;
4using System.Linq;
5
6namespace Parabox.STL
7{
11 public class pb_Stl_Menu : Editor
12 {
13 [MenuItem("Assets/Export Model/STL (Ascii)", true)]
14 [MenuItem("Assets/Export Model/STL (Binary)", true)]
15 static bool VerifyExport()
16 {
17 return Selection.transforms.SelectMany(x => x.GetComponentsInChildren<MeshFilter>()).FirstOrDefault(y => y.sharedMesh != null) != null;
18 }
19
20 [MenuItem("Assets/Export Model/STL (Ascii)", false, 30)]
21 static void MenuExportAscii()
22 {
23 ExportWithFileDialog(Selection.gameObjects, FileType.Ascii);
24 }
25
26 [MenuItem("Assets/Export Model/STL (Binary)", false, 30)]
27 static void MenuExportBinary()
28 {
29 ExportWithFileDialog(Selection.gameObjects, FileType.Binary);
30 }
31
32 private static void ExportWithFileDialog(GameObject[] gameObjects, FileType type)
33 {
34 if(gameObjects == null || gameObjects.Length < 1)
35 {
36 Debug.LogWarning("Attempting to export STL file with no GameObject selected. For reasons that should be obvious this is not allowed.");
37 return;
38 }
39
40 string path = EditorUtility.SaveFilePanel("Save Mesh to STL", "", gameObjects.FirstOrDefault().name, "stl");
41
42 if( pb_Stl_Exporter.Export(path, gameObjects, type) )
43 {
44 string full = path.Replace("\\", "/");
45
46 // if the file was saved in project, ping it
47 if(full.Contains(Application.dataPath))
48 {
49 string relative = full.Replace(Application.dataPath, "Assets");
50
51#if UNITY_4_7
52 Object o = (Object) AssetDatabase.LoadAssetAtPath(relative, typeof(Object));
53#else
54 Object o = AssetDatabase.LoadAssetAtPath<Object>(relative);
55#endif
56
57 if(o != null)
58 EditorGUIUtility.PingObject(o);
59
60 AssetDatabase.Refresh();
61 }
62 }
63 }
64 }
65}
UnityEngine.Debug Debug
Definition: TanodaServer.cs:19
UnityEngine.Object Object