Skip to content

Commit 2edfd43

Browse files
committed
use new UI settings instead of fbx exporter settings
1 parent 898781f commit 2edfd43

File tree

7 files changed

+63
-66
lines changed

7 files changed

+63
-66
lines changed

Assets/FbxExporters/Editor/ConvertToModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public static GameObject Convert (
168168

169169
// Export to FBX. It refreshes the database.
170170
{
171-
var fbxActualPath = ModelExporter.ExportObject (fbxFullPath, toConvert, lodExportType: EditorTools.ExportSettings.LODExportType.All);
171+
var fbxActualPath = ModelExporter.ExportObject (fbxFullPath, toConvert, lodExportType: EditorTools.ExportModelSettingsSerialize.LODExportType.All);
172172
if (fbxActualPath != fbxFullPath) {
173173
throw new System.Exception ("Failed to convert " + toConvert.name);
174174
}

Assets/FbxExporters/Editor/ExportModelEditorWindow.cs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ void OnEnable(){
3232
InitializeReceiver ();
3333
showOptions = true;
3434
this.minSize = new Vector2 (SelectableLabelMinWidth + LabelWidth + BrowseButtonWidth, 220);
35+
36+
if (!innerEditor) {
37+
var ms = ExportSettings.instance.exportModelSettings;
38+
if (!ms) {
39+
ExportSettings.LoadSettings ();
40+
ms = ExportSettings.instance.exportModelSettings;
41+
}
42+
innerEditor = UnityEditor.Editor.CreateEditor (ms, editorType: typeof(ExportModelSettingsEditor));
43+
}
3544
}
3645

3746
public static void Init (string filename = "", ModelExporter.AnimationExportType exportType = ModelExporter.AnimationExportType.all)
@@ -108,12 +117,6 @@ void OnGUI ()
108117
"Relative path for saving Model Prefabs."),GUILayout.Width(LabelWidth - FieldOffset));
109118

110119
var pathLabels = ExportSettings.GetRelativeSavePaths();
111-
/*for(int i = 0; i < pathLabels.Length; i++){
112-
if (pathLabels[i] == ".") {
113-
pathLabels[i] = "(Assets root)";
114-
break; // no duplicate paths so safe to break
115-
}
116-
}*/
117120

118121
ExportSettings.instance.selectedExportModelPath = EditorGUILayout.Popup (ExportSettings.instance.selectedExportModelPath, pathLabels, GUILayout.MinWidth(SelectableLabelMinWidth));
119122

@@ -151,14 +154,6 @@ void OnGUI ()
151154
showOptions = EditorGUILayout.Foldout (showOptions, "Options");
152155
EditorGUI.indentLevel++;
153156
if (showOptions) {
154-
if (!innerEditor) {
155-
var ms = ExportSettings.instance.exportModelSettings;
156-
if (!ms) {
157-
ExportSettings.LoadSettings ();
158-
ms = ExportSettings.instance.exportModelSettings;
159-
}
160-
innerEditor = UnityEditor.Editor.CreateEditor (ms, editorType: typeof(ExportModelSettingsEditor));
161-
}
162157
innerEditor.OnInspectorGUI ();
163158
}
164159

@@ -192,7 +187,7 @@ void OnGUI ()
192187
}
193188
}
194189

