3
3
using UnityEditorInternal ;
4
4
using UnityEngine ;
5
5
using UnityEditor ;
6
+ using System . Collections . Generic ;
6
7
7
8
namespace FbxExporters . EditorTools {
8
9
@@ -112,22 +113,20 @@ public override void OnInspectorGUI() {
112
113
if ( exportSettings . selectedMayaApp == options . Length - 1 ) {
113
114
exportSettings . selectedMayaApp = 0 ;
114
115
}
115
- int result = EditorGUILayout . Popup ( exportSettings . selectedMayaApp , options ) ;
116
- if ( result == options . Length - 1 ) {
116
+ int oldValue = exportSettings . selectedMayaApp ;
117
+ exportSettings . selectedMayaApp = EditorGUILayout . Popup ( exportSettings . selectedMayaApp , options ) ;
118
+ if ( exportSettings . selectedMayaApp == options . Length - 1 ) {
117
119
string mayaPath = EditorUtility . OpenFilePanel ( "Select Maya Application" , ExportSettings . kDefaultAdskRoot , "exe" ) ;
118
120
119
121
// check that the path is valid and references the maya executable
120
122
if ( ! string . IsNullOrEmpty ( mayaPath ) &&
121
- Path . GetFileNameWithoutExtension ( mayaPath ) . ToLower ( ) . Equals ( "maya" )
122
- ) {
123
+ Path . GetFileNameWithoutExtension ( mayaPath ) . ToLower ( ) . Equals ( "maya" ) ) {
123
124
ExportSettings . AddMayaOption ( mayaPath ) ;
124
125
Repaint ( ) ;
126
+ } else {
127
+ exportSettings . selectedMayaApp = oldValue ;
125
128
}
126
- } else {
127
- exportSettings . selectedMayaApp = result ;
128
129
}
129
-
130
-
131
130
GUILayout . EndHorizontal ( ) ;
132
131
133
132
if ( GUILayout . Button ( "Install Maya Integration" ) ) {
@@ -187,12 +186,12 @@ public class ExportSettings : ScriptableSingleton<ExportSettings>
187
186
[ SerializeField ]
188
187
string convertToModelSavePath ;
189
188
189
+ // List of names in order that they appear in option list
190
190
[ SerializeField ]
191
+ private List < string > mayaOptionNames ;
191
192
// List of paths in order that they appear in the option list
192
- private System . Collections . Generic . List < string > mayaOptionPaths ;
193
193
[ SerializeField ]
194
- // Dictionary of path -> display name
195
- private System . Collections . Generic . Dictionary < string , string > mayaAppOptions ;
194
+ private List < string > mayaOptionPaths ;
196
195
197
196
protected override void LoadDefaults ( )
198
197
{
@@ -201,7 +200,8 @@ protected override void LoadDefaults()
201
200
centerObjects = true ;
202
201
convertToModelSavePath = kDefaultSavePath ;
203
202
turntableScene = null ;
204
- mayaAppOptions = null ;
203
+ mayaOptionPaths = null ;
204
+ mayaOptionNames = null ;
205
205
}
206
206
207
207
/// <summary>
@@ -210,7 +210,7 @@ protected override void LoadDefaults()
210
210
/// <returns>The unique name.</returns>
211
211
/// <param name="name">Name.</param>
212
212
private static string GetUniqueName ( string name ) {
213
- if ( ! instance . mayaAppOptions . ContainsValue ( name ) ) {
213
+ if ( ! instance . mayaOptionNames . Contains ( name ) ) {
214
214
return name ;
215
215
}
216
216
var format = "{1} ({0})" ;
@@ -231,7 +231,7 @@ private static string GetUniqueName(string name){
231
231
do {
232
232
uniqueName = string . Format ( format , index , name ) ;
233
233
index ++ ;
234
- } while ( File . Exists ( uniqueName ) ) ;
234
+ } while ( instance . mayaOptionNames . Contains ( name ) ) ;
235
235
236
236
return uniqueName ;
237
237
}
@@ -243,16 +243,17 @@ private static string GetUniqueName(string name){
243
243
/// If MAYA_LOCATION is set, add this to the list as well.
244
244
/// </summary>
245
245
private static void FindMayaInstalls ( ) {
246
- if ( instance . mayaAppOptions == null ) {
247
- instance . mayaAppOptions = new System . Collections . Generic . Dictionary < string , string > ( ) ;
248
- }
249
- var mayaAppOptions = instance . mayaAppOptions ;
246
+ instance . mayaOptionPaths = new List < string > ( ) ;
247
+ instance . mayaOptionNames = new List < string > ( ) ;
248
+ var mayaOptionName = instance . mayaOptionNames ;
249
+ var mayaOptionPath = instance . mayaOptionPaths ;
250
250
251
251
// If the location is given by the environment, use it.
252
252
var location = System . Environment . GetEnvironmentVariable ( "MAYA_LOCATION" ) ;
253
253
if ( ! string . IsNullOrEmpty ( location ) ) {
254
254
location = location . TrimEnd ( '/' ) ;
255
- mayaAppOptions . Add ( GetMayaExePath ( location . Replace ( "\\ " , "/" ) ) , "MAYA_LOCATION" ) ;
255
+ mayaOptionPath . Add ( GetMayaExePath ( location . Replace ( "\\ " , "/" ) ) ) ;
256
+ mayaOptionName . Add ( "MAYA_LOCATION" ) ;
256
257
}
257
258
258
259
// List that directory and find the right version:
@@ -269,7 +270,8 @@ private static void FindMayaInstalls() {
269
270
if ( product . StartsWith ( "mayalt" , StringComparison . InvariantCultureIgnoreCase ) ) {
270
271
continue ;
271
272
}
272
- mayaAppOptions . Add ( GetMayaExePath ( productDir . FullName . Replace ( "\\ " , "/" ) ) , GetUniqueName ( product ) ) ;
273
+ mayaOptionPath . Add ( GetMayaExePath ( productDir . FullName . Replace ( "\\ " , "/" ) ) ) ;
274
+ mayaOptionName . Add ( GetUniqueName ( product ) ) ;
273
275
}
274
276
}
275
277
@@ -300,17 +302,32 @@ private static string GetMayaExePath(string location)
300
302
}
301
303
302
304
public static GUIContent [ ] GetMayaOptions ( ) {
303
- if ( instance . mayaAppOptions == null ) {
305
+ if ( instance . mayaOptionNames == null ||
306
+ instance . mayaOptionNames . Count != instance . mayaOptionPaths . Count ||
307
+ instance . mayaOptionNames . Count == 0 ) {
304
308
FindMayaInstalls ( ) ;
305
- instance . mayaOptionPaths = new System . Collections . Generic . List < string > ( ) ;
306
- foreach ( var key in instance . mayaAppOptions . Keys ) {
307
- instance . mayaOptionPaths . Add ( key ) ;
309
+ }
310
+
311
+ // remove options that no longer exist
312
+ List < int > toDelete = new List < int > ( ) ;
313
+ for ( int i = 0 ; i < instance . mayaOptionPaths . Count ; i ++ ) {
314
+ var mayaPath = instance . mayaOptionPaths [ i ] ;
315
+ if ( ! File . Exists ( mayaPath ) ) {
316
+ if ( i == instance . selectedMayaApp ) {
317
+ instance . selectedMayaApp = 0 ;
318
+ }
319
+ instance . mayaOptionNames . RemoveAt ( i ) ;
320
+ toDelete . Add ( i ) ;
308
321
}
309
322
}
310
- GUIContent [ ] optionArray = new GUIContent [ instance . mayaAppOptions . Count + 1 ] ;
323
+ foreach ( var index in toDelete ) {
324
+ instance . mayaOptionPaths . RemoveAt ( index ) ;
325
+ }
326
+
327
+ GUIContent [ ] optionArray = new GUIContent [ instance . mayaOptionPaths . Count + 1 ] ;
311
328
for ( int i = 0 ; i < instance . mayaOptionPaths . Count ; i ++ ) {
312
329
optionArray [ i ] = new GUIContent (
313
- instance . mayaAppOptions [ instance . mayaOptionPaths [ i ] ] ,
330
+ instance . mayaOptionNames [ i ] ,
314
331
instance . mayaOptionPaths [ i ]
315
332
) ;
316
333
}
@@ -320,17 +337,17 @@ public static GUIContent[] GetMayaOptions(){
320
337
}
321
338
322
339
public static void AddMayaOption ( string newOption ) {
323
- var mayaAppOptions = instance . mayaAppOptions ;
324
- if ( mayaAppOptions . ContainsKey ( newOption ) ) {
325
- instance . selectedMayaApp = instance . mayaOptionPaths . IndexOf ( newOption ) ;
340
+ var mayaOptionPaths = instance . mayaOptionPaths ;
341
+ if ( mayaOptionPaths . Contains ( newOption ) ) {
342
+ instance . selectedMayaApp = mayaOptionPaths . IndexOf ( newOption ) ;
326
343
return ;
327
344
}
328
345
329
346
// get the version
330
347
var version = AskMayaVersion ( newOption ) ;
331
- mayaAppOptions . Add ( newOption , GetUniqueName ( "Maya" + version ) ) ;
332
- instance . mayaOptionPaths . Add ( newOption ) ;
333
- instance . selectedMayaApp = instance . mayaOptionPaths . Count - 1 ;
348
+ instance . mayaOptionNames . Add ( GetUniqueName ( "Maya" + version ) ) ;
349
+ mayaOptionPaths . Add ( newOption ) ;
350
+ instance . selectedMayaApp = mayaOptionPaths . Count - 1 ;
334
351
}
335
352
336
353
/// <summary>
0 commit comments