Skip to content

Commit 6f83fb2

Browse files
committed
refactor so export settings serialize gets passed to exporter
- so we don't risk creating multiple scriptableobjects that don't get garbage collected
1 parent 6b29736 commit 6f83fb2

11 files changed

+83
-74
lines changed

Assets/FbxExporters/Editor/ConvertToModel.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,7 @@ public static GameObject Convert (
156156
{
157157
var fbxActualPath = ModelExporter.ExportObject (
158158
fbxFullPath, toConvert,
159-
exportOptions != null ? exportOptions :
160-
(ScriptableObject.CreateInstance <EditorTools.ConvertToPrefabSettings> () as EditorTools.ConvertToPrefabSettings)
159+
exportOptions != null ? exportOptions : new EditorTools.ConvertToPrefabSettingsSerialize()
161160
);
162161
if (fbxActualPath != fbxFullPath) {
163162
throw new System.Exception ("Failed to convert " + toConvert.name);

Assets/FbxExporters/Editor/ConvertToPrefabEditorWindow.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,14 @@ protected override void Export ()
6565

6666
if (m_toConvert.Length == 1) {
6767
ConvertToModel.Convert (
68-
m_toConvert[0], fbxFullPath: fbxPath, prefabFullPath: prefabPath, exportOptions: ExportSettings.instance.convertToPrefabSettings
68+
m_toConvert[0], fbxFullPath: fbxPath, prefabFullPath: prefabPath, exportOptions: ExportSettings.instance.convertToPrefabSettings.info
6969
);
7070
return;
7171
}
7272

7373
foreach (var go in m_toConvert) {
7474
ConvertToModel.Convert (
75-
go, fbxDirectoryFullPath: fbxDirPath, prefabDirectoryFullPath: prefabDirPath, exportOptions: ExportSettings.instance.convertToPrefabSettings
75+
go, fbxDirectoryFullPath: fbxDirPath, prefabDirectoryFullPath: prefabDirPath, exportOptions: ExportSettings.instance.convertToPrefabSettings.info
7676
);
7777
}
7878
}

Assets/FbxExporters/Editor/ConvertToPrefabSettings.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public override void OnInspectorGUI ()
2424
GUILayout.BeginHorizontal();
2525
EditorGUILayout.LabelField(new GUIContent("Export Format", "Export the FBX file in the standard binary format." +
2626
" Select ASCII to export the FBX file in ASCII format."), GUILayout.Width(LabelWidth - FieldOffset));
27-
exportSettings.exportFormat = (ExportModelSettingsSerialize.ExportFormat)EditorGUILayout.Popup((int)exportSettings.exportFormat, exportFormatOptions);
27+
exportSettings.exportFormat = (ExportSettings.ExportFormat)EditorGUILayout.Popup((int)exportSettings.exportFormat, exportFormatOptions);
2828
GUILayout.EndHorizontal();
2929

3030
GUILayout.BeginHorizontal();
@@ -75,10 +75,14 @@ public override void OnInspectorGUI ()
7575
}
7676

7777
public class ConvertToPrefabSettings : ExportOptionsSettingsBase<ConvertToPrefabSettingsSerialize>
78-
{
79-
}
78+
{}
8079

8180
[System.Serializable]
8281
public class ConvertToPrefabSettingsSerialize : ExportOptionsSettingsSerializeBase
83-
{}
82+
{
83+
public override ExportSettings.Include ModelAnimIncludeOption { get { return ExportSettings.Include.ModelAndAnim; } set { } }
84+
public override ExportSettings.LODExportType LODExportType { get { return ExportSettings.LODExportType.All; } set { } }
85+
public override ExportSettings.ObjectPosition ObjectPosition { get { return ExportSettings.ObjectPosition.Reset; } set { } }
86+
public override bool ExportUnrendered { get { return true; } set { } }
87+
}
8488
}

