Skip to content

Commit 0568d7e

Browse files
author
AJubrey
committed
[ADDED] support for multiple vendor locations and choosing a specified path based on an environment variable
1 parent 51ea6a0 commit 0568d7e

File tree

1 file changed

+59
-47
lines changed

1 file changed

+59
-47
lines changed

Assets/FbxExporters/Editor/FbxExportSettings.cs

Lines changed: 59 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public override void OnInspectorGUI() {
111111
throw new System.NotImplementedException ();
112112
}
113113

114-
string dccPath = EditorUtility.OpenFilePanel ("Select Digital Content Creation Application", ExportSettings.kDefaultAdskRoot, ext);
114+
string dccPath = EditorUtility.OpenFilePanel ("Select Digital Content Creation Application", ExportSettings.DCCVendorLocations()[0], ext);
115115

116116
// check that the path is valid and references the maya executable
117117
if (!string.IsNullOrEmpty (dccPath)) {
@@ -226,20 +226,31 @@ public class ExportSettings : ScriptableSingleton<ExportSettings>
226226
public const string kBlenderOptionName = "Blender ";
227227

228228
/// <summary>
229-
/// The path where all the different versions of Maya are installed
229+
/// The paths where all the different versions of Maya are installed
230230
/// by default. Depends on the platform.
231231
/// </summary>
232-
public static string kDefaultAdskRoot {
233-
get{
234-
switch (Application.platform) {
235-
case RuntimePlatform.WindowsEditor:
236-
return "C:/Program Files/Autodesk";
237-
case RuntimePlatform.OSXEditor:
238-
return "/Applications/Autodesk";
239-
default:
240-
throw new NotImplementedException ();
232+
public static string[] DCCVendorLocations() {
233+
234+
if (Environment.GetEnvironmentVariable("UNITY_FBX_3DAPP_VENDOR_LOCATIONS") != null)
235+
{
236+
string[] locations = Environment.GetEnvironmentVariable("UNITY_FBX_3DAPP_VENDOR_LOCATIONS").Split(';');
237+
for (int i = 0; i < locations.Length; i++)
238+
{
239+
if (Directory.Exists(locations[i]))
240+
{
241+
return locations;
242+
}
241243
}
242244
}
245+
246+
switch (Application.platform) {
247+
case RuntimePlatform.WindowsEditor:
248+
return new string[]{ "C:/Program Files/Autodesk", "D:/Program Files/Autodesk" };
249+
case RuntimePlatform.OSXEditor:
250+
return new string[]{ "/Applications/Autodesk" };
251+
default:
252+
throw new NotImplementedException ();
253+
}
243254
}
244255

245256
// Note: default values are set in LoadDefaults().
@@ -444,48 +455,49 @@ private static void FindDCCInstalls() {
444455
var dccOptionName = instance.dccOptionNames;
445456
var dccOptionPath = instance.dccOptionPaths;
446457

447-
// If the location is given by the environment, use it.
448-
var location = System.Environment.GetEnvironmentVariable ("MAYA_LOCATION");
449-
if (!string.IsNullOrEmpty(location)) {
450-
location = location.TrimEnd('/');
451-
dccOptionPath.Add (GetMayaExePath (location.Replace ("\\", "/")));
452-
dccOptionName.Add ("MAYA_LOCATION");
453-
}
454-
455-
if (!Directory.Exists (kDefaultAdskRoot)) {
456-
// no autodesk products installed
457-
return;
458-
}
459-
// List that directory and find the right version:
460-
// either the newest version, or the exact version we wanted.
461-
var adskRoot = new System.IO.DirectoryInfo(kDefaultAdskRoot);
462-
foreach(var productDir in adskRoot.GetDirectories()) {
463-
var product = productDir.Name;
458+
for (int i = 0; i < DCCVendorLocations().Length; i++)
459+
{
460+
if (!Directory.Exists(DCCVendorLocations()[0]))
461+
{
462+
// no autodesk products installed
463+
continue;
464+
}
465+
// List that directory and find the right version:
466+
// either the newest version, or the exact version we wanted.
467+
var adskRoot = new System.IO.DirectoryInfo(DCCVendorLocations()[i]);
468+
foreach (var productDir in adskRoot.GetDirectories())
469+
{
470+
var product = productDir.Name;
464471

465-
// Only accept those that start with 'maya' in either case.
466-
if (product.StartsWith ("maya", StringComparison.InvariantCultureIgnoreCase)) {
467-
// UNI-29074 TODO: add Maya LT support
468-
// Reject MayaLT -- it doesn't have plugins.
469-
if (product.StartsWith ("mayalt", StringComparison.InvariantCultureIgnoreCase)) {
470-
continue;
472+
// Only accept those that start with 'maya' in either case.
473+
if (product.StartsWith("maya", StringComparison.InvariantCultureIgnoreCase))
474+
{
475+
// UNI-29074 TODO: add Maya LT support
476+
// Reject MayaLT -- it doesn't have plugins.
477+
if (product.StartsWith("mayalt", StringComparison.InvariantCultureIgnoreCase))
478+
{
479+
continue;
480+
}
481+
string version = product.Substring("maya".Length);
482+
dccOptionPath.Add(GetMayaExePath(productDir.FullName.Replace("\\", "/")));
483+
dccOptionName.Add(GetUniqueDCCOptionName(kMayaOptionName + version));
471484
}
472-
string version = product.Substring ("maya".Length);
473-
dccOptionPath.Add (GetMayaExePath (productDir.FullName.Replace ("\\", "/")));
474-
dccOptionName.Add (GetUniqueDCCOptionName(kMayaOptionName + version));
475-
}
476485

477-
if (product.StartsWith ("3ds max", StringComparison.InvariantCultureIgnoreCase)) {
478-
var exePath = string.Format ("{0}/{1}", productDir.FullName.Replace ("\\", "/"), "3dsmax.exe");
486+
if (product.StartsWith("3ds max", StringComparison.InvariantCultureIgnoreCase))
487+
{
488+
var exePath = string.Format("{0}/{1}", productDir.FullName.Replace("\\", "/"), "3dsmax.exe");
479489

480-
string version = product.Substring("3ds max ".Length);
481-
var maxOptionName = GetUniqueDCCOptionName(kMaxOptionName + version);
490+
string version = product.Substring("3ds max ".Length);
491+
var maxOptionName = GetUniqueDCCOptionName(kMaxOptionName + version);
482492

483-
if (IsEarlierThanMax2017 (maxOptionName)) {
484-
continue;
493+
if (IsEarlierThanMax2017(maxOptionName))
494+
{
495+
continue;
496+
}
497+
498+
dccOptionPath.Add(exePath);
499+
dccOptionName.Add(maxOptionName);
485500
}
486-
487-
dccOptionPath.Add (exePath);
488-
dccOptionName.Add (maxOptionName);
489501
}
490502
}
491503
instance.selectedDCCApp = instance.GetPreferredDCCApp();

0 commit comments

Comments
 (0)