Skip to content

Commit a006aeb

Browse files
committed
fix ExportModelEditorWindow warnings
- make some variables and functions into properties
1 parent 317857c commit a006aeb

File tree

2 files changed

+128
-72
lines changed

2 files changed

+128
-72
lines changed

Packages/com.unity.formats.fbx/Editor/Scripts/ConvertToPrefabEditorWindow.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ protected void SetGameObjectsToConvert(IEnumerable<GameObject> toConvert)
8484
protected override void OnEnable()
8585
{
8686
base.OnEnable();
87-
if (!m_innerEditor)
87+
if (!InnerEditor)
8888
{
89-
m_innerEditor = UnityEditor.Editor.CreateEditor(ExportSettings.instance.convertToPrefabSettings);
89+
InnerEditor = UnityEditor.Editor.CreateEditor(ExportSettings.instance.convertToPrefabSettings);
9090
}
91-
m_prefabExtLabelWidth = m_fbxExtLabelStyle.CalcSize(new GUIContent(".prefab")).x;
91+
m_prefabExtLabelWidth = FbxExtLabelStyle.CalcSize(new GUIContent(".prefab")).x;
9292
}
9393

9494
protected bool ExportSetContainsAnimation()
@@ -106,7 +106,7 @@ protected bool ExportSetContainsAnimation()
106106

107107
protected override bool Export()
108108
{
109-
if (string.IsNullOrEmpty(m_exportFileName))
109+
if (string.IsNullOrEmpty(ExportFileName))
110110
{
111111
Debug.LogError("FbxExporter: Please specify an fbx filename");
112112
return false;
@@ -119,7 +119,7 @@ protected override bool Export()
119119
}
120120

121121
var fbxDirPath = ExportSettings.GetFbxAbsoluteSavePath();
122-
var fbxPath = System.IO.Path.Combine(fbxDirPath, m_exportFileName + ".fbx");
122+
var fbxPath = System.IO.Path.Combine(fbxDirPath, ExportFileName + ".fbx");
123123

124124
var prefabDirPath = ExportSettings.GetPrefabAbsoluteSavePath();
125125
var prefabPath = System.IO.Path.Combine(prefabDirPath, m_prefabFileName + ".prefab");
@@ -215,11 +215,11 @@ protected override void CreateCustomUI()
215215
EditorGUILayout.BeginHorizontal(EditorStyles.textField, GUILayout.Height(EditorGUIUtility.singleLineHeight));
216216
EditorGUI.indentLevel--;
217217
// continually resize to contents
218-
var textFieldSize = m_nameTextFieldStyle.CalcSize(new GUIContent(m_prefabFileName));
219-
m_prefabFileName = EditorGUILayout.TextField(m_prefabFileName, m_nameTextFieldStyle, GUILayout.Width(textFieldSize.x + 5), GUILayout.MinWidth(5));
218+
var textFieldSize = NameTextFieldStyle.CalcSize(new GUIContent(m_prefabFileName));
219+
m_prefabFileName = EditorGUILayout.TextField(m_prefabFileName, NameTextFieldStyle, GUILayout.Width(textFieldSize.x + 5), GUILayout.MinWidth(5));
220220
m_prefabFileName = ModelExporter.ConvertToValidFilename(m_prefabFileName);
221221

222-
EditorGUILayout.LabelField("<color=#808080ff>.prefab</color>", m_fbxExtLabelStyle, GUILayout.Width(m_prefabExtLabelWidth));
222+
EditorGUILayout.LabelField("<color=#808080ff>.prefab</color>", FbxExtLabelStyle, GUILayout.Width(m_prefabExtLabelWidth));
223223
EditorGUI.indentLevel++;
224224

225225
EditorGUILayout.EndHorizontal();
@@ -267,7 +267,7 @@ protected override void CreateCustomUI()
267267
GUILayout.EndHorizontal();
268268
}
269269

270-
protected override void DontShowDialogUI()
270+
protected override void DoNotShowDialogUI()
271271
{
272272
EditorGUI.indentLevel--;
273273
ExportSettings.instance.showConvertToPrefabDialog = !EditorGUILayout.Toggle(

Packages/com.unity.formats.fbx/Editor/Scripts/ExportModelEditorWindow.cs

Lines changed: 119 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,77 @@ public abstract class ExportOptionsEditorWindow : EditorWindow
2323

2424
protected virtual GUIContent WindowTitle { get { return new GUIContent (DefaultWindowTitle); } }
2525

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+
}
2732

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+
}
3146
#endif
3247
private static GUIContent presetIcon { get { return EditorGUIUtility.IconContent ("Preset.Context"); }}
3348
private static GUIStyle presetIconButton { get { return new GUIStyle("IconButton"); }}
3449