Assets/FbxExporters/Editor/ExportModelEditorWindow.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ protected int SetGameObjectsToExport(IEnumerable<UnityEngine.Object> toExport){
278278
private void SetAnimationExportType(bool isTimelineAnim){
279279
m_isTimelineAnim = isTimelineAnim;
280280
if (m_isTimelineAnim) {
281-
ExportSettings.instance.exportModelSettings.SetModelAnimIncludeOption (ExportModelSettingsSerialize.Include.Anim);
281+
ExportSettings.instance.exportModelSettings.info.ModelAnimIncludeOption = ExportSettings.Include.Anim;
282282
}
283283
if (m_innerEditor) {
284284
var exportModelSettingsEditor = m_innerEditor as ExportModelSettingsEditor;
@@ -342,15 +342,15 @@ protected override void Export(){
342342
if (!go) {
343343
continue;
344344
}
345-
ModelExporter.ExportAllTimelineClips (go, folderPath, ExportSettings.instance.exportModelSettings);
345+
ModelExporter.ExportAllTimelineClips (go, folderPath, ExportSettings.instance.exportModelSettings.info);
346346
}
347347
// refresh the asset database so that the file appears in the
348348
// asset folder view.
349349
AssetDatabase.Refresh ();
350350
return;
351351
}
352352

353-
if (ModelExporter.ExportObjects (filePath, m_toExport, ExportSettings.instance.exportModelSettings, timelineAnim: m_isTimelineAnim) != null) {
353+
if (ModelExporter.ExportObjects (filePath, m_toExport, ExportSettings.instance.exportModelSettings.info, timelineAnim: m_isTimelineAnim) != null) {
354354
// refresh the asset database so that the file appears in the
355355
// asset folder view.
356356
AssetDatabase.Refresh ();

Assets/FbxExporters/Editor/ExportModelSettings.cs

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -41,29 +41,29 @@ public override void OnInspectorGUI ()
4141
GUILayout.BeginHorizontal();
4242
EditorGUILayout.LabelField(new GUIContent("Export Format", "Export the FBX file in the standard binary format." +
4343
" Select ASCII to export the FBX file in ASCII format."), GUILayout.Width(LabelWidth - FieldOffset));
44-
exportSettings.exportFormat = (ExportModelSettingsSerialize.ExportFormat)EditorGUILayout.Popup((int)exportSettings.exportFormat, exportFormatOptions);
44+
exportSettings.exportFormat = (ExportSettings.ExportFormat)EditorGUILayout.Popup((int)exportSettings.exportFormat, exportFormatOptions);
4545
GUILayout.EndHorizontal();
4646

4747
GUILayout.BeginHorizontal();
4848
EditorGUILayout.LabelField(new GUIContent("Include", "Select whether to export models, animation or both."), GUILayout.Width(LabelWidth - FieldOffset));
4949
EditorGUI.BeginDisabledGroup(disableIncludeDropdown);
50-
exportSettings.include = (ExportModelSettingsSerialize.Include)EditorGUILayout.Popup((int)exportSettings.include, includeOptions);
50+
exportSettings.include = (ExportSettings.Include)EditorGUILayout.Popup((int)exportSettings.include, includeOptions);
5151
EditorGUI.EndDisabledGroup ();
5252
GUILayout.EndHorizontal();
5353

5454
GUILayout.BeginHorizontal();
5555
EditorGUILayout.LabelField(new GUIContent("LOD level", "Select which LOD to export."), GUILayout.Width(LabelWidth - FieldOffset));
5656
// greyed out if animation only
57-
EditorGUI.BeginDisabledGroup(exportSettings.include == ExportModelSettingsSerialize.Include.Anim);
58-
exportSettings.lodLevel = (ExportModelSettingsSerialize.LODExportType)EditorGUILayout.Popup((int)exportSettings.lodLevel, lodOptions);
57+
EditorGUI.BeginDisabledGroup(exportSettings.include == ExportSettings.Include.Anim);
58+
exportSettings.lodLevel = (ExportSettings.LODExportType)EditorGUILayout.Popup((int)exportSettings.lodLevel, lodOptions);
5959
EditorGUI.EndDisabledGroup ();
6060
GUILayout.EndHorizontal();
6161

6262
GUILayout.BeginHorizontal();
6363
EditorGUILayout.LabelField(new GUIContent("Object(s) Position", "Select an option for exporting object's transform."), GUILayout.Width(LabelWidth - FieldOffset));
6464
// greyed out if animation only
65-
EditorGUI.BeginDisabledGroup(exportSettings.include == ExportModelSettingsSerialize.Include.Anim);
66-
exportSettings.objectPosition = (ExportModelSettingsSerialize.ObjectPosition)EditorGUILayout.Popup((int)exportSettings.objectPosition, objPositionOptions);
65+
EditorGUI.BeginDisabledGroup(exportSettings.include == ExportSettings.Include.Anim);
66+
exportSettings.objectPosition = (ExportSettings.ObjectPosition)EditorGUILayout.Popup((int)exportSettings.objectPosition, objPositionOptions);
6767
EditorGUI.EndDisabledGroup ();
6868
GUILayout.EndHorizontal();
6969

@@ -92,61 +92,59 @@ public override void OnInspectorGUI ()
9292
EditorGUILayout.LabelField(new GUIContent("Export Unrendered:",
9393
"If checked, meshes will be exported even if they don't have a Renderer component."), GUILayout.Width(LabelWidth - FieldOffset));
9494
// greyed out if animation only
95-
EditorGUI.BeginDisabledGroup(exportSettings.include == ExportModelSettingsSerialize.Include.Anim);
95+
EditorGUI.BeginDisabledGroup(exportSettings.include == ExportSettings.Include.Anim);
9696
exportSettings.exportUnrendered = EditorGUILayout.Toggle(exportSettings.exportUnrendered);
9797
EditorGUI.EndDisabledGroup ();
9898
GUILayout.EndHorizontal ();
9999
}
100100
}
101101

102102
public interface IExportOptions {
103-
ExportModelSettingsSerialize.ExportFormat GetExportFormat { get; set; }
104-
ExportModelSettingsSerialize.Include GetModelAnimIncludeOption { get; set; }
105-
ExportModelSettingsSerialize.LODExportType GetLODExportType { get; set; }
106-
ExportModelSettingsSerialize.ObjectPosition GetObjectPosition { get; set; }
103+
ExportSettings.ExportFormat ExportFormat { get; set; }
104+
ExportSettings.Include ModelAnimIncludeOption { get; set; }
105+
ExportSettings.LODExportType LODExportType { get; set; }
106+
ExportSettings.ObjectPosition ObjectPosition { get; set; }
107107
bool AnimateSkinnedMesh { get; set; }
108108
bool UseMayaCompatibleNames { get; set; }
109+
bool ExportUnrendered { get; set; }
109110
}
110111

111-
public abstract class ExportOptionsSettingsBase<T> : ScriptableObject, IExportOptions where T : ExportOptionsSettingsSerializeBase
112+
public abstract class ExportOptionsSettingsBase<T> : ScriptableObject where T : ExportOptionsSettingsSerializeBase, new()
112113
{
113114
public T info = new T();
114-
ExportModelSettingsSerialize.ExportFormat GetExportFormat { get { return info.exportFormat; } set { info.exportFormat = value; } }
115-
ExportModelSettingsSerialize.Include GetModelAnimIncludeOption { get; set; }
116-
ExportModelSettingsSerialize.LODExportType GetLODExportType { get; set; }
117-
ExportModelSettingsSerialize.ObjectPosition GetObjectPosition { get; set; }
118-
bool AnimateSkinnedMesh { get; set; }
119-
bool UseMayaCompatibleNames { get; set; }
120-
bool ExportUnrendered { get; set; }
121115
}
122116

123117
public class ExportModelSettings : ExportOptionsSettingsBase<ExportModelSettingsSerialize>
124-
{
125-
}
118+
{}
126119

127120
[System.Serializable]
128-
public abstract class ExportOptionsSettingsSerializeBase
121+
public abstract class ExportOptionsSettingsSerializeBase : IExportOptions
129122
{
130-
public ExportModelSettingsSerialize.ExportFormat exportFormat = ExportModelSettingsSerialize.ExportFormat.ASCII;
123+
public ExportSettings.ExportFormat exportFormat = ExportSettings.ExportFormat.ASCII;
131124
public string rootMotionTransfer = "";
132125
public bool animatedSkinnedMesh = true;
133126
public bool mayaCompatibleNaming = true;
127+
128+
public ExportSettings.ExportFormat ExportFormat { get { return exportFormat; } set { exportFormat = value; } }
129+
public bool AnimateSkinnedMesh { get { return animatedSkinnedMesh; } set { animatedSkinnedMesh = value; } }
130+
public bool UseMayaCompatibleNames { get { return mayaCompatibleNaming; } set { mayaCompatibleNaming = value; } }
131+
public abstract ExportSettings.Include ModelAnimIncludeOption { get; set; }
132+
public abstract ExportSettings.LODExportType LODExportType { get; set; }
133+
public abstract ExportSettings.ObjectPosition ObjectPosition { get; set; }
134+
public abstract bool ExportUnrendered { get; set; }
134135
}
135136

136137
[System.Serializable]
137138
public class ExportModelSettingsSerialize : ExportOptionsSettingsSerializeBase
138139
{
139-
public enum ExportFormat { ASCII = 0, Binary = 1}
140-
141-
public enum Include { Model = 0, Anim = 1, ModelAndAnim = 2 }
142-
143-
public enum ObjectPosition { LocalCentered = 0, WorldAbsolute = 1, Reset = 2 /* For convert to model only, no UI option*/}
144-
145-
public enum LODExportType { All = 0, Highest = 1, Lowest = 2 }
146-
147-
public Include include = Include.ModelAndAnim;
148-
public LODExportType lodLevel = LODExportType.All;
149-
public ObjectPosition objectPosition = ObjectPosition.LocalCentered;
140+
public ExportSettings.Include include = ExportSettings.Include.ModelAndAnim;
141+
public ExportSettings.LODExportType lodLevel = ExportSettings.LODExportType.All;
142+
public ExportSettings.ObjectPosition objectPosition = ExportSettings.ObjectPosition.LocalCentered;
150143
public bool exportUnrendered = true;
144+
145+
public override ExportSettings.Include ModelAnimIncludeOption { get { return include; } set { include = value; } }
146+
public override ExportSettings.LODExportType LODExportType { get { return lodLevel; } set { lodLevel = value; } }
147+
public override ExportSettings.ObjectPosition ObjectPosition { get { return objectPosition; } set { objectPosition = value; } }
148+
public override bool ExportUnrendered { get { return exportUnrendered; } set { exportUnrendered = value; } }
151149
}
152150
}

Assets/FbxExporters/Editor/FbxExportSettings.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,14 @@ private static string TryFindDCC(string dccPath, string ext, ExportSettings.DCCT
209209
[FilePath("ProjectSettings/FbxExportSettings.asset",FilePathAttribute.Location.ProjectFolder)]
210210
public class ExportSettings : ScriptableSingleton<ExportSettings>
211211
{
212+
public enum ExportFormat { ASCII = 0, Binary = 1}
213+
214+
public enum Include { Model = 0, Anim = 1, ModelAndAnim = 2 }
215+
216+
public enum ObjectPosition { LocalCentered = 0, WorldAbsolute = 1, Reset = 2 /* For convert to model only, no UI option*/}
217+
218+
public enum LODExportType { All = 0, Highest = 1, Lowest = 2 }
219+
212220
public const string kDefaultSavePath = ".";
213221
private static List<string> s_PreferenceList = new List<string>() {kMayaOptionName, kMayaLtOptionName, kMaxOptionName};
214222
//Any additional names require a space after the name

0 commit comments

Comments
 (0)