@@ -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
@@ -63,28 +84,30 @@ protected override void Export ()
63
84
return ;
64
85
}
65
86
66
- if ( m_toConvert == null ) {
87
+ if ( ToExport == null ) {
67
88
Debug . LogError ( "FbxExporter: missing object for conversion" ) ;
68
89
return ;
69
90
}
70
91
71
- if ( m_toConvert . Length == 1 ) {
92
+ if ( ToExport . Length == 1 ) {
93
+ var go = ModelExporter . GetGameObject ( ToExport [ 0 ] ) ;
72
94
ConvertToModel . Convert (
73
- m_toConvert [ 0 ] , fbxFullPath : fbxPath , prefabFullPath : prefabPath , exportOptions : ExportSettings . instance . convertToPrefabSettings . info
95
+ go , fbxFullPath : fbxPath , prefabFullPath : prefabPath , exportOptions : ExportSettings . instance . convertToPrefabSettings . info
74
96
) ;
75
97
return ;
76
98
}
77
99
78
- foreach ( var go in m_toConvert ) {
100
+ foreach ( var obj in ToExport ) {
101
+ var go = ModelExporter . GetGameObject ( obj ) ;
79
102
ConvertToModel . Convert (
80
103
go , fbxDirectoryFullPath : fbxDirPath , prefabDirectoryFullPath : prefabDirPath , exportOptions : ExportSettings . instance . convertToPrefabSettings . info
81
104
) ;
82
105
}
83
106
}
84
107
85
- protected override bool DisableNameSelection ( )
108
+ protected override ExportOptionsSettingsSerializeBase SettingsObject
86
109
{
87
- return m_toConvert . Length > 1 ;
110
+ get { return ExportSettings . instance . convertToPrefabSettings . info ; }
88
111
}
89
112
#if UNITY_2018_1_OR_NEWER
90
113
protected override void ShowPresetReceiver ( )
@@ -96,10 +119,10 @@ protected override void CreateCustomUI ()
96
119
{
97
120
GUILayout . BeginHorizontal ( ) ;
98
121
EditorGUILayout . LabelField ( new GUIContent (
99
- "Prefab Name: " ,
122
+ "Prefab Name" ,
100
123
"Filename to save prefab to." ) , GUILayout . Width ( LabelWidth - TextFieldAlignOffset ) ) ;
101
124
102
- EditorGUI . BeginDisabledGroup ( DisableNameSelection ( ) ) ;
125
+ EditorGUI . BeginDisabledGroup ( DisableNameSelection ) ;
103
126
// Show the export name with an uneditable ".prefab" at the end
104
127
//-------------------------------------
105
128
EditorGUILayout . BeginVertical ( ) ;
@@ -121,7 +144,7 @@ protected override void CreateCustomUI ()
121
144
122
145
GUILayout . BeginHorizontal ( ) ;
123
146
EditorGUILayout . LabelField ( new GUIContent (
124
- "Prefab Path: " ,
147
+ "Prefab Path" ,
125
148
"Relative path for saving Linked Prefabs." ) , GUILayout . Width ( LabelWidth - FieldOffset ) ) ;
126
149
127
150
var pathLabels = ExportSettings . GetRelativePrefabSavePaths ( ) ;
0 commit comments