3550
private bool m_showOptions;
3651

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+
}
4097

4198
protected abstract bool DisableTransferAnim { get; }
4299
protected abstract bool DisableNameSelection { get; }
@@ -55,18 +112,6 @@ protected virtual void OnEnable(){
55112
#endif
56113
m_showOptions = true;
57114
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;
70115
}
71116

72117
protected static T CreateWindow<T>() where T : EditorWindow {
@@ -80,24 +125,24 @@ protected virtual void InitializeWindow(string filename = ""){
80125

81126
#if UNITY_2018_1_OR_NEWER
82127
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;
89134
}
90135
}
91136
#endif
92137

93-
public void SetFilename(string filename){
138+
internal void SetFilename(string filename){
94139
// remove .fbx from end of filename
95140
int extIndex = filename.LastIndexOf(".fbx");
96141
if (extIndex < 0) {
97-
m_exportFileName = filename;
142+
ExportFileName = filename;
98143
return;
99144
}
100-
m_exportFileName = filename.Remove(extIndex);
145+
ExportFileName = filename.Remove(extIndex);
101146
}
102147

103148
public void SaveExportSettings()
@@ -124,9 +169,9 @@ protected virtual void CreateCustomUI(){}
124169

125170
protected void ShowPresetReceiver(UnityEngine.Object target){
126171
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);
130175
}
131176
#endif
132177

@@ -184,9 +229,11 @@ protected bool IsInSameHierarchy(Transform t1, Transform t2){
184229
}
185230

186231

187-
protected virtual GameObject GetGameObject()
232+
protected virtual GameObject FirstGameObjectToExport
188233
{
189-
return ModelExporter.GetGameObject ( ToExport [0] );
234+
get {
235+
return ModelExporter.GetGameObject(ToExport[0]);
236+
}
190237
}
191238

