MegaOBJExportEditor.cs 990 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using UnityEngine;
  2. using UnityEditor;
  3. [CanEditMultipleObjects, CustomEditor(typeof(MegaOBJExport))]
  4. public class MegaOBJExportEditor : Editor
  5. {
  6. [MenuItem("GameObject/Mega Export OBJ File")]
  7. static void ExportOBJFile()
  8. {
  9. if ( Selection.activeGameObject )
  10. {
  11. MeshFilter mf = (MeshFilter)Selection.activeGameObject.GetComponent<MeshFilter>();
  12. if ( mf )
  13. {
  14. string path = EditorUtility.SaveFilePanel("OBJ Export Filename", "", mf.gameObject.name + ".obj", "obj");
  15. if ( path.Length != 0 )
  16. MegaOBJExport.MeshToFile(mf, path);
  17. }
  18. }
  19. }
  20. public override void OnInspectorGUI()
  21. {
  22. MegaOBJExport mod = (MegaOBJExport)target;
  23. #if !UNITY_5 && !UNITY_2017 && !UNITY_2018 && !UNITY_2019 && !UNITY_2020
  24. EditorGUIUtility.LookLikeControls();
  25. #endif
  26. DrawDefaultInspector();
  27. if ( GUILayout.Button("Set Path") )
  28. {
  29. string path = EditorUtility.SaveFolderPanel("OBJ Export Path", mod.path, "Path");
  30. if ( path.Length != 0 )
  31. {
  32. mod.path = path;
  33. }
  34. }
  35. }
  36. }