Skip to content

Commit 5374b48

Browse files
committed
move transfer anim source/dest to abstract class
- avoid as much duplicate code as possible
1 parent a1a5e30 commit 5374b48

File tree

2 files changed

+65
-76
lines changed

2 files changed

+65
-76
lines changed

Assets/FbxExporters/Editor/ConvertToPrefabEditorWindow.cs

Lines changed: 17 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,10 @@ public class ConvertToPrefabEditorWindow : ExportOptionsEditorWindow
1515
protected override GUIContent WindowTitle { get { return new GUIContent ("Convert Options"); }}
1616
protected override float MinWindowHeight { get { return 280; } } // determined by trial and error
1717
protected override string ExportButtonName { get { return "Convert"; } }
18-
private GameObject[] m_toConvert;
1918
private string m_prefabFileName = "";
2019

2120
private float m_prefabExtLabelWidth;
2221

23-
protected override Transform TransferAnimationSource {
24-
get {
25-
return ExportSettings.instance.convertToPrefabSettings.info.AnimationSource;
26-
}
27-
set {
28-
var selectedGO = ModelExporter.GetGameObject(m_toConvert[0]);
29-
if (!TransferAnimationSourceIsValid (value, selectedGO)) {
30-
return;
31-
}
32-
ExportSettings.instance.convertToPrefabSettings.info.SetAnimationSource (value);
33-
}
34-
}
35-
36-
protected override Transform TransferAnimationDest {
37-
get {
38-
return ExportSettings.instance.convertToPrefabSettings.info.AnimationDest;
39-
}
40-
set {
41-
var selectedGO = ModelExporter.GetGameObject(m_toConvert[0]);
42-
if (!TransferAnimationDestIsValid (value, selectedGO)) {
43-
return;
44-
}
45-
ExportSettings.instance.convertToPrefabSettings.info.SetAnimationDest (value);
46-
}
47-
}
48-
4922
public static void Init (IEnumerable<GameObject> toConvert)
5023
{
5124
ConvertToPrefabEditorWindow window = CreateWindow<ConvertToPrefabEditorWindow> ();
@@ -55,22 +28,22 @@ public static void Init (IEnumerable<GameObject> toConvert)
5528
}
5629

5730
protected void SetGameObjectsToConvert(IEnumerable<GameObject> toConvert){
58-
m_toConvert = toConvert.OrderBy (go => go.name).ToArray ();
31+
ToExport = toConvert.OrderBy (go => go.name).ToArray ();
5932

60-
if (m_toConvert.Length == 1) {
61-
m_prefabFileName = m_toConvert [0].name;
33+
if (ToExport.Length == 1) {
34+
m_prefabFileName = ToExport [0].name;
6235

6336
// if only one object selected, set transfer source/dest to this object
64-
var go = ModelExporter.GetGameObject (m_toConvert [0]);
37+
var go = ModelExporter.GetGameObject (ToExport [0]);
6538
if (go) {
6639
TransferAnimationSource = go.transform;
6740
TransferAnimationDest = go.transform;
6841
}
69-
} else if (m_toConvert.Length > 1) {
42+
} else if (ToExport.Length > 1) {
7043
m_prefabFileName = "(automatic)";
7144
}
7245

73-
DisableTransferAnim = DisableNameSelection = m_toConvert.Length > 1;
46+
DisableTransferAnim = DisableNameSelection = ToExport.Length > 1;
7447

7548
this.SetFilename (m_prefabFileName);
7649
}
@@ -97,25 +70,32 @@ protected override void Export ()
9770
return;
9871
}
9972

