1
+ using System . Collections ;
2
+ using System . Collections . Generic ;
3
+ using UnityEngine ;
4
+ using UnityEditor ;
5
+ using FbxExporters . EditorTools ;
6
+
7
+ namespace FbxExporters
8
+ {
9
+ namespace Editor
10
+ {
11
+ public class ExportModelEditorWindow : EditorWindow
12
+ {
13
+
14
+ private const string WindowTitle = "Export Options" ;
15
+ private const float SelectableLabelMinWidth = 90 ;
16
+ private const float BrowseButtonWidth = 25 ;
17
+ private const float LabelWidth = 144 ;
18
+ private const float FieldOffset = 18 ;
19
+
20
+ public static void Init ( )
21
+ {
22
+ ExportModelEditorWindow window = ( ExportModelEditorWindow ) EditorWindow . GetWindow < ExportModelEditorWindow > ( WindowTitle , focus : true ) ;
23
+ window . Show ( ) ;
24
+
25
+ window . minSize = new Vector2 ( SelectableLabelMinWidth + LabelWidth + BrowseButtonWidth , 100 ) ;
26
+ }
27
+
28
+ void OnGUI ( )
29
+ {
30
+ // Increasing the label width so that none of the text gets cut off
31
+ EditorGUIUtility . labelWidth = LabelWidth ;
32
+
33
+ EditorGUILayout . LabelField ( "Naming" , EditorStyles . boldLabel ) ;
34
+ EditorGUI . indentLevel ++ ;
35
+ GUILayout . BeginHorizontal ( ) ;
36
+ EditorGUILayout . LabelField ( new GUIContent (
37
+ "Export Path:" ,
38
+ "Relative path for saving Model Prefabs." ) , GUILayout . Width ( LabelWidth - FieldOffset ) ) ;
39
+
40
+ var pathLabel = ExportSettings . GetRelativeSavePath ( ) ;
41
+ if ( pathLabel == "." ) { pathLabel = "(Assets root)" ; }
42
+ EditorGUILayout . SelectableLabel ( pathLabel ,
43
+ EditorStyles . textField ,
44
+ GUILayout . MinWidth ( SelectableLabelMinWidth ) ,
45
+ GUILayout . Height ( EditorGUIUtility . singleLineHeight ) ) ;
46
+
47
+ if ( GUILayout . Button ( new GUIContent ( "..." , "Browse to a new location for saving model prefabs" ) , EditorStyles . miniButton , GUILayout . Width ( BrowseButtonWidth ) ) )
48
+ {
49
+ string initialPath = ExportSettings . GetAbsoluteSavePath ( ) ;
50
+
51
+ // if the directory doesn't exist, set it to the default save path
52
+ // so we don't open somewhere unexpected
53
+ if ( ! System . IO . Directory . Exists ( initialPath ) )
54
+ {
55
+ initialPath = Application . dataPath ;
56
+ }
57
+
58
+ string fullPath = EditorUtility . OpenFolderPanel (
59
+ "Select Model Prefabs Path" , initialPath , null
60
+ ) ;
61
+
62
+ // Unless the user canceled, make sure they chose something in the Assets folder.
63
+ if ( ! string . IsNullOrEmpty ( fullPath ) )
64
+ {
65
+ var relativePath = ExportSettings . ConvertToAssetRelativePath ( fullPath ) ;
66
+ if ( string . IsNullOrEmpty ( relativePath ) )
67
+ {
68
+ Debug . LogWarning ( "Please select a location in the Assets folder" ) ;
69
+ }
70
+ else
71
+ {
72
+ ExportSettings . SetRelativeSavePath ( relativePath ) ;
73
+
74
+ // Make sure focus is removed from the selectable label
75
+ // otherwise it won't update
76
+ GUIUtility . hotControl = 0 ;
77
+ GUIUtility . keyboardControl = 0 ;
78
+ }
79
+ }
80
+ }
81
+
82
+ GUILayout . EndHorizontal ( ) ;
83
+ }
84
+ }
85
+ }
86
+ }
0 commit comments