@@ -15,13 +15,23 @@ namespace Editor
15
15
public class ConvertToPrefabEditorWindow : ExportOptionsEditorWindow
16
16
{
17
17
protected override GUIContent WindowTitle { get { return new GUIContent ( "Convert Options" ) ; } }
18
- protected override float MinWindowHeight { get { return 300 ; } } // determined by trial and error
18
+ protected override float MinWindowHeight { get { return 350 ; } } // determined by trial and error
19
19
protected override string ExportButtonName { get { return "Convert" ; } }
20
- private GameObject [ ] m_toConvert ;
21
20
private string m_prefabFileName = "" ;
22
21
23
22
private float m_prefabExtLabelWidth ;
24
23
24
+ protected override bool DisableNameSelection {
25
+ get {
26
+ return ( ToExport != null && ToExport . Length > 1 ) ;
27
+ }
28
+ }
29
+ protected override bool DisableTransferAnim {
30
+ get {
31
+ return ToExport == null || ToExport . Length > 1 ;
32
+ }
33
+ }
34
+
25
35
public static void Init ( IEnumerable < GameObject > toConvert )
26
36
{
27
37
ConvertToPrefabEditorWindow window = CreateWindow < ConvertToPrefabEditorWindow > ( ) ;
@@ -31,13 +41,24 @@ public static void Init (IEnumerable<GameObject> toConvert)
31
41
}
32
42
33
43
protected void SetGameObjectsToConvert ( IEnumerable < GameObject > toConvert ) {
34
- m_toConvert = toConvert . OrderBy ( go => go . name ) . ToArray ( ) ;
44
+ ToExport = toConvert . OrderBy ( go => go . name ) . ToArray ( ) ;
35
45
36
- if ( m_toConvert . Length == 1 ) {
37
- m_prefabFileName = m_toConvert [ 0 ] . name ;
38
- } else if ( m_toConvert . Length > 1 ) {
46
+ TransferAnimationSource = null ;
47
+ TransferAnimationDest = null ;
48
+
49
+ if ( ToExport . Length == 1 ) {
50
+ m_prefabFileName = ToExport [ 0 ] . name ;
51
+
52
+ // if only one object selected, set transfer source/dest to this object
53
+ var go = ModelExporter . GetGameObject ( ToExport [ 0 ] ) ;
54
+ if ( go ) {
55
+ TransferAnimationSource = go . transform ;
56
+ TransferAnimationDest = go . transform ;
57
+ }
58
+ } else if ( ToExport . Length > 1 ) {
39
59
m_prefabFileName = "(automatic)" ;
40
60
}
61
+
41
62
this . SetFilename ( m_prefabFileName ) ;
42
63
}
43
64
@@ -73,29 +94,31 @@ protected override bool Export ()
73
94
return false ;
74
95
}
75
96
76
- if ( m_toConvert == null ) {
97
+ if ( ToExport == null ) {
77
98
Debug . LogError ( "FbxExporter: missing object for conversion" ) ;
78
99
return false ;
79
100
}
80
101
81
- if ( m_toConvert . Length == 1 ) {
102
+ if ( ToExport . Length == 1 ) {
103
+ var go = ModelExporter . GetGameObject ( ToExport [ 0 ] ) ;
82
104
ConvertToModel . Convert (
83
- m_toConvert [ 0 ] , fbxFullPath : fbxPath , prefabFullPath : prefabPath , exportOptions : ExportSettings . instance . convertToPrefabSettings . info
105
+ go , fbxFullPath : fbxPath , prefabFullPath : prefabPath , exportOptions : ExportSettings . instance . convertToPrefabSettings . info
84
106
) ;
85
107
return true ;
86
108
}
87
109
88
- foreach ( var go in m_toConvert ) {
110
+ foreach ( var obj in ToExport ) {
111
+ var go = ModelExporter . GetGameObject ( obj ) ;
89
112
ConvertToModel . Convert (
90
113
go , fbxDirectoryFullPath : fbxDirPath , prefabDirectoryFullPath : prefabDirPath , exportOptions : ExportSettings . instance . convertToPrefabSettings . info
91
114
) ;
92
115
}
93
116
return true ;
94
117
}
95
118
96
- protected override bool DisableNameSelection ( )
119
+ protected override ExportOptionsSettingsSerializeBase SettingsObject
97
120
{
98
- return m_toConvert . Length > 1 ;
121
+ get { return ExportSettings . instance . convertToPrefabSettings . info ; }
99
122
}
100
123
#if UNITY_2018_1_OR_NEWER
101
124
protected override void ShowPresetReceiver ( )
@@ -107,10 +130,10 @@ protected override void CreateCustomUI ()
107
130
{
108
131
GUILayout . BeginHorizontal ( ) ;
109
132
EditorGUILayout . LabelField ( new GUIContent (
110
- "Prefab Name: " ,
133
+ "Prefab Name" ,
111
134
"Filename to save prefab to." ) , GUILayout . Width ( LabelWidth - TextFieldAlignOffset ) ) ;
112
135
113
- EditorGUI . BeginDisabledGroup ( DisableNameSelection ( ) ) ;
136
+ EditorGUI . BeginDisabledGroup ( DisableNameSelection ) ;
114
137
// Show the export name with an uneditable ".prefab" at the end
115
138
//-------------------------------------
116
139
EditorGUILayout . BeginVertical ( ) ;
@@ -132,7 +155,7 @@ protected override void CreateCustomUI ()
132
155
133
156
GUILayout . BeginHorizontal ( ) ;
134
157
EditorGUILayout . LabelField ( new GUIContent (
135
- "Prefab Path: " ,
158
+ "Prefab Path" ,
136
159
"Relative path for saving Linked Prefabs." ) , GUILayout . Width ( LabelWidth - FieldOffset ) ) ;
137
160
138
161
var pathLabels = ExportSettings . GetRelativePrefabSavePaths ( ) ;
0 commit comments