Skip to content

Commit bf148ed

Browse files
committed
use properties instead of functions
1 parent 82d5894 commit bf148ed

File tree

2 files changed

+64
-52
lines changed

2 files changed

+64
-52
lines changed

Assets/FbxExporters/Editor/ConvertToPrefabEditorWindow.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ protected void SetGameObjectsToConvert(IEnumerable<GameObject> toConvert){
6161
} else if (m_toConvert.Length > 1) {
6262
m_prefabFileName = "(automatic)";
6363
}
64+
65+
DisableTransferAnim = DisableNameSelection = m_toConvert.Length > 1;
66+
6467
this.SetFilename (m_prefabFileName);
6568
}
6669

@@ -105,11 +108,6 @@ protected override void Export ()
105108
}
106109
}
107110

108-
protected override bool DisableNameSelection ()
109-
{
110-
return m_toConvert.Length > 1;
111-
}
112-
113111
protected override void ShowPresetReceiver ()
114112
{
115113
ShowPresetReceiver (ExportSettings.instance.convertToPrefabSettings);
@@ -122,7 +120,7 @@ protected override void CreateCustomUI ()
122120
"Prefab Name:",
123121
"Filename to save prefab to."),GUILayout.Width(LabelWidth-TextFieldAlignOffset));
124122

125-
EditorGUI.BeginDisabledGroup (DisableNameSelection());
123+
EditorGUI.BeginDisabledGroup (DisableNameSelection);
126124
// Show the export name with an uneditable ".prefab" at the end
127125
//-------------------------------------
128126
EditorGUILayout.BeginVertical ();

Assets/FbxExporters/Editor/ExportModelEditorWindow.cs

Lines changed: 60 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ public abstract class ExportOptionsEditorWindow : EditorWindow
2828

2929
protected string m_exportFileName = "";
3030

31+
private bool m_disableTransferAnim = false;
32+
protected bool DisableTransferAnim { get { return m_disableTransferAnim; } set { m_disableTransferAnim = value; } }
33+
34+
private bool m_disableNameSelection = false;
35+
protected bool DisableNameSelection { get { return m_disableNameSelection; } set { m_disableNameSelection = value; } }
36+
3137
protected UnityEditor.Editor m_innerEditor;
3238
protected FbxExportPresetSelectorReceiver m_receiver;
3339

@@ -105,10 +111,6 @@ public void OnPresetSelectionChanged()
105111
/// </summary>
106112
protected virtual void CreateCustomUI(){}
107113

108-
protected virtual bool DisableNameSelection(){
109-
return false;
110-
}
111-
112114
protected abstract void ShowPresetReceiver ();
113115

114116
protected void ShowPresetReceiver(UnityEngine.Object target){
@@ -141,7 +143,7 @@ protected void OnGUI ()
141143
"Export Name:",
142144
"Filename to save model to."),GUILayout.Width(LabelWidth-TextFieldAlignOffset));
143145

144-
EditorGUI.BeginDisabledGroup (DisableNameSelection());
146+
EditorGUI.BeginDisabledGroup (DisableNameSelection);
145147
// Show the export name with an uneditable ".fbx" at the end
146148
//-------------------------------------
147149
EditorGUILayout.BeginVertical ();
@@ -202,15 +204,18 @@ protected void OnGUI ()
202204
CreateCustomUI();
203205

204206
EditorGUILayout.Space ();
207+
208+
EditorGUI.BeginDisabledGroup (DisableTransferAnim);
205209
EditorGUI.indentLevel--;
206210
GUILayout.BeginHorizontal();
207211
EditorGUILayout.LabelField(new GUIContent("Transfer Animation", "Select bone to transfer root motion animation to."), GUILayout.Width(LabelWidth - FieldOffset));
208212
GUILayout.EndHorizontal();
209213
EditorGUI.indentLevel++;
210214
TransferAnimationSource = EditorGUILayout.ObjectField ("Source", TransferAnimationSource, typeof(Transform), allowSceneObjects: true) as Transform;
211215
TransferAnimationDest = EditorGUILayout.ObjectField ("Destination", TransferAnimationDest, typeof(Transform), allowSceneObjects: true) as Transform;
212-
213216
EditorGUILayout.Space ();
217+
EditorGUI.EndDisabledGroup ();
218+
214219
EditorGUI.indentLevel--;
215220
m_showOptions = EditorGUILayout.Foldout (m_showOptions, "Options");
216221
EditorGUI.indentLevel++;
@@ -266,14 +271,55 @@ public class ExportModelEditorWindow : ExportOptionsEditorWindow
266271
private UnityEngine.Object[] m_toExport;
267272