100-
if (m_toConvert == null) {
73+
if (ToExport == null) {
10174
Debug.LogError ("FbxExporter: missing object for conversion");
10275
return;
10376
}
10477

105-
if (m_toConvert.Length == 1) {
78+
if (ToExport.Length == 1) {
79+
var go = ModelExporter.GetGameObject (ToExport [0]);
10680
ConvertToModel.Convert (
107-
m_toConvert[0], fbxFullPath: fbxPath, prefabFullPath: prefabPath, exportOptions: ExportSettings.instance.convertToPrefabSettings.info
81+
go, fbxFullPath: fbxPath, prefabFullPath: prefabPath, exportOptions: ExportSettings.instance.convertToPrefabSettings.info
10882
);
10983
return;
11084
}
11185

112-
foreach (var go in m_toConvert) {
86+
foreach (var obj in ToExport) {
87+
var go = ModelExporter.GetGameObject (obj);
11388
ConvertToModel.Convert (
11489
go, fbxDirectoryFullPath: fbxDirPath, prefabDirectoryFullPath: prefabDirPath, exportOptions: ExportSettings.instance.convertToPrefabSettings.info
11590
);
11691
}
11792
}
11893

94+
protected override ExportOptionsSettingsSerializeBase SettingsObject
95+
{
96+
get { return ExportSettings.instance.convertToPrefabSettings.info; }
97+
}
98+
11999
protected override void ShowPresetReceiver ()
120100
{
121101
ShowPresetReceiver (ExportSettings.instance.convertToPrefabSettings);

Assets/FbxExporters/Editor/ExportModelEditorWindow.cs

Lines changed: 48 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ public abstract class ExportOptionsEditorWindow : EditorWindow
4646
protected GUIStyle m_fbxExtLabelStyle;
4747
protected float m_fbxExtLabelWidth;
4848

49+
protected abstract EditorTools.ExportOptionsSettingsSerializeBase SettingsObject { get; }
50+
51+
private UnityEngine.Object[] m_toExport;
52+
protected UnityEngine.Object[] ToExport {
53+
get { return m_toExport; }
54+
set { m_toExport = value; }
55+
}
56+
4957
protected virtual void OnEnable(){
5058
InitializeReceiver ();
5159
m_showOptions = true;
@@ -120,8 +128,31 @@ protected void ShowPresetReceiver(UnityEngine.Object target){
120128
UnityEditor.Presets.PresetSelector.ShowSelector(target, null, true, m_receiver);
121129
}
122130

123-
protected abstract Transform TransferAnimationSource { get; set; }
124-
protected abstract Transform TransferAnimationDest { get; set; }
131+
protected Transform TransferAnimationSource {
132+
get {
133+
return SettingsObject.AnimationSource;
134+
}
135+
set {
136+
var selectedGO = ModelExporter.GetGameObject(ToExport[0]);
137+
if (!TransferAnimationSourceIsValid (value, selectedGO)) {
138+
return;
139+
}
140+
SettingsObject.SetAnimationSource (value);
141+
}
142+
}
143+
144+
protected Transform TransferAnimationDest {
145+
get {
146+
return SettingsObject.AnimationDest;
147+
}
148+
set {
149+
var selectedGO = ModelExporter.GetGameObject(ToExport[0]);
150+
if (!TransferAnimationDestIsValid (value, selectedGO)) {
151+
return;
152+
}
153+
SettingsObject.SetAnimationDest (value);
154+
}
155+
}
125156

126157
//-------Helper functions for determining if Animation source and dest are valid---------
127158

@@ -153,7 +184,7 @@ protected bool IsInSameHierarchy(Transform t1, Transform t2){
153184
}
154185

155186

156-
protected virtual bool TransferAnimationSourceIsValid(Transform newValue, GameObject selectedGO){
187+
protected bool TransferAnimationSourceIsValid(Transform newValue, GameObject selectedGO){
157188
if (!newValue) {
158189
return true;
159190
}
@@ -171,7 +202,7 @@ protected virtual bool TransferAnimationSourceIsValid(Transform newValue, GameOb
171202
return true;
172203
}
173204

174-
protected virtual bool TransferAnimationDestIsValid(Transform newValue, GameObject selectedGO){
205+
protected bool TransferAnimationDestIsValid(Transform newValue, GameObject selectedGO){
175206
if (!newValue) {
176207
return true;
177208
}
@@ -336,7 +367,6 @@ protected bool OverwriteExistingFile(string filePath){
336367
public class ExportModelEditorWindow : ExportOptionsEditorWindow
337368
{
338369
protected override float MinWindowHeight { get { return 260; } }
339-
private UnityEngine.Object[] m_toExport;
340370

341371
private bool m_isTimelineAnim = false;
342372
protected bool IsTimelineAnim {
@@ -380,30 +410,9 @@ protected bool IsPlayableDirector {
380410
}
381411
}
382412

383-
protected override Transform TransferAnimationSource {
384-
get {
385-
return ExportSettings.instance.exportModelSettings.info.AnimationSource;
386-
}
387-
set {
388-
var selectedGO = ModelExporter.GetGameObject(m_toExport[0]);
389-
if (!TransferAnimationSourceIsValid (value, selectedGO)) {
390-
return;
391-
}
392-
ExportSettings.instance.exportModelSettings.info.SetAnimationSource (value);
393-
}
394-
}
395-
396-
protected override Transform TransferAnimationDest {
397-
get {
398-
return ExportSettings.instance.exportModelSettings.info.AnimationDest;
399-
}
400-
set {
401-
var selectedGO = ModelExporter.GetGameObject(m_toExport[0]);
402-
if (!TransferAnimationDestIsValid (value, selectedGO)) {
403-
return;
404-
}
405-
ExportSettings.instance.exportModelSettings.info.SetAnimationDest (value);
406-
}
413+
protected override ExportOptionsSettingsSerializeBase SettingsObject
414+
{
415+
get { return ExportSettings.instance.exportModelSettings.info; }
407416
}
408417

409418
public static void Init (IEnumerable<UnityEngine.Object> toExport, string filename = "", bool isTimelineAnim = false, bool isPlayableDirector = false)
@@ -421,19 +430,19 @@ public static void Init (IEnumerable<UnityEngine.Object> toExport, string filena
421430
}
422431

423432
protected int SetGameObjectsToExport(IEnumerable<UnityEngine.Object> toExport){
424-
m_toExport = toExport.ToArray ();
433+
ToExport = toExport.ToArray ();
425434

426435
// if only one object selected, set transfer source/dest to this object
427-
if (m_toExport.Length == 1) {
428-
var go = ModelExporter.GetGameObject (m_toExport [0]);
436+
if (ToExport.Length == 1) {
437+
var go = ModelExporter.GetGameObject (ToExport [0]);
429438
if (go) {
430439
TransferAnimationSource = go.transform;
431440
TransferAnimationDest = go.transform;
432441
}
433442
}
434-
DisableTransferAnim = m_toExport.Length > 1;
443+
DisableTransferAnim = ToExport.Length > 1;
435444

436-
return m_toExport.Length;
445+
return ToExport.Length;
437446
}
438447

439448
/// <summary>
@@ -443,8 +452,8 @@ protected int SetGameObjectsToExport(IEnumerable<UnityEngine.Object> toExport){
443452
/// objects selected for export.</returns>
444453
protected string GetFilenameFromObjects(){
445454
var filename = "";
446-
if (m_toExport.Length == 1) {
447-
filename = m_toExport [0].name;
455+
if (ToExport.Length == 1) {
456+
filename = ToExport [0].name;
448457
} else {
449458
filename = "Untitled";
450459
}
@@ -470,20 +479,20 @@ protected override void Export(){
470479
}
471480

472481
if (IsPlayableDirector) {
473-
foreach (var obj in m_toExport) {
482+
foreach (var obj in ToExport) {
474483
var go = ModelExporter.GetGameObject (obj);
475484
if (!go) {
476485
continue;
477486
}
478-
ModelExporter.ExportAllTimelineClips (go, folderPath, ExportSettings.instance.exportModelSettings.info);
487+
ModelExporter.ExportAllTimelineClips (go, folderPath, SettingsObject);
479488
}
480489
// refresh the asset database so that the file appears in the
481490
// asset folder view.
482491
AssetDatabase.Refresh ();
483492
return;
484493
}
485494

486-
if (ModelExporter.ExportObjects (filePath, m_toExport, ExportSettings.instance.exportModelSettings.info, timelineAnim: m_isTimelineAnim) != null) {
495+
if (ModelExporter.ExportObjects (filePath, ToExport, SettingsObject, timelineAnim: m_isTimelineAnim) != null) {
487496
// refresh the asset database so that the file appears in the
488497
// asset folder view.
489498
AssetDatabase.Refresh ();

0 commit comments

Comments
 (0)