@@ -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 . FindMostRecentProgram ( ) ;
101
+ exportSettings . selectedDCCApp = exportSettings . FindPreferredProgram ( ) ;
102
102
}
103
103
104
104
int oldValue = exportSettings . selectedDCCApp ;
@@ -226,6 +226,7 @@ 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
230
230
231
/// <summary>
231
232
/// The path where all the different versions of Maya are installed
@@ -265,10 +266,10 @@ public static string kDefaultAdskRoot {
265
266
266
267
// List of names in order that they appear in option list
267
268
[ SerializeField ]
268
- private List < string > dccOptionNames ;
269
+ public List < string > dccOptionNames ;
269
270
// List of paths in order that they appear in the option list
270
271
[ SerializeField ]
271
- private List < string > dccOptionPaths ;
272
+ public List < string > dccOptionPaths ;
272
273
273
274
protected override void LoadDefaults ( )
274
275
{
@@ -316,84 +317,87 @@ private static string GetUniqueName(string name){
316
317
/// Find the latest program available and make that the default choice.
317
318
/// Will always take any Maya version over any 3ds Max version.
318
319
///
319
- /// Returns the position of the most recent program in the list of dccOptionPaths
320
+ /// Returns the index of the most recent program in the list of dccOptionPaths
320
321
///
321
322
/// </summary>
322
- public int FindMostRecentProgram ( )
323
+ public int FindPreferredProgram ( )
323
324
{
324
- int newestMayaVersion = - 1 ;
325
- int savedMayaVersionNumber = 0 ;
326
- int newestMaxVersion = - 1 ;
327
- int savedMaxVersionNumber = 0 ;
328
325
329
- for ( int i = 0 ; i < instance . dccOptionPaths . Count ; i ++ )
326
+ int newestDCCVersionIndex = 0 ;
327
+ int newestDCCVersionNumber = 0 ;
328
+
329
+ for ( int i = 0 ; i < dccOptionPaths . Count ; i ++ )
330
330
{
331
- if ( instance . dccOptionPaths [ i ] . ToLower ( ) . Contains ( "maya" ) )
331
+ int versionToCheck = FindDCCVersion ( dccOptionNames [ i ] ) ;
332
+ if ( versionToCheck > newestDCCVersionNumber )
332
333
{
333
- if ( newestMayaVersion == - 1 )
334
- {
335
- newestMayaVersion = 0 ;
336
- savedMayaVersionNumber = FindDCCVersion ( dccOptionNames [ i ] ) ;
337
- continue ;
338
- }
339
-
340
- //Check if the path we are considering is newer than the previously saved one
341
- int versionToCheck = FindDCCVersion ( dccOptionNames [ i ] ) ;
342
- if ( versionToCheck > savedMayaVersionNumber )
343
- {
344
- newestMayaVersion = i ;
345
- savedMayaVersionNumber = versionToCheck ;
346
- }
334
+ newestDCCVersionIndex = i ;
335
+ newestDCCVersionNumber = versionToCheck ;
347
336
}
348
- else if ( newestMayaVersion == - 1 && instance . dccOptionPaths [ i ] . ToLower ( ) . Contains ( "max" ) )
337
+ else if ( versionToCheck == newestDCCVersionNumber )
349
338
{
350
- if ( newestMaxVersion == - 1 )
339
+ string selection = PickPrefferedName ( dccOptionNames [ newestDCCVersionIndex ] , dccOptionNames [ i ] ) ;
340
+ if ( selection == dccOptionNames [ i ] )
351
341
{
352
- newestMaxVersion = 0 ;
353
- savedMaxVersionNumber = FindDCCVersion ( dccOptionNames [ newestMaxVersion ] ) ;
354
- continue ;
342
+ newestDCCVersionIndex = i ;
343
+ newestDCCVersionNumber = FindDCCVersion ( dccOptionNames [ i ] ) ;
355
344
}
356
-
357
- //Check if the path we are considering is newer than the previously saved one
358
- int versionToCheck = FindDCCVersion ( dccOptionNames [ i ] ) ;
359
- if ( versionToCheck > savedMaxVersionNumber )
360
- {
361
- newestMaxVersion = i ;
362
- savedMaxVersionNumber = versionToCheck ;
363
- }
364
-
365
345
}
366
-
367
346
}
347
+ Debug . Assert ( newestDCCVersionIndex > - 1 && newestDCCVersionIndex < dccOptionPaths . Count ) ;
348
+ return newestDCCVersionIndex ;
349
+ }
350
+ /// <summary>
351
+ /// Gives our preffered program name from two options. ACCEPTS ENTRIES FROM DCCOptionNames LIST
352
+ /// </summary>
353
+ /// <param name="optionA"></param>
354
+ /// <param name="optionB"></param>
355
+ /// <returns></returns>
356
+ private string PickPrefferedName ( string optionA , string optionB )
357
+ {
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 ] ;
368
362
369
- //We prefer to use the latest Maya version, if one exists
370
- if ( newestMayaVersion != - 1 )
363
+ for ( int i = 0 ; i < 2 ; i ++ )
371
364
{
372
- return newestMayaVersion ;
373
- }
374
- else if ( newestMaxVersion != - 1 )
375
- {
376
- return newestMaxVersion ;
365
+ for ( int j = 0 ; j < preferenceList . Count ; j ++ )
366
+ {
367
+ if ( optionArray [ i ] == preferenceList [ j ] )
368
+ {
369
+ optionScores [ i ] = j ;
370
+ }
371
+ }
377
372
}
378
373
379
- return 0 ;
374
+ return optionScores [ 0 ] < optionScores [ 1 ] ? optionA : optionB ;
380
375
}
381
376
382
377
/// <summary>
383
- /// Finds the 3ds Max version based off of the title of the application
378
+ /// Finds the version based off of the title of the application
384
379
/// </summary>
385
380
/// <param name="path"></param>
386
381
/// <returns> the year/version OR -1 if the year could not be parsed </returns>
387
382
private static int FindDCCVersion ( string AppName )
388
383
{
389
384
int version ;
385
+ string [ ] piecesArray = AppName . Split ( ' ' ) ;
386
+ //Get the number, which is always the last chunk separated by a space.
387
+ string number = piecesArray [ piecesArray . Length - 1 ] ;
390
388
391
- if ( int . TryParse ( AppName , out version ) )
389
+ if ( int . TryParse ( number , out version ) )
392
390
{
393
391
return version ;
394
392
}
395
393
else
396
394
{
395
+ float fVersion ;
396
+ //In case we are looking at a Blender version- the int parse will fail so we'll need to parse it as a float.
397
+ if ( float . TryParse ( number , out fVersion ) )
398
+ {
399
+ return ( int ) fVersion ;
400
+ }
397
401
return - 1 ;
398
402
}
399
403
}
@@ -448,7 +452,7 @@ private static void FindDCCInstalls() {
448
452
dccOptionName . Add ( GetUniqueName ( "3ds Max " + version ) ) ;
449
453
}
450
454
}
451
- instance . selectedDCCApp = instance . FindMostRecentProgram ( ) ;
455
+ instance . selectedDCCApp = instance . FindPreferredProgram ( ) ;
452
456
}
453
457
454
458
/// <summary>
@@ -495,7 +499,7 @@ public static GUIContent[] GetDCCOptions(){
495
499
var dccPath = instance . dccOptionPaths [ i ] ;
496
500
if ( ! File . Exists ( dccPath ) ) {
497
501
if ( i == instance . selectedDCCApp ) {
498
- instance . selectedDCCApp = instance . FindMostRecentProgram ( ) ;
502
+ instance . selectedDCCApp = instance . FindPreferredProgram ( ) ;
499
503
}
500
504
namesToDelete . Add ( instance . dccOptionNames [ i ] ) ;
501
505
pathsToDelete . Add ( dccPath ) ;
0 commit comments