Skip to content

Commit cf0d1b1

Browse files
author
AJubrey
committed
[CHANGED] broke up and decoupled a lot of the vendor location code
1 parent 33db5c5 commit cf0d1b1

File tree

1 file changed

+87
-104
lines changed

1 file changed

+87
-104
lines changed

Assets/FbxExporters/Editor/FbxExportSettings.cs

Lines changed: 87 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using UnityEngine;
55
using UnityEditor;
66
using System.Collections.Generic;
7+
using System.Linq;
78

89
namespace FbxExporters.EditorTools {
910

@@ -251,131 +252,113 @@ private static string DefaultIntegrationSavePath {
251252
}
252253
}
253254

254-
/// <summary>
255-
/// The paths where all the different versions of Maya are installed
256-
/// by default. Depends on the platform.
257-
/// </summary>
258-
public static string[] DCCVendorLocations {
259-
get{
260-
var environmentVariable = Environment.GetEnvironmentVariable("UNITY_FBX_3DAPP_VENDOR_LOCATIONS");
261-
List<string> locationsList = new List<string>();
262-
List<string> WindowsDefaultLocations = new List<string>() { "C:/Program Files/Autodesk", "D:/Program Files/Autodesk" };
263-
List<string> OSXDefaultLocations = new List<string>() { "/Applications/Autodesk" };
264-
bool foundVendorLocation = false;
255+
private static string GetVendorLocationFromEnv(string env)
256+
{
257+
string result = null;
258+
259+
if (string.IsNullOrEmpty(env))
260+
return null;
261+
262+
string location = Environment.GetEnvironmentVariable(env);
263+
264+
if (string.IsNullOrEmpty(location))
265+
return null;
266+
267+
if (!Directory.Exists(location))
268+
return null;
269+
270+
//Remove any extra slashes on the end
271+
//Maya would accept a single slash in either direction, so we should be able to
272+
location = location.Replace("\\", "/");
273+
location.TrimEnd('/');
274+
275+
if (Application.platform == RuntimePlatform.WindowsEditor)
276+
{
277+
//If we are on Windows, we need only go up one location to get to the "Autodesk" folder.
278+
result = Directory.GetParent(location).ToString();
279+
}
280+
else if (Application.platform == RuntimePlatform.OSXEditor)
281+
{
282+
//We can assume our path is: /Applications/Autodesk/maya2017/Maya.app/Contents
283+
//So we need to go up three folders.
265284

266-
if (environmentVariable != null)
285+
var appFolder = Directory.GetParent(location);
286+
if (appFolder != null)
267287
{
268-
string[] locations = environmentVariable.Split(';');
269-
for (int i = 0; i < locations.Length; i++)
288+
var versionFolder = Directory.GetParent(appFolder.ToString());
289+
if (versionFolder != null)
270290
{
271-
if (Directory.Exists(locations[i]))
291+
var autoDeskFolder = Directory.GetParent(versionFolder.ToString());
292+
if (autoDeskFolder != null)
272293
{
273-
locationsList.Add(locations[i]);
294+
result = autoDeskFolder.ToString();
274295
}
275296
}
276-
//If we found anything, just return the list
277-
if (locationsList.Count > 0)
278-
{
279-
foundVendorLocation = true;
280-
}
281297
}
298+
}
282299

283-
var location = System.Environment.GetEnvironmentVariable("MAYA_LOCATION");
284-
if (!string.IsNullOrEmpty(location))
285-
{
286-
string possibleLocation = null;
287-
if (Application.platform == RuntimePlatform.WindowsEditor)
288-
{
289-
//If we are on Windows, we need only go up one location to get to the "Autodesk" folder.
290-
if (Directory.GetParent(location) != null)
291-
{
292-
//'Directory.GetParent()' will take care of any double backslashes the user may have added
293-
possibleLocation = Directory.GetParent(location).ToString();
294-
295-
//We only need to remove duplicates of default locations if we are using the default locations-
296-
//We only use default locations if we do not use the user specified vendor locations
297-
if (!foundVendorLocation)
298-
{
299-
//Make sure the user defined path is not included in the default paths
300-
for (int i = 0; i < WindowsDefaultLocations.Count; i++)
301-
{
302-
//we don't want a minute difference in slashes or capitalization to throw off our check
303-
if (WindowsDefaultLocations[i] != null &&
304-
possibleLocation != null &&
305-
WindowsDefaultLocations[i].Replace("\\", "/").ToLower().Equals(possibleLocation.Replace("\\", "/").ToLower()))
306-
{
307-
possibleLocation = null;
308-
break;
309-
}
310-
}
311-
}
312-
}
313-
}
314-
else if (Application.platform == RuntimePlatform.OSXEditor)
315-
{
316-
//We can assume our path is: /Applications/Autodesk/maya2017/Maya.app/Contents
317-
//So we need to go up three folders.
300+
return result;
301+
}
318302

319-
//Remove any extra slashes on the end
320-
//Maya would accept a single slash in either direction, so we should be able to
321-
location.TrimEnd('/');
322-
location.TrimEnd('\\');
303+
// Returns a set of valid vendor folder paths with no trailing '/'
304+
private static HashSet<string> GetCustomVendorLocations()
305+
{
306+
HashSet<string> result = new HashSet<string>();
323307

324-
var appFolder = Directory.GetParent(location);
325-
if (appFolder != null)
326-
{
327-
var versionFolder = Directory.GetParent(appFolder.ToString());
328-
if (versionFolder != null)
329-
{
330-
var autoDeskFolder = Directory.GetParent(versionFolder.ToString());
331-
if (autoDeskFolder != null)
332-
{
333-
possibleLocation = autoDeskFolder.ToString();
334-
335-
//Make sure the user defined path is not included in the default paths
336-
for (int i = 0; i < OSXDefaultLocations.Count; i++)
337-
{
338-
//we don't want a minute difference in slashes or capitalization to throw off our check
339-
if (OSXDefaultLocations[i].Replace("\\", "/").ToLower().Equals(possibleLocation.Replace("\\", "/").ToLower()))
340-
{
341-
possibleLocation = null;
342-
continue;
343-
}
344-
}
345-
}
346-
}
347-
}
348-
}
349-
else
350-
{
351-
throw new NotImplementedException();
352-
}
308+
var environmentVariable = Environment.GetEnvironmentVariable("UNITY_FBX_3DAPP_VENDOR_LOCATIONS");
353309

354-
if (!string.IsNullOrEmpty(possibleLocation) && Directory.Exists(possibleLocation))
310+
if (!string.IsNullOrEmpty(environmentVariable))
311+
{
312+
string[] locations = environmentVariable.Split(';');
313+
for (int i = 0; i < locations.Length; i++)
314+
{
315+
if (Directory.Exists(locations[i]))
355316
{
356-
locationsList.Add(possibleLocation.ToString());
317+
result.Add(locations[i]);
357318
}
358319
}
320+
}
321+
322+
323+
return result;
324+
}
359325

360-
if (foundVendorLocation)
326+
private static HashSet<string> GetDefaultVendorLocations()
327+
{
328+
if (Application.platform == RuntimePlatform.WindowsEditor)
329+
return new HashSet<string>() { "C:/Program Files/Autodesk", "D:/Program Files/Autodesk" };
330+
else if (Application.platform == RuntimePlatform.OSXEditor)
331+
return new HashSet<string>() { "/Applications/Autodesk" };
332+
333+
throw new NotImplementedException();
334+
}
335+
336+
/// <summary>
337+
/// Retrieve available vendor locations.
338+
/// If there is valid alternative vendor locations, do not use defaults
339+
/// always use MAYA_LOCATION when available
340+
/// </summary>
341+
public static string[] DCCVendorLocations
342+
{
343+
get
344+
{
345+
HashSet<string> result = GetCustomVendorLocations();
346+
347+
if (result == null || result.Count < 1)
361348
{
362-
return locationsList.ToArray();
349+
result = GetDefaultVendorLocations();
363350
}
364351

365-
switch (Application.platform)
352+
var additionalLocation = GetVendorLocationFromEnv("MAYA_LOCATION");
353+
354+
if (!string.IsNullOrEmpty(additionalLocation))
366355
{
367-
case RuntimePlatform.WindowsEditor:
368-
locationsList.AddRange(WindowsDefaultLocations);
369-
break;
370-
case RuntimePlatform.OSXEditor:
371-
locationsList.AddRange(OSXDefaultLocations);
372-
break;
373-
default:
374-
throw new NotImplementedException();
356+
result.Add(additionalLocation);
375357
}
376-
return locationsList.ToArray();
358+
359+
return result.ToArray<string>();
377360
}
378-
}
361+
}
379362

380363
// Note: default values are set in LoadDefaults().
381364
public bool mayaCompatibleNames = true;

0 commit comments

Comments
 (0)