4
4
using UnityEngine ;
5
5
using System . Collections . Generic ;
6
6
using System . Linq ;
7
+ using System . Reflection ;
7
8
using System . Runtime . Serialization ;
8
9
using System . Security . Permissions ;
9
10
@@ -32,6 +33,24 @@ internal class ExportSettingsEditor : UnityEditor.Editor {
32
33
const float FieldOffset = 18 ;
33
34
const float BrowseButtonOffset = 5 ;
34
35
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
+
35
54
[ SecurityPermission ( SecurityAction . LinkDemand ) ]
36
55
public override void OnInspectorGUI ( ) {
37
56
ExportSettings exportSettings = ( ExportSettings ) target ;
@@ -69,9 +88,7 @@ public override void OnInspectorGUI() {
69
88
EditorGUI . indentLevel ++ ;
70
89
71
90
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 ) ) ;
75
92
76
93
// dropdown to select Maya version to use
77
94
var options = ExportSettings . GetDCCOptions ( ) ;
@@ -115,25 +132,20 @@ public override void OnInspectorGUI() {
115
132
EditorGUILayout . Space ( ) ;
116
133
117
134
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 ,
120
136
exportSettings . LaunchAfterInstallation
121
137
) ;
122
138
123
139
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 ,
126
141
exportSettings . HideSendToUnityMenuProperty
127
142
) ;
128
143
129
144
EditorGUILayout . Space ( ) ;
130
145
131
146
// disable button if no 3D application is available
132
147
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 ) ) {
137
149
EditorApplication . delayCall += UnityEditor . Formats . Fbx . Exporter . IntegrationsUI . InstallDCCIntegration ;
138
150
}
139
151
EditorGUI . EndDisabledGroup ( ) ;
@@ -145,13 +157,8 @@ public override void OnInspectorGUI() {
145
157
EditorGUI . indentLevel ++ ;
146
158
147
159
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 ) ) {
155
162
var componentUpdater = new UnityEditor . Formats . Fbx . Exporter . RepairMissingScripts ( ) ;
156
163
var filesToRepairCount = componentUpdater . AssetsToRepairCount ;
157
164
var dialogTitle = "FBX Prefab Component Updater" ;
@@ -227,6 +234,37 @@ private static string TryFindDCC(string dccPath, string ext, ExportSettings.DCCT
227
234
return newDccPath ;
228
235
}
229
236
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
+ }
230
268
}
231
269
232
270
[ FilePath ( "ProjectSettings/FbxExportSettings.asset" , FilePathAttribute . Location . ProjectFolder ) ]
@@ -1332,14 +1370,6 @@ internal static string NormalizePath(string path, bool isRelative,
1332
1370
}
1333
1371
}
1334
1372
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
-
1343
1373
internal override void Load ( )
1344
1374
{
1345
1375
base . Load ( ) ;
0 commit comments