Skip to content

Commit 476303f

Browse files
authored
Merge pull request #260 from Unity-Technologies/Uni-33810_handle_MayaLT_in_preferred3DApp
Uni-33810 Handle MayaLT in GetPreferredDCCApp()
2 parents 2c9e40a + e4b8990 commit 476303f

File tree

2 files changed

+48
-6
lines changed

2 files changed

+48
-6
lines changed

Assets/FbxExporters/Editor/FbxExportSettings.cs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ public class ExportSettings : ScriptableSingleton<ExportSettings>
281281
//Any additional names require a space after the name
282282
public const string kMaxOptionName = "3ds Max ";
283283
public const string kMayaOptionName = "Maya ";
284-
public const string kMayaLtOptionName = "MayaLT ";
284+
public const string kMayaLtOptionName = "Maya LT";
285285

286286
private static string DefaultIntegrationSavePath {
287287
get{
@@ -590,13 +590,22 @@ private int ChoosePreferredDCCApp(int optionA, int optionB)
590590
return -1;
591591
}
592592

593-
//We assume that the option names have a
594-
int scoreA = s_PreferenceList.IndexOf(appA.Split(' ')[0]);
595-
int scoreB = s_PreferenceList.IndexOf(appB.Split(' ')[0]);
593+
int scoreA = s_PreferenceList.FindIndex(app => RemoveSpacesAndNumbers(app).Equals(RemoveSpacesAndNumbers(appA)));
594+
595+
int scoreB = s_PreferenceList.FindIndex(app => RemoveSpacesAndNumbers(app).Equals(RemoveSpacesAndNumbers(appB)));
596596

597597
return scoreA < scoreB ? optionA : optionB;
598598
}
599599

600+
/// <summary>
601+
/// Takes a given string and removes any spaces or numbers from it
602+
/// </summary>
603+
/// <param name="s"></param>
604+
public static string RemoveSpacesAndNumbers(string s)
605+
{
606+
return System.Text.RegularExpressions.Regex.Replace(s, @"[\s^0-9]", "");
607+
}
608+
600609
/// <summary>
601610
/// Finds the version based off of the title of the application
602611
/// </summary>
@@ -627,11 +636,20 @@ private static int FindDCCVersion(string AppName)
627636
}
628637
else
629638
{
639+
//remove any letters in the string in a final attempt to extract an int from it (this will happen with MayaLT, for example)
640+
string AppNameCopy = AppName;
641+
string stringWithoutLetters = System.Text.RegularExpressions.Regex.Replace(AppNameCopy, "[^0-9]", "");
642+
643+
if (int.TryParse(stringWithoutLetters, out version))
644+
{
645+
return version;
646+
}
647+
630648
float fVersion;
631649
//In case we are looking at something with a decimal based version- the int parse will fail so we'll need to parse it as a float.
632650
if (float.TryParse(number, out fVersion))
633651
{
634-
return (int)fVersion;
652+
return (int)fVersion;
635653
}
636654
return -1;
637655
}

Assets/FbxExporters/Editor/UnitTests/FbxExportSettingsTest.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,31 @@ public void TestFindPreferredProgram ()
216216
//Try running it with a null list
217217
preferred = ExportSettings.instance.GetPreferredDCCApp ();
218218

219-
Assert.AreEqual (preferred, -1);
219+
Assert.AreEqual(preferred, -1);
220+
221+
//Testing the results of only having a mayaLT install
222+
ExportSettings.instance.SetDCCOptionNames(new List<string> { ExportSettings.kMayaLtOptionName + "2018" }); //hardcoded because the constant is changed in another branch but not this one at this time
223+
preferred = ExportSettings.instance.GetPreferredDCCApp();
224+
225+
Assert.AreEqual(preferred, 0);
226+
227+
//Testing the results of only having a maya install
228+
ExportSettings.instance.SetDCCOptionNames(new List<string> { ExportSettings.kMayaOptionName + "2018" });
229+
preferred = ExportSettings.instance.GetPreferredDCCApp();
230+
231+
Assert.AreEqual(preferred, 0);
232+
233+
//Testing the results of only having a max install
234+
ExportSettings.instance.SetDCCOptionNames(new List<string> { ExportSettings.kMaxOptionName + "2018" });
235+
preferred = ExportSettings.instance.GetPreferredDCCApp();
236+
237+
Assert.AreEqual(preferred, 0);
238+
239+
//Testing the preference priority
240+
ExportSettings.instance.SetDCCOptionNames(new List<string> { ExportSettings.kMaxOptionName + "2018", ExportSettings.kMayaOptionName + "2018", ExportSettings.kMayaLtOptionName + "2018" });
241+
preferred = ExportSettings.instance.GetPreferredDCCApp();
242+
243+
Assert.AreEqual(preferred, 1);
220244
}
221245

222246
[Test]

0 commit comments

Comments
 (0)