Skip to content

Commit 79dfbba

Browse files
authored
Merge pull request #205 from Unity-Technologies/Uni-31021_allow_multiple_vendor_paths
Uni-31021 support for multiple vendor locations
2 parents 72ad319 + 349ce85 commit 79dfbba

File tree

1 file changed

+86
-46
lines changed

1 file changed

+86
-46
lines changed

Assets/FbxExporters/Editor/FbxExportSettings.cs

Lines changed: 86 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public override void OnInspectorGUI() {
121121
throw new System.NotImplementedException ();
122122
}
123123

124-
string dccPath = EditorUtility.OpenFilePanel ("Select Digital Content Creation Application", ExportSettings.kDefaultAdskRoot, ext);
124+
string dccPath = EditorUtility.OpenFilePanel ("Select Digital Content Creation Application", ExportSettings.GetFirstValidVendorLocation(), ext);
125125

126126
// check that the path is valid and references the maya executable
127127
if (!string.IsNullOrEmpty (dccPath)) {
@@ -238,18 +238,37 @@ public class ExportSettings : ScriptableSingleton<ExportSettings>
238238
public const string kBlenderOptionName = "Blender ";
239239

240240
/// <summary>
241-
/// The path where all the different versions of Maya are installed
241+
/// The paths where all the different versions of Maya are installed
242242
/// by default. Depends on the platform.
243243
/// </summary>
244-
public static string kDefaultAdskRoot {
244+
public static string[] DCCVendorLocations {
245245
get{
246-
switch (Application.platform) {
247-
case RuntimePlatform.WindowsEditor:
248-
return "C:/Program Files/Autodesk";
249-
case RuntimePlatform.OSXEditor:
250-
return "/Applications/Autodesk";
251-
default:
252-
throw new NotImplementedException ();
246+
var environmentVariable = Environment.GetEnvironmentVariable("UNITY_FBX_3DAPP_VENDOR_LOCATIONS");
247+
if (environmentVariable != null)
248+
{
249+
string[] locations = environmentVariable.Split(';');
250+
List<string> locationsList = new List<string>();
251+
for (int i = 0; i < locations.Length; i++)
252+
{
253+
if (Directory.Exists(locations[i]))
254+
{
255+
locationsList.Add(locations[i]);
256+
}
257+
}
258+
if (locationsList.Count > 0)
259+
{
260+
return locationsList.ToArray();
261+
}
262+
}
263+
264+
switch (Application.platform)
265+
{
266+
case RuntimePlatform.WindowsEditor:
267+
return new string[] { "C:/Program Files/Autodesk", "D:/Program Files/Autodesk" };
268+
case RuntimePlatform.OSXEditor:
269+
return new string[] { "/Applications/Autodesk" };
270+
default:
271+
throw new NotImplementedException();
253272
}
254273
}
255274
}
@@ -458,53 +477,73 @@ private static void FindDCCInstalls() {
458477
var dccOptionName = instance.dccOptionNames;
459478
var dccOptionPath = instance.dccOptionPaths;
460479

461-
// If the location is given by the environment, use it.
462-
var location = System.Environment.GetEnvironmentVariable ("MAYA_LOCATION");
463-
if (!string.IsNullOrEmpty(location)) {
464-
location = location.TrimEnd('/');
465-
dccOptionPath.Add (GetMayaExePath (location.Replace ("\\", "/")));
466-
dccOptionName.Add ("MAYA_LOCATION");
467-
}
468-
469-
if (!Directory.Exists (kDefaultAdskRoot)) {
470-
// no autodesk products installed
471-
return;
472-
}
473-
// List that directory and find the right version:
474-
// either the newest version, or the exact version we wanted.
475-
var adskRoot = new System.IO.DirectoryInfo(kDefaultAdskRoot);
476-
foreach(var productDir in adskRoot.GetDirectories()) {
477-
var product = productDir.Name;
480+
for (int i = 0; i < DCCVendorLocations.Length; i++)
481+
{
482+
if (!Directory.Exists(DCCVendorLocations[i]))
483+
{
484+
// no autodesk products installed
485+
continue;
486+
}
487+
// List that directory and find the right version:
488+
// either the newest version, or the exact version we wanted.
489+
var adskRoot = new System.IO.DirectoryInfo(DCCVendorLocations[i]);
490+
foreach (var productDir in adskRoot.GetDirectories())
491+
{
492+
var product = productDir.Name;
478493

479-
// Only accept those that start with 'maya' in either case.
480-
if (product.StartsWith ("maya", StringComparison.InvariantCultureIgnoreCase)) {
481-
// UNI-29074 TODO: add Maya LT support
482-
// Reject MayaLT -- it doesn't have plugins.
483-
if (product.StartsWith ("mayalt", StringComparison.InvariantCultureIgnoreCase)) {
484-
continue;
494+
// Only accept those that start with 'maya' in either case.
495+
if (product.StartsWith("maya", StringComparison.InvariantCultureIgnoreCase))
496+
{
497+
// UNI-29074 TODO: add Maya LT support
498+
// Reject MayaLT -- it doesn't have plugins.
499+
if (product.StartsWith("mayalt", StringComparison.InvariantCultureIgnoreCase))
500+
{
501+
continue;
502+
}
503+
string version = product.Substring("maya".Length);
504+
dccOptionPath.Add(GetMayaExePath(productDir.FullName.Replace("\\", "/")));
505+
dccOptionName.Add(GetUniqueDCCOptionName(kMayaOptionName + version));
485506
}
486-
string version = product.Substring ("maya".Length);
487-
dccOptionPath.Add (GetMayaExePath (productDir.FullName.Replace ("\\", "/")));
488-
dccOptionName.Add (GetUniqueDCCOptionName(kMayaOptionName + version));
489-
}
490507

491-
if (product.StartsWith ("3ds max", StringComparison.InvariantCultureIgnoreCase)) {
492-
var exePath = string.Format ("{0}/{1}", productDir.FullName.Replace ("\\", "/"), "3dsmax.exe");
508+
if (product.StartsWith("3ds max", StringComparison.InvariantCultureIgnoreCase))
509+
{
510+
var exePath = string.Format("{0}/{1}", productDir.FullName.Replace("\\", "/"), "3dsmax.exe");
511+
512+
string version = product.Substring("3ds max ".Length);
513+
var maxOptionName = GetUniqueDCCOptionName(kMaxOptionName + version);
493514

494-
string version = product.Substring("3ds max ".Length);
495-
var maxOptionName = GetUniqueDCCOptionName(kMaxOptionName + version);
515+
if (IsEarlierThanMax2017(maxOptionName))
516+
{
517+
continue;
518+
}
496519

497-
if (IsEarlierThanMax2017 (maxOptionName)) {
498-
continue;
520+
dccOptionPath.Add(exePath);
521+
dccOptionName.Add(maxOptionName);
499522
}
500-
501-
dccOptionPath.Add (exePath);
502-
dccOptionName.Add (maxOptionName);
503523
}
504524
}
505525
instance.selectedDCCApp = instance.GetPreferredDCCApp();
506526
}
507527

528+
/// <summary>
529+
/// Returns the first valid folder in our list of vendor locations
530+
/// </summary>
531+
/// <returns>The first valid vendor location</returns>
532+
public static string GetFirstValidVendorLocation()
533+
{
534+
string[] locations = DCCVendorLocations;
535+
for (int i = 0; i < locations.Length; i++)
536+
{
537+
//Look through the list of locations we have and take the first valid one
538+
if (Directory.Exists(locations[i]))
539+
{
540+
return locations[i];
541+
}
542+
}
543+
//if no valid locations exist, just take us to the project folder
544+
return Directory.GetCurrentDirectory();
545+
}
546+
508547
/// <summary>
509548
/// Gets the maya exe at Maya install location.
510549
/// </summary>
@@ -563,6 +602,7 @@ public static GUIContent[] GetDCCOptions(){
563602
}
564603

565604
if (instance.dccOptionPaths.Count <= 0) {
605+
instance.selectedDCCApp = 0;
566606
return new GUIContent[]{
567607
new GUIContent("<No 3D Application found>")
568608
};

0 commit comments

Comments
 (0)