Skip to content

Commit 7381ff8

Browse files
author
AJubrey
committed
[CHANGED] the DCCOptionNames list to public and adjusted the test case to reflect that
[ADDED] clear() and set() functions for the DCCOptionNames list
1 parent 8b62476 commit 7381ff8

File tree

2 files changed

+65
-32
lines changed

2 files changed

+65
-32
lines changed

Assets/FbxExporters/Editor/FbxExportSettings.cs

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,12 @@ private static string TryFindDCC(string dccPath, string ext, ExportSettings.DCCT
226226
public class ExportSettings : ScriptableSingleton<ExportSettings>
227227
{
228228
public const string kDefaultSavePath = ".";
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 ";
229+
private static List<string> s_PreferenceList = new List<string>() {kMayaOptionName, kMayaLtOptionName, kMaxOptionName, kBlenderOptionName };
230+
//Any additional names require a space after the name
231+
public const string kMaxOptionName = "3ds Max ";
232+
public const string kMayaOptionName = "Maya ";
233+
public const string kMayaLtOptionName = "MayaLT ";
234+
public const string kBlenderOptionName = "Blender ";
232235

233236
/// <summary>
234237
/// The path where all the different versions of Maya are installed
@@ -268,10 +271,10 @@ public static string kDefaultAdskRoot {
268271

269272
// List of names in order that they appear in option list
270273
[SerializeField]
271-
public List<string> dccOptionNames;
274+
private List<string> dccOptionNames = new List<string>();
272275
// List of paths in order that they appear in the option list
273276
[SerializeField]
274-
public List<string> dccOptionPaths;
277+
private List<string> dccOptionPaths;
275278

276279
protected override void LoadDefaults()
277280
{
@@ -287,7 +290,12 @@ protected override void LoadDefaults()
287290
/// </summary>
288291
/// <returns>The unique name.</returns>
289292
/// <param name="name">Name.</param>
290-
public static string GetUniqueName(string name){
293+
public static string GetUniqueDCCOptionName(string name){
294+
Debug.Assert(instance != null);
295+
if (name == null)
296+
{
297+
return null;
298+
}
291299
if (!instance.dccOptionNames.Contains(name)) {
292300
return name;
293301
}
@@ -314,6 +322,16 @@ public static string GetUniqueName(string name){
314322
return uniqueName;
315323
}
316324

325+
public void SetDCCOptionNames(List<string> newList)
326+
{
327+
dccOptionNames = newList;
328+
}
329+
330+
public void ClearDCCOptionNames()
331+
{
332+
dccOptionNames.Clear();
333+
}
334+
317335
/// <summary>
318336
///
319337
/// Find the latest program available and make that the default choice.
@@ -335,6 +353,10 @@ public int GetPreferredDCCApp()
335353
for (int i = 0; i < dccOptionNames.Count; i++)
336354
{
337355
int versionToCheck = FindDCCVersion(dccOptionNames[i]);
356+
if (versionToCheck == -1)
357+
{
358+
continue;
359+
}
338360
if (versionToCheck > newestDCCVersionNumber)
339361
{
340362
newestDCCVersionIndex = i;
@@ -362,16 +384,23 @@ public int GetPreferredDCCApp()
362384
/// <returns></returns>
363385
private int ChoosePreferredDCCApp(int optionA, int optionB)
364386
{
365-
int scoreA = s_PreferenceList.IndexOf(GetAppNameFromFolderName(dccOptionNames[optionA]));
366-
int scoreB = s_PreferenceList.IndexOf(GetAppNameFromFolderName(dccOptionNames[optionB]));
387+
Debug.Assert(optionA >= 0 && optionB >= 0 && optionA < dccOptionNames.Count && optionB < dccOptionNames.Count);
388+
if (dccOptionNames.Count == 0)
389+
{
390+
return -1;
391+
}
392+
var appA = dccOptionNames[optionA];
393+
var appB = dccOptionNames[optionB];
394+
if (appA == null || appB == null || appA.Length <= 0 || appB.Length <= 0)
395+
{
396+
return -1;
397+
}
367398

368-
return scoreA < scoreB ? optionA : optionB;
369-
}
399+
//We assume that the option names have a
400+
int scoreA = s_PreferenceList.IndexOf(appA.Split(' ')[0]);
401+
int scoreB = s_PreferenceList.IndexOf(appB.Split(' ')[0]);
370402

371-
///
372-
private string GetAppNameFromFolderName(string originalString)
373-
{
374-
return originalString.ToLower().Split(' ')[0];
403+
return scoreA < scoreB ? optionA : optionB;
375404
}
376405

377406
/// <summary>
@@ -448,7 +477,7 @@ private static void FindDCCInstalls() {
448477
}
449478
string version = product.Substring ("maya".Length);
450479
dccOptionPath.Add (GetMayaExePath (productDir.FullName.Replace ("\\", "/")));
451-
dccOptionName.Add (GetUniqueName (s_MayaName + version));
480+
dccOptionName.Add (GetUniqueDCCOptionName(kMayaOptionName + version));
452481
}
453482

454483
if (product.StartsWith ("3ds max", StringComparison.InvariantCultureIgnoreCase)) {
@@ -458,7 +487,7 @@ private static void FindDCCInstalls() {
458487
}
459488
string version = product.Substring ("3ds max ".Length);
460489
dccOptionPath.Add (exePath);
461-
dccOptionName.Add (GetUniqueName (s_MaxName + version));
490+
dccOptionName.Add (GetUniqueDCCOptionName(kMaxOptionName + version));
462491
}
463492
}
464493
instance.selectedDCCApp = instance.GetPreferredDCCApp();
@@ -565,7 +594,7 @@ public static void AddDCCOption(string newOption, DCCType dcc){
565594
Debug.LogError (string.Format("Unity Integration does not support Maya LT: \"{0}\"", newOption));
566595
return;
567596
}
568-
optionName = GetUniqueName ("Maya " + version);
597+
optionName = GetUniqueDCCOptionName("Maya " + version);
569598
break;
570599
case DCCType.Max:
571600
optionName = GetMaxOptionName (newOption);
@@ -608,7 +637,7 @@ static string AskMayaVersion(string exePath) {
608637
/// <returns>The 3DsMax dropdown option label.</returns>
609638
/// <param name="exePath">Exe path.</param>
610639
public static string GetMaxOptionName(string exePath){
611-
return GetUniqueName (Path.GetFileName(Path.GetDirectoryName (exePath)));
640+
return GetUniqueDCCOptionName(Path.GetFileName(Path.GetDirectoryName (exePath)));
612641
}
613642

614643
public static bool IsEarlierThanMax2017(string AppName){

Assets/FbxExporters/Editor/UnitTests/FbxExportSettingsTest.cs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -183,34 +183,38 @@ public void TestGetSetFields()
183183
public void TestFindPreferredProgram()
184184
{
185185
//Add a number of fake programs to the list, including some garbage ones
186-
ExportSettings.instance.dccOptionNames = new List<string>();
187-
ExportSettings.instance.dccOptionNames.Add(ExportSettings.GetUniqueName(ExportSettings.s_MaxName + "2000"));
188-
ExportSettings.instance.dccOptionNames.Add(ExportSettings.GetUniqueName(ExportSettings.s_MayaName + "2016"));
189-
ExportSettings.instance.dccOptionNames.Add(ExportSettings.GetUniqueName(ExportSettings.s_MayaName + "2017"));
190-
ExportSettings.instance.dccOptionNames.Add(ExportSettings.GetUniqueName(ExportSettings.s_MaxName + "2017"));
191-
ExportSettings.instance.dccOptionNames.Add(ExportSettings.GetUniqueName("Blender " + "2.67"));
192-
ExportSettings.instance.dccOptionNames.Add(ExportSettings.GetUniqueName(""));
193-
ExportSettings.instance.dccOptionNames.Add(ExportSettings.GetUniqueName(null));
194-
ExportSettings.instance.dccOptionNames.Add(ExportSettings.GetUniqueName(ExportSettings.s_MayaName + "lt"));
195-
ExportSettings.instance.dccOptionNames.Add(ExportSettings.GetUniqueName(ExportSettings.s_MayaName + "2017"));
186+
List<string> testList = new List<string>();
187+
testList.Add(null);
188+
testList.Add(ExportSettings.GetUniqueDCCOptionName(ExportSettings.kMaxOptionName + "2000"));
189+
testList.Add(ExportSettings.GetUniqueDCCOptionName(ExportSettings.kMayaOptionName + "2016"));
190+
testList.Add(ExportSettings.GetUniqueDCCOptionName(ExportSettings.kMayaOptionName + "2017"));
191+
testList.Add(ExportSettings.GetUniqueDCCOptionName(ExportSettings.kMaxOptionName + "2017"));
192+
testList.Add(ExportSettings.GetUniqueDCCOptionName(ExportSettings.kBlenderOptionName + "2.67"));
193+
testList.Add(ExportSettings.GetUniqueDCCOptionName(""));
194+
testList.Add(ExportSettings.GetUniqueDCCOptionName(null));
195+
testList.Add(ExportSettings.GetUniqueDCCOptionName(ExportSettings.kMayaLtOptionName));
196+
testList.Add(ExportSettings.GetUniqueDCCOptionName(ExportSettings.kMayaOptionName + "2017"));
197+
198+
ExportSettings.instance.SetDCCOptionNames(testList);
196199

197200
int preferred = ExportSettings.instance.GetPreferredDCCApp();
198201
//While Maya 2017 and 3ds Max 2017 are tied for most recent, Maya 2017 should win because we prefer Maya.
199-
Assert.AreEqual(preferred, 2);
202+
Assert.AreEqual(preferred, 9);
200203

201-
ExportSettings.instance.dccOptionNames = new List<string> { "Blender 2.67", "Blender 3.0" };
204+
List<string> blenderList = new List<string> { "Blender 2.67", "Blender 3.0" };
205+
ExportSettings.instance.SetDCCOptionNames(blenderList);
202206

203207
preferred = ExportSettings.instance.GetPreferredDCCApp();
204208
//The function should be able to deal with floats well enough to give us a preferred version of soemthing like blender, which does not use the year.
205209
Assert.AreEqual(preferred, 1);
206210

207-
ExportSettings.instance.dccOptionNames.Clear();
211+
ExportSettings.instance.ClearDCCOptionNames();
208212
//Try running it with an empty list
209213
preferred = ExportSettings.instance.GetPreferredDCCApp();
210214

211215
Assert.AreEqual(preferred, -1);
212216

213-
ExportSettings.instance.dccOptionNames = null;
217+
ExportSettings.instance.SetDCCOptionNames(null);
214218
//Try running it with a null list
215219
preferred = ExportSettings.instance.GetPreferredDCCApp();
216220

0 commit comments

Comments
 (0)