@@ -23,20 +23,77 @@ public abstract class ExportOptionsEditorWindow : EditorWindow
23
23
24
24
protected virtual GUIContent WindowTitle { get { return new GUIContent ( DefaultWindowTitle ) ; } }
25
25
26
- protected string m_exportFileName = "" ;
26
+ private string m_exportFileName = "" ;
27
+ protected string ExportFileName
28
+ {
29
+ get { return m_exportFileName ; }
30
+ set { m_exportFileName = value ; }
31
+ }
27
32
28
- protected UnityEditor . Editor m_innerEditor ;
29
- #if UNITY_2018_1_OR_NEWER
30
- protected FbxExportPresetSelectorReceiver m_receiver ;
33
+ private UnityEditor . Editor m_innerEditor ;
34
+ protected UnityEditor . Editor InnerEditor
35
+ {
36
+ get { return m_innerEditor ; }
37
+ set { m_innerEditor = value ; }
38
+ }
39
+ #if UNITY_2018_1_OR_NEWER
40
+ private FbxExportPresetSelectorReceiver m_receiver ;
41
+ protected FbxExportPresetSelectorReceiver Receiver
42
+ {
43
+ get { return m_receiver ; }
44
+ set { m_receiver = value ; }
45
+ }
31
46
#endif
32
47
private static GUIContent presetIcon { get { return EditorGUIUtility . IconContent ( "Preset.Context" ) ; } }
33
48
private static GUIStyle presetIconButton { get { return new GUIStyle ( "IconButton" ) ; } }
34
49
35
50
private bool m_showOptions ;
36
51
37
- protected GUIStyle m_nameTextFieldStyle ;
38
- protected GUIStyle m_fbxExtLabelStyle ;
39
- protected float m_fbxExtLabelWidth ;
52
+ private GUIStyle m_nameTextFieldStyle ;
53
+ protected GUIStyle NameTextFieldStyle
54
+ {
55
+ get {
56
+ if ( m_nameTextFieldStyle == null )
57
+ {
58
+ m_nameTextFieldStyle = new GUIStyle ( GUIStyle . none ) ;
59
+ m_nameTextFieldStyle . alignment = TextAnchor . LowerCenter ;
60
+ m_nameTextFieldStyle . clipping = TextClipping . Clip ;
61
+ m_nameTextFieldStyle . normal . textColor = EditorStyles . textField . normal . textColor ;
62
+ }
63
+ return m_nameTextFieldStyle ;
64
+ }
65
+ set { m_nameTextFieldStyle = value ; }
66
+ }
67
+
68
+ private GUIStyle m_fbxExtLabelStyle ;
69
+ protected GUIStyle FbxExtLabelStyle
70
+ {
71
+ get {
72
+ if ( m_fbxExtLabelStyle == null )
73
+ {
74
+ m_fbxExtLabelStyle = new GUIStyle ( GUIStyle . none ) ;
75
+ m_fbxExtLabelStyle . alignment = TextAnchor . MiddleLeft ;
76
+ m_fbxExtLabelStyle . richText = true ;
77
+ m_fbxExtLabelStyle . contentOffset = new Vector2 ( FbxExtOffset , 0 ) ;
78
+ }
79
+ return m_fbxExtLabelStyle ;
80
+ }
81
+ set { m_fbxExtLabelStyle = value ; }
82
+ }
83
+
84
+ private float m_fbxExtLabelWidth = - 1 ;
85
+ protected float FbxExtLabelWidth
86
+ {
87
+ get
88
+ {
89
+ if ( m_fbxExtLabelWidth < 0 )
90
+ {
91
+ m_fbxExtLabelWidth = FbxExtLabelStyle . CalcSize ( new GUIContent ( ".fbx" ) ) . x ;
92
+ }
93
+ return m_fbxExtLabelWidth ;
94
+ }
95
+ set { m_fbxExtLabelWidth = value ; }
96
+ }
40
97
41
98
protected abstract bool DisableTransferAnim { get ; }
42
99
protected abstract bool DisableNameSelection { get ; }
@@ -55,18 +112,6 @@ protected virtual void OnEnable(){
55
112
#endif
56
113
m_showOptions = true ;
57
114
this . minSize = new Vector2 ( SelectableLabelMinWidth + LabelWidth + BrowseButtonWidth , MinWindowHeight ) ;
58
-
59
- m_nameTextFieldStyle = new GUIStyle ( GUIStyle . none ) ;
60
- m_nameTextFieldStyle . alignment = TextAnchor . LowerCenter ;
61
- m_nameTextFieldStyle . clipping = TextClipping . Clip ;
62
- m_nameTextFieldStyle . normal . textColor = EditorStyles . textField . normal . textColor ;
63
-
64
- m_fbxExtLabelStyle = new GUIStyle ( GUIStyle . none ) ;
65
- m_fbxExtLabelStyle . alignment = TextAnchor . MiddleLeft ;
66
- m_fbxExtLabelStyle . richText = true ;
67
- m_fbxExtLabelStyle . contentOffset = new Vector2 ( FbxExtOffset , 0 ) ;
68
-
69
- m_fbxExtLabelWidth = m_fbxExtLabelStyle . CalcSize ( new GUIContent ( ".fbx" ) ) . x ;
70
115
}
71
116
72
117
protected static T CreateWindow < T > ( ) where T : EditorWindow {
@@ -80,24 +125,24 @@ protected virtual void InitializeWindow(string filename = ""){
80
125
81
126
#if UNITY_2018_1_OR_NEWER
82
127
protected void InitializeReceiver ( ) {
83
- if ( ! m_receiver ) {
84
- m_receiver = ScriptableObject . CreateInstance < FbxExportPresetSelectorReceiver > ( ) as FbxExportPresetSelectorReceiver ;
85
- m_receiver . SelectionChanged -= OnPresetSelectionChanged ;
86
- m_receiver . SelectionChanged += OnPresetSelectionChanged ;
87
- m_receiver . DialogClosed -= SaveExportSettings ;
88
- m_receiver . DialogClosed += SaveExportSettings ;
128
+ if ( ! Receiver ) {
129
+ Receiver = ScriptableObject . CreateInstance < FbxExportPresetSelectorReceiver > ( ) as FbxExportPresetSelectorReceiver ;
130
+ Receiver . SelectionChanged -= OnPresetSelectionChanged ;
131
+ Receiver . SelectionChanged += OnPresetSelectionChanged ;
132
+ Receiver . DialogClosed -= SaveExportSettings ;
133
+ Receiver . DialogClosed += SaveExportSettings ;
89
134
}
90
135
}
91
136
#endif
92
137
93
- public void SetFilename ( string filename ) {
138
+ internal void SetFilename ( string filename ) {
94
139
// remove .fbx from end of filename
95
140
int extIndex = filename . LastIndexOf ( ".fbx" ) ;
96
141
if ( extIndex < 0 ) {
97
- m_exportFileName = filename ;
142
+ ExportFileName = filename ;
98
143
return ;
99
144
}
100
- m_exportFileName = filename . Remove ( extIndex ) ;
145
+ ExportFileName = filename . Remove ( extIndex ) ;
101
146
}
102
147
103
148
public void SaveExportSettings ( )
@@ -124,9 +169,9 @@ protected virtual void CreateCustomUI(){}
124
169
125
170
protected void ShowPresetReceiver ( UnityEngine . Object target ) {
126
171
InitializeReceiver ( ) ;
127
- m_receiver . SetTarget ( target ) ;
128
- m_receiver . SetInitialValue ( new Preset ( target ) ) ;
129
- UnityEditor . Presets . PresetSelector . ShowSelector ( target , null , true , m_receiver ) ;
172
+ Receiver . SetTarget ( target ) ;
173
+ Receiver . SetInitialValue ( new Preset ( target ) ) ;
174
+ UnityEditor . Presets . PresetSelector . ShowSelector ( target , null , true , Receiver ) ;
130
175
}
131
176
#endif
132
177
@@ -184,9 +229,11 @@ protected bool IsInSameHierarchy(Transform t1, Transform t2){
184
229
}
185
230
186
231
187
- protected virtual GameObject GetGameObject ( )
232
+ protected virtual GameObject FirstGameObjectToExport
188
233
{
189
- return ModelExporter . GetGameObject ( ToExport [ 0 ] ) ;
234
+ get {
235
+ return ModelExporter . GetGameObject ( ToExport [ 0 ] ) ;
236
+ }
190
237
}
191
238
192
239
protected bool TransferAnimationSourceIsValid ( Transform newValue ) {
@@ -199,7 +246,7 @@ protected bool TransferAnimationSourceIsValid(Transform newValue){
199
246
return false ;
200
247
}
201
248
202
- var selectedGO = GetGameObject ( ) ;
249
+ var selectedGO = FirstGameObjectToExport ;
203
250
204
251
// source must be ancestor to dest
205
252
if ( TransferAnimationDest && ! IsAncestor ( newValue , TransferAnimationDest ) ) {
@@ -224,7 +271,7 @@ protected bool TransferAnimationDestIsValid(Transform newValue){
224
271
return false ;
225
272
}
226
273
227
- var selectedGO = GetGameObject ( ) ;
274
+ var selectedGO = FirstGameObjectToExport ;
228
275
229
276
// source must be ancestor to dest
230
277
if ( TransferAnimationSource && ! IsAncestor ( TransferAnimationSource , newValue ) ) {
@@ -242,7 +289,7 @@ protected bool TransferAnimationDestIsValid(Transform newValue){
242
289
/// <summary>
243
290
/// Add UI to turn the dialog off next time the user exports
244
291
/// </summary>
245
- protected virtual void DontShowDialogUI ( ) { }
292
+ protected virtual void DoNotShowDialogUI ( ) { }
246
293
247
294
// -------------------------------------------------------------------------------------
248
295
@@ -277,11 +324,11 @@ protected void OnGUI ()
277
324
EditorGUILayout . BeginHorizontal ( EditorStyles . textField , GUILayout . Height ( EditorGUIUtility . singleLineHeight ) ) ;
278
325
EditorGUI . indentLevel -- ;
279
326
// continually resize to contents
280
- var textFieldSize = m_nameTextFieldStyle . CalcSize ( new GUIContent ( m_exportFileName ) ) ;
281
- m_exportFileName = EditorGUILayout . TextField ( m_exportFileName , m_nameTextFieldStyle , GUILayout . Width ( textFieldSize . x + 5 ) , GUILayout . MinWidth ( 5 ) ) ;
282
- m_exportFileName = ModelExporter . ConvertToValidFilename ( m_exportFileName ) ;
327
+ var textFieldSize = NameTextFieldStyle . CalcSize ( new GUIContent ( ExportFileName ) ) ;
328
+ ExportFileName = EditorGUILayout . TextField ( ExportFileName , NameTextFieldStyle , GUILayout . Width ( textFieldSize . x + 5 ) , GUILayout . MinWidth ( 5 ) ) ;
329
+ ExportFileName = ModelExporter . ConvertToValidFilename ( ExportFileName ) ;
283
330
284
- EditorGUILayout . LabelField ( "<color=#808080ff>.fbx</color>" , m_fbxExtLabelStyle , GUILayout . Width ( m_fbxExtLabelWidth ) ) ;
331
+ EditorGUILayout . LabelField ( "<color=#808080ff>.fbx</color>" , FbxExtLabelStyle , GUILayout . Width ( FbxExtLabelWidth ) ) ;
285
332
EditorGUI . indentLevel ++ ;
286
333
287
334
EditorGUILayout . EndHorizontal ( ) ;
@@ -350,13 +397,13 @@ protected void OnGUI ()
350
397
m_showOptions = EditorGUILayout . Foldout ( m_showOptions , "Options" ) ;
351
398
EditorGUI . indentLevel ++ ;
352
399
if ( m_showOptions ) {
353
- m_innerEditor . OnInspectorGUI ( ) ;
400
+ InnerEditor . OnInspectorGUI ( ) ;
354
401
}
355
402
356
403
GUILayout . FlexibleSpace ( ) ;
357
404
358
405
GUILayout . BeginHorizontal ( ) ;
359
- DontShowDialogUI ( ) ;
406
+ DoNotShowDialogUI ( ) ;
360
407
GUILayout . FlexibleSpace ( ) ;
361
408
if ( GUILayout . Button ( "Cancel" , GUILayout . Width ( ExportButtonWidth ) ) ) {
362
409
this . Close ( ) ;
@@ -406,11 +453,14 @@ protected override bool DisableNameSelection {
406
453
}
407
454
}
408
455
409
- protected override GameObject GetGameObject ( )
456
+ protected override GameObject FirstGameObjectToExport
410
457
{
411
- return ( IsTimelineAnim )
412
- ? AnimationOnlyExportData . GetGameObjectAndAnimationClip ( ToExport [ 0 ] ) . Key
413
- : ModelExporter . GetGameObject ( ToExport [ 0 ] ) ;
458
+ get
459
+ {
460
+ return ( IsTimelineAnim )
461
+ ? AnimationOnlyExportData . GetGameObjectAndAnimationClip ( ToExport [ 0 ] ) . Key
462
+ : ModelExporter . GetGameObject ( ToExport [ 0 ] ) ;
463
+ }
414
464
}
415
465
416
466
protected override bool DisableTransferAnim {
@@ -431,8 +481,8 @@ protected bool IsTimelineAnim {
431
481
m_previousInclude = ExportSettings . instance . exportModelSettings . info . ModelAnimIncludeOption ;
432
482
ExportSettings . instance . exportModelSettings . info . SetModelAnimIncludeOption ( ExportSettings . Include . Anim ) ;
433
483
}
434
- if ( m_innerEditor ) {
435
- var exportModelSettingsEditor = m_innerEditor as ExportModelSettingsEditor ;
484
+ if ( InnerEditor ) {
485
+ var exportModelSettingsEditor = InnerEditor as ExportModelSettingsEditor ;
436
486
if ( exportModelSettingsEditor ) {
437
487
exportModelSettingsEditor . DisableIncludeDropdown ( m_isTimelineAnim ) ;
438
488
}
@@ -446,8 +496,8 @@ protected bool SingleHierarchyExport {
446
496
set {
447
497
m_singleHierarchyExport = value ;
448
498
449
- if ( m_innerEditor ) {
450
- var exportModelSettingsEditor = m_innerEditor as ExportModelSettingsEditor ;
499
+ if ( InnerEditor ) {
500
+ var exportModelSettingsEditor = InnerEditor as ExportModelSettingsEditor ;
451
501
if ( exportModelSettingsEditor ) {
452
502
exportModelSettingsEditor . SetIsSingleHierarchy ( m_singleHierarchyExport ) ;
453
503
}
@@ -469,7 +519,7 @@ public static void Init (IEnumerable<UnityEngine.Object> toExport, string filena
469
519
470
520
int numObjects = window . SetGameObjectsToExport ( toExport ) ;
471
521
if ( string . IsNullOrEmpty ( filename ) ) {
472
- filename = window . GetFilenameFromObjects ( ) ;
522
+ filename = window . DefaultFilename ;
473
523
}
474
524
window . InitializeWindow ( filename ) ;
475
525
window . SingleHierarchyExport = ( numObjects == 1 ) ;
@@ -486,7 +536,7 @@ protected int SetGameObjectsToExport(IEnumerable<UnityEngine.Object> toExport){
486
536
// if only one object selected, set transfer source/dest to this object
487
537
if ( ToExport . Length == 1 || ( IsTimelineAnim && ToExport . Length > 0 ) )
488
538
{
489
- GameObject go = GetGameObject ( ) ;
539
+ GameObject go = FirstGameObjectToExport ;
490
540
if ( go )
491
541
{
492
542
TransferAnimationSource = go . transform ;
@@ -502,21 +552,27 @@ protected int SetGameObjectsToExport(IEnumerable<UnityEngine.Object> toExport){
502
552
/// </summary>
503
553
/// <returns>The object's name if one object selected, "Untitled" if multiple
504
554
/// objects selected for export.</returns>
505
- protected string GetFilenameFromObjects ( ) {
506
- var filename = "" ;
507
- if ( ToExport . Length == 1 ) {
508
- filename = ToExport [ 0 ] . name ;
509
- } else {
510
- filename = "Untitled" ;
555
+ protected string DefaultFilename {
556
+ get
557
+ {
558
+ var filename = "" ;
559
+ if ( ToExport . Length == 1 )
560
+ {
561
+ filename = ToExport [ 0 ] . name ;
562
+ }
563
+ else
564
+ {
565
+ filename = "Untitled" ;
566
+ }
567
+ return filename ;
511
568
}
512
- return filename ;
513
569
}
514
570
515
571
protected override void OnEnable ( )
516
572
{
517
573
base . OnEnable ( ) ;
518
- if ( ! m_innerEditor ) {
519
- m_innerEditor = UnityEditor . Editor . CreateEditor ( ExportSettings . instance . exportModelSettings ) ;
574
+ if ( ! InnerEditor ) {
575
+ InnerEditor = UnityEditor . Editor . CreateEditor ( ExportSettings . instance . exportModelSettings ) ;
520
576
this . SingleHierarchyExport = m_singleHierarchyExport ;
521
577
this . IsTimelineAnim = m_isTimelineAnim ;
522
578
}
@@ -540,12 +596,12 @@ protected virtual void RestoreSettings()
540
596
541
597
542
598
protected override bool Export ( ) {
543
- if ( string . IsNullOrEmpty ( m_exportFileName ) ) {
599
+ if ( string . IsNullOrEmpty ( ExportFileName ) ) {
544
600
Debug . LogError ( "FbxExporter: Please specify an fbx filename" ) ;
545
601
return false ;
546
602
}
547
603
var folderPath = ExportSettings . GetFbxAbsoluteSavePath ( ) ;
548
- var filePath = System . IO . Path . Combine ( folderPath , m_exportFileName + ".fbx" ) ;
604
+ var filePath = System . IO . Path . Combine ( folderPath , ExportFileName + ".fbx" ) ;
549
605
550
606
if ( ! OverwriteExistingFile ( filePath ) ) {
551
607
return false ;
0 commit comments