268273
private bool m_isTimelineAnim = false;
274+
protected bool IsTimelineAnim {
275+
get { return m_isTimelineAnim; }
276+
set{
277+
m_isTimelineAnim = value;
278+
if (m_isTimelineAnim) {
279+
ExportSettings.instance.exportModelSettings.info.SetModelAnimIncludeOption(ExportSettings.Include.Anim);
280+
}
281+
if (m_innerEditor) {
282+
var exportModelSettingsEditor = m_innerEditor as ExportModelSettingsEditor;
283+
if (exportModelSettingsEditor) {
284+
exportModelSettingsEditor.DisableIncludeDropdown(m_isTimelineAnim);
285+
}
286+
}
287+
}
288+
}
289+
269290
private bool m_singleHierarchyExport = true;
291+
protected bool SingleHierarchyExport {
292+
get { return m_singleHierarchyExport; }
293+
set {
294+
m_singleHierarchyExport = value;
295+
296+
if (m_innerEditor) {
297+
var exportModelSettingsEditor = m_innerEditor as ExportModelSettingsEditor;
298+
if (exportModelSettingsEditor) {
299+
exportModelSettingsEditor.SetIsSingleHierarchy (m_singleHierarchyExport);
300+
}
301+
}
302+
}
303+
}
304+
270305
private bool m_isPlayableDirector = false;
306+
protected bool IsPlayableDirector {
307+
get { return m_isPlayableDirector; }
308+
set {
309+
m_isPlayableDirector = value;
310+
DisableNameSelection = m_isPlayableDirector;
311+
}
312+
}
271313

272314
protected override Transform TransferAnimationSource {
273315
get {
274316
return ExportSettings.instance.exportModelSettings.info.AnimationSource;
275317
}
276318
set {
319+
// source must be ancestor to dest
320+
321+
// must be in same hierarchy as selected GO
322+
277323
ExportSettings.instance.exportModelSettings.info.SetAnimationSource (value);
278324
}
279325
}
@@ -295,9 +341,9 @@ public static void Init (IEnumerable<UnityEngine.Object> toExport, string filena
295341
filename = window.GetFilenameFromObjects ();
296342
}
297343
window.InitializeWindow (filename);
298-
window.SetAnimationExportType (isTimelineAnim);
299-
window.SetSingleHierarchyExport (numObjects == 1);
300-
window.SetIsPlayableDirector (isPlayableDirector);
344+
window.IsTimelineAnim = isTimelineAnim;
345+
window.SingleHierarchyExport = (numObjects == 1);
346+
window.IsPlayableDirector = isPlayableDirector;
301347
window.Show ();
302348
}
303349

@@ -311,39 +357,12 @@ protected int SetGameObjectsToExport(IEnumerable<UnityEngine.Object> toExport){
311357
TransferAnimationSource = go.transform;
312358
TransferAnimationDest = go.transform;
313359
}
314-
}
360+
}
361+
DisableTransferAnim = m_toExport.Length > 1;
315362

316363
return m_toExport.Length;
317364
}
318365

319-
private void SetAnimationExportType(bool isTimelineAnim){
320-
m_isTimelineAnim = isTimelineAnim;
321-
if (m_isTimelineAnim) {
322-
ExportSettings.instance.exportModelSettings.info.SetModelAnimIncludeOption(ExportSettings.Include.Anim);
323-
}
324-
if (m_innerEditor) {
325-
var exportModelSettingsEditor = m_innerEditor as ExportModelSettingsEditor;
326-
if (exportModelSettingsEditor) {
327-
exportModelSettingsEditor.DisableIncludeDropdown(m_isTimelineAnim);
328-
}
329-
}
330-
}
331-
332-
private void SetSingleHierarchyExport(bool singleHierarchy){
333-
m_singleHierarchyExport = singleHierarchy;
334-
335-
if (m_innerEditor) {
336-
var exportModelSettingsEditor = m_innerEditor as ExportModelSettingsEditor;
337-
if (exportModelSettingsEditor) {
338-
exportModelSettingsEditor.SetIsSingleHierarchy (m_singleHierarchyExport);
339-
}
340-
}
341-
}
342-
343-
private void SetIsPlayableDirector(bool isPlayableDirector){
344-
m_isPlayableDirector = isPlayableDirector;
345-
}
346-
347366
/// <summary>
348367
/// Gets the filename from objects to export.
349368
/// </summary>
@@ -364,16 +383,11 @@ protected override void OnEnable ()
364383
base.OnEnable ();
365384
if (!m_innerEditor) {
366385
m_innerEditor = UnityEditor.Editor.CreateEditor (ExportSettings.instance.exportModelSettings);
367-
this.SetSingleHierarchyExport (m_singleHierarchyExport);
368-
this.SetAnimationExportType (m_isTimelineAnim);
386+
this.SingleHierarchyExport = m_singleHierarchyExport;
387+
this.IsTimelineAnim = m_isTimelineAnim;
369388
}
370389
}
371390

372-
protected override bool DisableNameSelection ()
373-
{
374-
return m_isPlayableDirector;
375-
}
376-
377391
protected override void Export(){
378392
var folderPath = ExportSettings.GetFbxAbsoluteSavePath ();
379393
var filePath = System.IO.Path.Combine (folderPath, m_exportFileName + ".fbx");
@@ -382,7 +396,7 @@ protected override void Export(){
382396
return;
383397
}
384398

385-
if (m_isPlayableDirector) {
399+
if (IsPlayableDirector) {
386400
foreach (var obj in m_toExport) {
387401
var go = ModelExporter.GetGameObject (obj);
388402
if (!go) {

0 commit comments

Comments
 (0)