195-
if (ModelExporter.ExportObjects (filePath, exportType: m_animExportType, lodExportType: ExportSettings.instance.lodExportType) != null) {
190+
if (ModelExporter.ExportObjects (filePath, exportType: m_animExportType, lodExportType: ExportSettings.GetLODExportType()) != null) {
196191
// refresh the asset database so that the file appears in the
197192
// asset folder view.
198193
AssetDatabase.Refresh ();

Assets/FbxExporters/Editor/ExportModelSettings.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public override void OnInspectorGUI ()
3030
EditorGUI.BeginDisabledGroup(exportSettings.include == ExportModelSettingsSerialize.Include.Anim);
3131
GUILayout.BeginHorizontal();
3232
EditorGUILayout.LabelField(new GUIContent("LOD level", "Select which LOD to export."), GUILayout.Width(LabelWidth - FieldOffset));
33-
exportSettings.lodLevel = (ExportSettings.LODExportType)EditorGUILayout.Popup((int)exportSettings.lodLevel, new string[]{"All", "Highest", "Lowest"});
33+
exportSettings.lodLevel = (ExportModelSettingsSerialize.LODExportType)EditorGUILayout.Popup((int)exportSettings.lodLevel, new string[]{"All", "Highest", "Lowest"});
3434
GUILayout.EndHorizontal();
3535

3636
GUILayout.BeginHorizontal();
@@ -39,12 +39,15 @@ public override void OnInspectorGUI ()
3939
GUILayout.EndHorizontal();
4040
EditorGUI.EndDisabledGroup ();
4141

42+
// TODO: add implementation for these options, grey out in the meantime
43+
EditorGUI.BeginDisabledGroup (true);
4244
GUILayout.BeginHorizontal();
4345
EditorGUILayout.LabelField(new GUIContent("Transfer Root Motion To", "Select bone to transfer root motion animation to."), GUILayout.Width(LabelWidth - FieldOffset));
4446
EditorGUILayout.Popup(0, new string[]{"<None>"});
4547
GUILayout.EndHorizontal();
4648

4749
exportSettings.animatedSkinnedMesh = EditorGUILayout.Toggle ("Animated Skinned Mesh", exportSettings.animatedSkinnedMesh);
50+
EditorGUI.EndDisabledGroup ();
4851
}
4952
}
5053

@@ -67,9 +70,11 @@ public enum Include { Model = 0, Anim = 1, ModelAndAnim = 2 }
6770

6871
public enum ObjectPosition { LocalCentered = 0, WorldAbsolute = 1, LocalPivot = 2 }
6972

73+
public enum LODExportType { All = 0, Highest = 1, Lowest = 2 }
74+
7075
public ExportFormat exportFormat = ExportFormat.ASCII;
7176
public Include include = Include.ModelAndAnim;
72-
public ExportSettings.LODExportType lodLevel = ExportSettings.LODExportType.All;
77+
public LODExportType lodLevel = LODExportType.All;
7378
public ObjectPosition objectPosition = ObjectPosition.LocalCentered;
7479
public string rootMotionTransfer = "";
7580
public bool animatedSkinnedMesh = true;

Assets/FbxExporters/Editor/FbxExportSettings.cs

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -44,29 +44,12 @@ public override void OnInspectorGUI() {
4444
),
4545
exportSettings.mayaCompatibleNames);
4646

47-
exportSettings.centerObjects = EditorGUILayout.Toggle (
48-
new GUIContent("Center Objects:",
49-
"Center objects around a shared root and keep their relative placement unchanged."),
50-
exportSettings.centerObjects
51-
);
52-
5347
exportSettings.autoUpdaterEnabled = EditorGUILayout.Toggle(
5448
new GUIContent("Auto-Updater:",
5549
"Automatically updates prefabs with new fbx data that was imported."),
5650
exportSettings.autoUpdaterEnabled
5751
);
5852

