Skip to content

Commit e493f0d

Browse files
committed
Changed FbxExportSettings to use the new ProviderSettings instead.
1 parent d7331b6 commit e493f0d

File tree

1 file changed

+56
-26
lines changed

1 file changed

+56
-26
lines changed

proto.com.unity.formats.fbx/Editor/FbxExportSettings.cs

Lines changed: 56 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using UnityEngine;
55
using System.Collections.Generic;
66
using System.Linq;
7+
using System.Reflection;
78
using System.Runtime.Serialization;
89
using System.Security.Permissions;
910

@@ -32,6 +33,24 @@ internal class ExportSettingsEditor : UnityEditor.Editor {
3233
const float FieldOffset = 18;
3334
const float BrowseButtonOffset = 5;
3435

36+
static class Style
37+
{
38+
public static GUIContent Application3D = new GUIContent(
39+
"3D Application:",
40+
"Select the 3D Application for which you would like to install the Unity integration.");
41+
public static GUIContent KeepOpen = new GUIContent("Keep Open:",
42+
"Keep the selected 3D application open after Unity integration install has completed.");
43+
public static GUIContent HideNativeMenu = new GUIContent("Hide Native Menu:",
44+
"Replace Maya's native 'Send to Unity' menu with the Unity Integration's menu");
45+
public static GUIContent InstallIntegrationContent = new GUIContent(
46+
"Install Unity Integration",
47+
"Install and configure the Unity integration for the selected 3D application so that you can import and export directly with this project.");
48+
public static GUIContent RepairMissingScripts = new GUIContent(
49+
"Run Component Updater",
50+
"If FBX exporter version 1.3.0f1 or earlier was previously installed, then links to the FbxPrefab component will need updating.\n" +
51+
"Run this to update all FbxPrefab references in text serialized prefabs and scene files.");
52+
}
53+
3554
[SecurityPermission(SecurityAction.LinkDemand)]
3655
public override void OnInspectorGUI() {
3756
ExportSettings exportSettings = (ExportSettings)target;
@@ -69,9 +88,7 @@ public override void OnInspectorGUI() {
6988
EditorGUI.indentLevel++;
7089

7190
GUILayout.BeginHorizontal ();
72-
EditorGUILayout.LabelField(new GUIContent (
73-
"3D Application:",
74-
"Select the 3D Application for which you would like to install the Unity integration."), GUILayout.Width(LabelWidth - FieldOffset));
91+
EditorGUILayout.LabelField(Style.Application3D, GUILayout.Width(LabelWidth - FieldOffset));
7592

7693
// dropdown to select Maya version to use
7794
var options = ExportSettings.GetDCCOptions();
@@ -115,25 +132,20 @@ public override void OnInspectorGUI() {
115132
EditorGUILayout.Space();
116133

117134
exportSettings.LaunchAfterInstallation = EditorGUILayout.Toggle(
118-
new GUIContent("Keep Open:",
119-
"Keep the selected 3D application open after Unity integration install has completed."),
135+
Style.KeepOpen,
120136
exportSettings.LaunchAfterInstallation
121137
);
122138

123139
exportSettings.HideSendToUnityMenuProperty = EditorGUILayout.Toggle(
124-
new GUIContent("Hide Native Menu:",
125-
"Replace Maya's native 'Send to Unity' menu with the Unity Integration's menu"),
140+
Style.HideNativeMenu,
126141
exportSettings.HideSendToUnityMenuProperty
127142
);
128143

129144
EditorGUILayout.Space();
130145

131146
// disable button if no 3D application is available
132147
EditorGUI.BeginDisabledGroup (!ExportSettings.CanInstall());
133-
var installIntegrationContent = new GUIContent(
134-
"Install Unity Integration",
135-
"Install and configure the Unity integration for the selected 3D application so that you can import and export directly with this project.");
136-
if (GUILayout.Button (installIntegrationContent)) {
148+
if (GUILayout.Button (Style.InstallIntegrationContent)) {
137149
EditorApplication.delayCall += UnityEditor.Formats.Fbx.Exporter.IntegrationsUI.InstallDCCIntegration;
138150
}
139151
EditorGUI.EndDisabledGroup ();
@@ -145,13 +157,8 @@ public override void OnInspectorGUI() {
145157
EditorGUI.indentLevel++;
146158

147159
EditorGUILayout.Space ();
148-
149-
var repairMissingScripts = new GUIContent (
150-
"Run Component Updater",
151-
"If FBX exporter version 1.3.0f1 or earlier was previously installed, then links to the FbxPrefab component will need updating.\n" +
152-
"Run this to update all FbxPrefab references in text serialized prefabs and scene files.");
153-
154-
if (GUILayout.Button (repairMissingScripts)) {
160+
161+
if (GUILayout.Button (Style.RepairMissingScripts)) {
155162
var componentUpdater = new UnityEditor.Formats.Fbx.Exporter.RepairMissingScripts ();
156163
var filesToRepairCount = componentUpdater.AssetsToRepairCount;
157164
var dialogTitle = "FBX Prefab Component Updater";
@@ -227,6 +234,37 @@ private static string TryFindDCC(string dccPath, string ext, ExportSettings.DCCT
227234
return newDccPath;
228235
}
229236

237+
[SettingsProvider]
238+
static SettingsProvider CreateFbxExportSettingsProvider()
239+
{
240+
ExportSettings.instance.name = "FBX Export Settings";
241+
ExportSettings.instance.Load();
242+
243+
var provider = AssetSettingsProvider.CreateProviderFromObject(
244+
"Project/Fbx Export", ExportSettings.instance, GetSearchKeywordsFromGUIContentProperties(typeof(Style)));
245+
provider.inspectorUpdateHandler += () =>
246+
{
247+
if (provider.settingsEditor != null &&
248+
provider.settingsEditor.serializedObject.UpdateIfRequiredOrScript())
249+
{
250+
provider.Repaint();
251+
}
252+
};
253+
return provider;
254+
}
255+
256+
static IEnumerable<string> GetSearchKeywordsFromGUIContentProperties(Type type)
257+
{
258+
return type.GetFields(BindingFlags.Static | BindingFlags.Public)
259+
.Where(field => typeof(GUIContent).IsAssignableFrom(field.FieldType))
260+
.Select(field => ((GUIContent)field.GetValue(null)).text)
261+
.Concat(type.GetProperties(BindingFlags.Static | BindingFlags.Public)
262+
.Where(prop => typeof(GUIContent).IsAssignableFrom(prop.PropertyType))
263+
.Select(prop => ((GUIContent)prop.GetValue(null, null)).text))
264+
.Where(content => content != null)
265+
.Select(content => content.ToLowerInvariant())
266+
.Distinct();
267+
}
230268
}
231269

232270
[FilePath("ProjectSettings/FbxExportSettings.asset",FilePathAttribute.Location.ProjectFolder)]
@@ -1332,14 +1370,6 @@ internal static string NormalizePath(string path, bool isRelative,
13321370
}
13331371
}
13341372

1335-
[MenuItem("Edit/Project Settings/FBX Export", priority = 300)]
1336-
static void ShowManager()
1337-
{
1338-
instance.name = "FBX Export Settings";
1339-
Selection.activeObject = instance;
1340-
instance.Load();
1341-
}
1342-
13431373
internal override void Load ()
13441374
{
13451375
base.Load ();

0 commit comments

Comments
 (0)