192239
protected bool TransferAnimationSourceIsValid(Transform newValue){
@@ -199,7 +246,7 @@ protected bool TransferAnimationSourceIsValid(Transform newValue){
199246
return false;
200247
}
201248

202-
var selectedGO = GetGameObject();
249+
var selectedGO = FirstGameObjectToExport;
203250

204251
// source must be ancestor to dest
205252
if (TransferAnimationDest && !IsAncestor(newValue, TransferAnimationDest)) {
@@ -224,7 +271,7 @@ protected bool TransferAnimationDestIsValid(Transform newValue){
224271
return false;
225272
}
226273

227-
var selectedGO = GetGameObject();
274+
var selectedGO = FirstGameObjectToExport;
228275

229276
// source must be ancestor to dest
230277
if (TransferAnimationSource && !IsAncestor(TransferAnimationSource, newValue)) {
@@ -242,7 +289,7 @@ protected bool TransferAnimationDestIsValid(Transform newValue){
242289
/// <summary>
243290
/// Add UI to turn the dialog off next time the user exports
244291
/// </summary>
245-
protected virtual void DontShowDialogUI() { }
292+
protected virtual void DoNotShowDialogUI() { }
246293

247294
// -------------------------------------------------------------------------------------
248295

@@ -277,11 +324,11 @@ protected void OnGUI ()
277324
EditorGUILayout.BeginHorizontal(EditorStyles.textField, GUILayout.Height(EditorGUIUtility.singleLineHeight));
278325
EditorGUI.indentLevel--;
279326
// 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);
283330

284-
EditorGUILayout.LabelField ("<color=#808080ff>.fbx</color>", m_fbxExtLabelStyle, GUILayout.Width(m_fbxExtLabelWidth));
331+
EditorGUILayout.LabelField ("<color=#808080ff>.fbx</color>", FbxExtLabelStyle, GUILayout.Width(FbxExtLabelWidth));
285332
EditorGUI.indentLevel++;
286333

287334
EditorGUILayout.EndHorizontal();
@@ -350,13 +397,13 @@ protected void OnGUI ()
350397
m_showOptions = EditorGUILayout.Foldout (m_showOptions, "Options");
351398
EditorGUI.indentLevel++;
352399
if (m_showOptions) {
353-
m_innerEditor.OnInspectorGUI ();
400+
InnerEditor.OnInspectorGUI ();
354401
}
355402

356403
GUILayout.FlexibleSpace ();
357404

358405
GUILayout.BeginHorizontal ();
359-
DontShowDialogUI();
406+
DoNotShowDialogUI();
360407
GUILayout.FlexibleSpace ();
361408
if (GUILayout.Button ("Cancel", GUILayout.Width(ExportButtonWidth))) {
362409
this.Close ();
@@ -406,11 +453,14 @@ protected override bool DisableNameSelection {
406453
}
407454
}
408455

409-
protected override GameObject GetGameObject()
456+
protected override GameObject FirstGameObjectToExport
410457
{
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+
}
414464
}
415465

416466
protected override bool DisableTransferAnim {
@@ -431,8 +481,8 @@ protected bool IsTimelineAnim {
431481
m_previousInclude = ExportSettings.instance.exportModelSettings.info.ModelAnimIncludeOption;
432482
ExportSettings.instance.exportModelSettings.info.SetModelAnimIncludeOption(ExportSettings.Include.Anim);
433483
}
434-
if (m_innerEditor) {
435-
var exportModelSettingsEditor = m_innerEditor as ExportModelSettingsEditor;
484+
if (InnerEditor) {
485+
var exportModelSettingsEditor = InnerEditor as ExportModelSettingsEditor;
436486
if (exportModelSettingsEditor) {
437487
exportModelSettingsEditor.DisableIncludeDropdown(m_isTimelineAnim);
438488
}
@@ -446,8 +496,8 @@ protected bool SingleHierarchyExport {
446496
set {
447497
m_singleHierarchyExport = value;
448498

449-
if (m_innerEditor) {
450-
var exportModelSettingsEditor = m_innerEditor as ExportModelSettingsEditor;
499+
if (InnerEditor) {
500+
var exportModelSettingsEditor = InnerEditor as ExportModelSettingsEditor;
451501
if (exportModelSettingsEditor) {
452502
exportModelSettingsEditor.SetIsSingleHierarchy (m_singleHierarchyExport);
453503
}
@@ -469,7 +519,7 @@ public static void Init (IEnumerable<UnityEngine.Object> toExport, string filena
469519

470520
int numObjects = window.SetGameObjectsToExport (toExport);
471521
if (string.IsNullOrEmpty (filename)) {
472-
filename = window.GetFilenameFromObjects ();
522+
filename = window.DefaultFilename;
473523
}
474524
window.InitializeWindow (filename);
475525
window.SingleHierarchyExport = (numObjects == 1);
@@ -486,7 +536,7 @@ protected int SetGameObjectsToExport(IEnumerable<UnityEngine.Object> toExport){
486536
// if only one object selected, set transfer source/dest to this object
487537
if (ToExport.Length == 1 || (IsTimelineAnim && ToExport.Length > 0))
488538
{
489-
GameObject go = GetGameObject();
539+
GameObject go = FirstGameObjectToExport;
490540
if (go)
491541
{
492542
TransferAnimationSource = go.transform;
@@ -502,21 +552,27 @@ protected int SetGameObjectsToExport(IEnumerable<UnityEngine.Object> toExport){
502552
/// </summary>
503553
/// <returns>The object's name if one object selected, "Untitled" if multiple
504554
/// 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;
511568
}
512-
return filename;
513569
}
514570

515571
protected override void OnEnable ()
516572
{
517573
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);
520576
this.SingleHierarchyExport = m_singleHierarchyExport;
521577
this.IsTimelineAnim = m_isTimelineAnim;
522578
}
@@ -540,12 +596,12 @@ protected virtual void RestoreSettings()
540596

541597

542598
protected override bool Export(){
543-
if (string.IsNullOrEmpty (m_exportFileName)) {
599+
if (string.IsNullOrEmpty (ExportFileName)) {
544600
Debug.LogError ("FbxExporter: Please specify an fbx filename");
545601
return false;
546602
}
547603
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");
549605

550606
if (!OverwriteExistingFile (filePath)) {
551607
return false;

0 commit comments

Comments
 (0)