59-
GUILayout.BeginHorizontal();
60-
EditorGUILayout.LabelField(new GUIContent("Export Format:", "Export the FBX file in the standard binary format." +
61-
" Select ASCII to export the FBX file in ASCII format."), GUILayout.Width(LabelWidth - FieldOffset));
62-
exportSettings.ExportFormatSelection = EditorGUILayout.Popup(exportSettings.ExportFormatSelection, new string[]{"Binary", "ASCII"});
63-
GUILayout.EndHorizontal();
64-
65-
GUILayout.BeginHorizontal();
66-
EditorGUILayout.LabelField(new GUIContent("LOD Export:", "Select which LOD to export."), GUILayout.Width(LabelWidth - FieldOffset));
67-
exportSettings.lodExportType = (ExportSettings.LODExportType)EditorGUILayout.Popup((int)exportSettings.lodExportType, new string[]{"All", "Highest", "Lowest"});
68-
GUILayout.EndHorizontal();
69-
7053
GUILayout.BeginHorizontal();
7154
EditorGUILayout.LabelField(new GUIContent(
7255
"Export Path:",
@@ -436,26 +419,15 @@ public static string[] DCCVendorLocations
436419

437420
// Note: default values are set in LoadDefaults().
438421
public bool mayaCompatibleNames = true;
439-
public bool centerObjects = false;
440422
public bool autoUpdaterEnabled = true;
441423
public bool launchAfterInstallation = true;
442424
public bool HideSendToUnityMenu = true;
443-
public int ExportFormatSelection;
444425
public bool BakeAnimation = true;
445426

446427
public string IntegrationSavePath;
447428

448429
public int selectedDCCApp = 0;
449430

450-
[SerializeField]
451-
public LODExportType lodExportType = LODExportType.All;
452-
453-
public enum LODExportType {
454-
All = 0,
455-
Highest = 1,
456-
Lowest = 2
457-
}
458-
459431
/// <summary>
460432
/// The path where Convert To Model will save the new fbx and prefab.
461433
///
@@ -472,6 +444,7 @@ public enum LODExportType {
472444
[SerializeField]
473445
private List<string> exportModelSavePaths = new List<string> ();
474446

447+
[SerializeField]
475448
public int selectedExportModelPath = 0;
476449
private int maxStoredSavePaths = 5;
477450

@@ -482,26 +455,54 @@ public enum LODExportType {
482455
[SerializeField]
483456
private List<string> dccOptionPaths;
484457

458+
// don't serialize as ScriptableObject does not get properly serialized on export
485459
[System.NonSerialized]
486460
public ExportModelSettings exportModelSettings;
487461

462+
// store contents of export model settings for serialization
488463
[SerializeField]
489464
private ExportModelSettingsSerialize exportModelSettingsSerialize;
490465

466+
// ---------------- get functions for options in ExportModelSettings ----------------
467+
public static ExportModelSettingsSerialize.ExportFormat GetExportFormat(){
468+
return instance.exportModelSettings.info.exportFormat;
469+
}
470+
471+
public static ExportModelSettingsSerialize.Include GetModelAnimIncludeOption(){
472+
return instance.exportModelSettings.info.include;
473+
}
474+
475+
public static ExportModelSettingsSerialize.LODExportType GetLODExportType(){
476+
return instance.exportModelSettings.info.lodLevel;
477+
}
478+
479+
public static ExportModelSettingsSerialize.ObjectPosition GetObjectPosition(){
480+
return instance.exportModelSettings.info.objectPosition;
481+
}
482+
483+
public static string GetRootMotionTransferNode(){
484+
return instance.exportModelSettings.info.rootMotionTransfer;
485+
}
486+
487+
public static bool AnimateSkinnedMesh(){
488+
return instance.exportModelSettings.info.animatedSkinnedMesh;
489+
}
490+
// ---------------------------------------------------------------------------------
491+
491492
protected override void LoadDefaults()
492493
{
493494
mayaCompatibleNames = true;
494-
centerObjects = true;
495495
autoUpdaterEnabled = true;
496496
launchAfterInstallation = true;
497497
HideSendToUnityMenu = true;
498-
ExportFormatSelection = 0;
499498
convertToModelSavePath = kDefaultSavePath;
500499
exportModelSavePaths = new List<string> (){ kDefaultSavePath };
501500
IntegrationSavePath = DefaultIntegrationSavePath;
502501
dccOptionPaths = null;
503502
dccOptionNames = null;
504503
BakeAnimation = true;
504+
exportModelSettings = ScriptableObject.CreateInstance (typeof(ExportModelSettings)) as ExportModelSettings;
505+
exportModelSettingsSerialize = exportModelSettings.info;
505506
}
506507

507508
/// <summary>

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,6 @@ public class ModelExporter : System.IDisposable
104104

105105
public const string PACKAGE_UI_NAME = "FBX Exporter";
106106

107-
public enum ExportFormat
108-
{
109-
Binary = 0,
110-
ASCII = 1
111-
}
112-
113107
/// <summary>
114108
/// name of the scene's default camera
115109
/// </summary>
@@ -1924,7 +1918,7 @@ protected int ExportTransformHierarchy(
19241918
GameObject unityGo, FbxScene fbxScene, FbxNode fbxNodeParent,
19251919
int exportProgress, int objectCount, Vector3 newCenter,
19261920
TransformExportType exportType = TransformExportType.Local,
1927-
ExportSettings.LODExportType lodExportType = ExportSettings.LODExportType.All
1921+
ExportModelSettingsSerialize.LODExportType lodExportType = ExportModelSettingsSerialize.LODExportType.All
19281922
)
19291923
{
19301924
int numObjectsExported = exportProgress;
@@ -1962,12 +1956,12 @@ protected int ExportTransformHierarchy(
19621956

19631957
// if this object has an LOD group, then export according to the LOD preference setting
19641958
var lodGroup = unityGo.GetComponent<LODGroup>();
1965-
if (lodGroup && lodExportType != ExportSettings.LODExportType.All) {
1959+
if (lodGroup && lodExportType != ExportModelSettingsSerialize.LODExportType.All) {
19661960
LOD[] lods = lodGroup.GetLODs ();
19671961

19681962
// LODs are ordered from highest to lowest.
19691963
// If exporting lowest LOD, reverse the array
1970-
if (lodExportType == ExportSettings.LODExportType.Lowest) {
1964+
if (lodExportType == ExportModelSettingsSerialize.LODExportType.Lowest) {
19711965
// reverse the array
19721966
LOD[] tempLods = new LOD[lods.Length];
19731967
System.Array.Copy (lods, tempLods, lods.Length);
@@ -2708,7 +2702,7 @@ public int ExportAll (
27082702
IEnumerable<UnityEngine.Object> unityExportSet,
27092703
Dictionary<GameObject, AnimationOnlyExportData> animationExportData,
27102704
TransformExportType exportType = TransformExportType.Global,
2711-
ExportSettings.LODExportType lodExportType = ExportSettings.LODExportType.All)
2705+
ExportModelSettingsSerialize.LODExportType lodExportType = ExportModelSettingsSerialize.LODExportType.All)
27122706
{
27132707
exportCancelled = false;
27142708

@@ -2741,7 +2735,7 @@ public int ExportAll (
27412735
// Initialize the exporter.
27422736
// fileFormat must be binary if we are embedding textures
27432737
int fileFormat = -1;
2744-
if (EditorTools.ExportSettings.instance.ExportFormatSelection == (int)ExportFormat.ASCII)
2738+
if (EditorTools.ExportSettings.GetExportFormat() == ExportModelSettingsSerialize.ExportFormat.ASCII)
27452739
{
27462740
fileFormat = fbxManager.GetIOPluginRegistry().FindWriterIDByDescription("FBX ascii (*.fbx)");
27472741
}
@@ -2813,7 +2807,9 @@ public int ExportAll (
28132807

28142808
Vector3 center = Vector3.zero;
28152809
if(exportType == TransformExportType.Global){
2816-
center = (ExportSettings.centerObjects && revisedExportSet.Count > 1)? FindCenter(revisedExportSet) : Vector3.zero;
2810+
center = (
2811+
ExportSettings.GetObjectPosition() == ExportModelSettingsSerialize.ObjectPosition.LocalCentered && revisedExportSet.Count > 1
2812+
)? FindCenter(revisedExportSet) : Vector3.zero;
28172813
}
28182814

28192815
foreach (var unityGo in revisedExportSet) {
@@ -3586,7 +3582,7 @@ public static string ExportObjects (
35863582
UnityEngine.Object[] objects = null,
35873583
AnimationExportType exportType = AnimationExportType.all,
35883584
TransformExportType transformExportType = TransformExportType.Global,
3589-
ExportSettings.LODExportType lodExportType = ExportSettings.LODExportType.All)
3585+
ExportModelSettingsSerialize.LODExportType lodExportType = ExportModelSettingsSerialize.LODExportType.All)
35903586
{
35913587
LastFilePath = filePath;
35923588

@@ -3641,7 +3637,7 @@ public static string ExportObject (
36413637
string filePath, UnityEngine.Object root,
36423638
AnimationExportType exportType = AnimationExportType.all,
36433639
TransformExportType transformExportType = TransformExportType.Reset,
3644-
ExportSettings.LODExportType lodExportType = ExportSettings.LODExportType.All)
3640+
ExportModelSettingsSerialize.LODExportType lodExportType = ExportModelSettingsSerialize.LODExportType.All)
36453641
{
36463642
return ExportObjects(filePath, new Object[] { root }, exportType, transformExportType, lodExportType);
36473643
}

Assets/FbxExporters/Editor/UnitTests/ExporterTestBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ protected virtual string ExportSelectedObjects(string filename, params Object[]
261261
/// <returns>The exported fbx file path.</returns>
262262
/// <param name="hierarchy">Hierarchy.</param>
263263
/// <param name="animOnly">If set to <c>true</c> export animation only.</param>
264-
protected string ExportToFbx (GameObject hierarchy, bool animOnly = false, EditorTools.ExportSettings.LODExportType lodExportType = EditorTools.ExportSettings.LODExportType.All){
264+
protected string ExportToFbx (GameObject hierarchy, bool animOnly = false, EditorTools.ExportModelSettingsSerialize.LODExportType lodExportType = EditorTools.ExportModelSettingsSerialize.LODExportType.All){
265265
string filename = GetRandomFbxFilePath ();
266266
var exportedFilePath = FbxExporters.Editor.ModelExporter.ExportObject (
267267
filename, hierarchy,

Assets/FbxExporters/Editor/UnitTests/ModelExporterTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ public void LODExportTest(){
778778

779779
// test export all
780780
// expected LODs exported: Sphere_LOD0, Capsule_LOD0, Cube_LOD2
781-
string filename = ExportToFbx(lodGroup, lodExportType:EditorTools.ExportSettings.LODExportType.All);
781+
string filename = ExportToFbx(lodGroup, lodExportType:EditorTools.ExportModelSettingsSerialize.LODExportType.All);
782782
GameObject fbxObj = AssetDatabase.LoadMainAssetAtPath (filename) as GameObject;
783783
Assert.IsTrue (fbxObj);
784784

@@ -787,7 +787,7 @@ public void LODExportTest(){
787787

788788
// test export highest
789789
// expected LODs exported: Sphere_LOD0, Capsule_LOD0
790-
filename = ExportToFbx(lodGroup, lodExportType:EditorTools.ExportSettings.LODExportType.Highest);
790+
filename = ExportToFbx(lodGroup, lodExportType:EditorTools.ExportModelSettingsSerialize.LODExportType.Highest);
791791
fbxObj = AssetDatabase.LoadMainAssetAtPath (filename) as GameObject;
792792
Assert.IsTrue (fbxObj);
793793

@@ -796,7 +796,7 @@ public void LODExportTest(){
796796

797797
// test export lowest
798798
// expected LODs exported: Cube_LOD2
799-
filename = ExportToFbx(lodGroup, lodExportType:EditorTools.ExportSettings.LODExportType.Lowest);
799+
filename = ExportToFbx(lodGroup, lodExportType:EditorTools.ExportModelSettingsSerialize.LODExportType.Lowest);
800800
fbxObj = AssetDatabase.LoadMainAssetAtPath (filename) as GameObject;
801801
Assert.IsTrue (fbxObj);
802802

0 commit comments

Comments
 (0)