@@ -98,7 +98,7 @@ public override void OnInspectorGUI() {
98
98
var options = ExportSettings . GetDCCOptions ( ) ;
99
99
// make sure we never initially have browse selected
100
100
if ( exportSettings . selectedDCCApp == options . Length - 1 ) {
101
- exportSettings . selectedDCCApp = exportSettings . FindPreferredProgram ( ) ;
101
+ exportSettings . selectedDCCApp = exportSettings . GetPreferredDCCApp ( ) ;
102
102
}
103
103
104
104
int oldValue = exportSettings . selectedDCCApp ;
@@ -226,7 +226,9 @@ private static string TryFindDCC(string dccPath, string ext, ExportSettings.DCCT
226
226
public class ExportSettings : ScriptableSingleton < ExportSettings >
227
227
{
228
228
public const string kDefaultSavePath = "." ;
229
- private static List < string > preferenceList = new List < string > ( ) { "maya" , "mayalt" , "3ds" , "blender" } ;
229
+ private static List < string > s_PreferenceList = new List < string > ( ) { "maya" , "mayalt" , "3ds" , "blender" } ;
230
+ public static string s_MaxName = "3ds Max " ;
231
+ public static string s_MayaName = "Maya " ;
230
232
231
233
/// <summary>
232
234
/// The path where all the different versions of Maya are installed
@@ -285,7 +287,7 @@ protected override void LoadDefaults()
285
287
/// </summary>
286
288
/// <returns>The unique name.</returns>
287
289
/// <param name="name">Name.</param>
288
- private static string GetUniqueName ( string name ) {
290
+ public static string GetUniqueName ( string name ) {
289
291
if ( ! instance . dccOptionNames . Contains ( name ) ) {
290
292
return name ;
291
293
}
@@ -307,7 +309,7 @@ private static string GetUniqueName(string name){
307
309
do {
308
310
uniqueName = string . Format ( format , index , name ) ;
309
311
index ++ ;
310
- } while ( instance . dccOptionNames . Contains ( name ) ) ;
312
+ } while ( instance . dccOptionNames . Contains ( uniqueName ) ) ;
311
313
312
314
return uniqueName ;
313
315
}
@@ -317,16 +319,20 @@ private static string GetUniqueName(string name){
317
319
/// Find the latest program available and make that the default choice.
318
320
/// Will always take any Maya version over any 3ds Max version.
319
321
///
320
- /// Returns the index of the most recent program in the list of dccOptionPaths
322
+ /// Returns the index of the most recent program in the list of dccOptionNames
321
323
///
322
324
/// </summary>
323
- public int FindPreferredProgram ( )
325
+ public int GetPreferredDCCApp ( )
324
326
{
327
+ if ( dccOptionNames == null )
328
+ {
329
+ return - 1 ;
330
+ }
325
331
326
- int newestDCCVersionIndex = 0 ;
327
- int newestDCCVersionNumber = 0 ;
332
+ int newestDCCVersionIndex = - 1 ;
333
+ int newestDCCVersionNumber = - 1 ;
328
334
329
- for ( int i = 0 ; i < dccOptionPaths . Count ; i ++ )
335
+ for ( int i = 0 ; i < dccOptionNames . Count ; i ++ )
330
336
{
331
337
int versionToCheck = FindDCCVersion ( dccOptionNames [ i ] ) ;
332
338
if ( versionToCheck > newestDCCVersionNumber )
@@ -336,42 +342,36 @@ public int FindPreferredProgram()
336
342
}
337
343
else if ( versionToCheck == newestDCCVersionNumber )
338
344
{
339
- string selection = PickPrefferedName ( dccOptionNames [ newestDCCVersionIndex ] , dccOptionNames [ i ] ) ;
340
- if ( selection == dccOptionNames [ i ] )
345
+ int selection = ChoosePreferredDCCApp ( newestDCCVersionIndex , i ) ;
346
+ if ( selection == i )
341
347
{
342
348
newestDCCVersionIndex = i ;
343
349
newestDCCVersionNumber = FindDCCVersion ( dccOptionNames [ i ] ) ;
344
350
}
345
351
}
346
352
}
347
- Debug . Assert ( newestDCCVersionIndex > - 1 && newestDCCVersionIndex < dccOptionPaths . Count ) ;
353
+ Debug . Assert ( newestDCCVersionIndex >= - 1 && newestDCCVersionIndex < dccOptionNames . Count ) ;
348
354
return newestDCCVersionIndex ;
349
355
}
350
356
/// <summary>
351
- /// Gives our preffered program name from two options. ACCEPTS ENTRIES FROM DCCOptionNames LIST
357
+ /// Takes the index of two program names from dccOptionNames and chooses our preferred one based on the preference list
358
+ /// This happens in case of a tie between two programs with the same release year / version
352
359
/// </summary>
353
360
/// <param name="optionA"></param>
354
361
/// <param name="optionB"></param>
355
362
/// <returns></returns>
356
- private string PickPrefferedName ( string optionA , string optionB )
363
+ private int ChoosePreferredDCCApp ( int optionA , int optionB )
357
364
{
358
- string [ ] optionArray = new string [ 2 ] ;
359
- optionArray [ 0 ] = optionA . ToLower ( ) . Split ( ' ' ) [ 0 ] ;
360
- optionArray [ 1 ] = optionB . ToLower ( ) . Split ( ' ' ) [ 0 ] ;
361
- int [ ] optionScores = new int [ 2 ] ;
365
+ int scoreA = s_PreferenceList . IndexOf ( GetAppNameFromFolderName ( dccOptionNames [ optionA ] ) ) ;
366
+ int scoreB = s_PreferenceList . IndexOf ( GetAppNameFromFolderName ( dccOptionNames [ optionB ] ) ) ;
362
367
363
- for ( int i = 0 ; i < 2 ; i ++ )
364
- {
365
- for ( int j = 0 ; j < preferenceList . Count ; j ++ )
366
- {
367
- if ( optionArray [ i ] == preferenceList [ j ] )
368
- {
369
- optionScores [ i ] = j ;
370
- }
371
- }
372
- }
368
+ return scoreA < scoreB ? optionA : optionB ;
369
+ }
373
370
374
- return optionScores [ 0 ] < optionScores [ 1 ] ? optionA : optionB ;
371
+ ///
372
+ private string GetAppNameFromFolderName ( string originalString )
373
+ {
374
+ return originalString . ToLower ( ) . Split ( ' ' ) [ 0 ] ;
375
375
}
376
376
377
377
/// <summary>
@@ -381,8 +381,17 @@ private string PickPrefferedName(string optionA, string optionB)
381
381
/// <returns> the year/version OR -1 if the year could not be parsed </returns>
382
382
private static int FindDCCVersion ( string AppName )
383
383
{
384
+ if ( AppName == null )
385
+ {
386
+ return - 1 ;
387
+ }
388
+
384
389
int version ;
385
390
string [ ] piecesArray = AppName . Split ( ' ' ) ;
391
+ if ( piecesArray . Length == 0 )
392
+ {
393
+ return - 1 ;
394
+ }
386
395
//Get the number, which is always the last chunk separated by a space.
387
396
string number = piecesArray [ piecesArray . Length - 1 ] ;
388
397
@@ -439,7 +448,7 @@ private static void FindDCCInstalls() {
439
448
}
440
449
string version = product . Substring ( "maya" . Length ) ;
441
450
dccOptionPath . Add ( GetMayaExePath ( productDir . FullName . Replace ( "\\ " , "/" ) ) ) ;
442
- dccOptionName . Add ( GetUniqueName ( "Maya " + version ) ) ;
451
+ dccOptionName . Add ( GetUniqueName ( s_MayaName + version ) ) ;
443
452
}
444
453
445
454
if ( product . StartsWith ( "3ds max" , StringComparison . InvariantCultureIgnoreCase ) ) {
@@ -449,10 +458,10 @@ private static void FindDCCInstalls() {
449
458
}
450
459
string version = product . Substring ( "3ds max " . Length ) ;
451
460
dccOptionPath . Add ( exePath ) ;
452
- dccOptionName . Add ( GetUniqueName ( "3ds Max " + version ) ) ;
461
+ dccOptionName . Add ( GetUniqueName ( s_MaxName + version ) ) ;
453
462
}
454
463
}
455
- instance . selectedDCCApp = instance . FindPreferredProgram ( ) ;
464
+ instance . selectedDCCApp = instance . GetPreferredDCCApp ( ) ;
456
465
}
457
466
458
467
/// <summary>
@@ -499,7 +508,7 @@ public static GUIContent[] GetDCCOptions(){
499
508
var dccPath = instance . dccOptionPaths [ i ] ;
500
509
if ( ! File . Exists ( dccPath ) ) {
501
510
if ( i == instance . selectedDCCApp ) {
502
- instance . selectedDCCApp = instance . FindPreferredProgram ( ) ;
511
+ instance . selectedDCCApp = instance . GetPreferredDCCApp ( ) ;
503
512
}
504
513
namesToDelete . Add ( instance . dccOptionNames [ i ] ) ;
505
514
pathsToDelete . Add ( dccPath ) ;
0 commit comments