Skip to content

Commit 5dde7a2

Browse files
committed
move MayaLocation code to IntegrationsUI
without the version, no longer need a separate class for just for getting the location
1 parent 402a917 commit 5dde7a2

File tree

2 files changed

+122
-116
lines changed

2 files changed

+122
-116
lines changed

Assets/FbxExporters/Editor/InstallIntegration.cs

Lines changed: 118 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -31,113 +31,6 @@ public MayaException(string message) : base(message) { }
3131
public MayaException(string message, System.Exception inner) : base(message, inner) { }
3232
}
3333

34-
public class MayaLocation {
35-
36-
/// <summary>
37-
/// Find the Maya installation that has your desired version, or
38-
/// the newest version if the 'desired' is an empty string.
39-
///
40-
/// If MAYA_LOCATION is set, the desired version is ignored.
41-
/// </summary>
42-
public MayaLocation(string desiredVersion = "") {
43-
// If the location is given by the environment, use it.
44-
Location = System.Environment.GetEnvironmentVariable ("MAYA_LOCATION");
45-
if (!string.IsNullOrEmpty(Location)) {
46-
Location = Location.TrimEnd('/');
47-
Debug.Log("Using maya set by MAYA_LOCATION: " + Location);
48-
return;
49-
}
50-
51-
// List that directory and find the right version:
52-
// either the newest version, or the exact version we wanted.
53-
string mayaRoot = "";
54-
string bestVersion = "";
55-
var adskRoot = new System.IO.DirectoryInfo(AdskRoot);
56-
foreach(var productDir in adskRoot.GetDirectories()) {
57-
var product = productDir.Name;
58-
59-
// Only accept those that start with 'maya' in either case.
60-
if (!product.StartsWith("maya", StringComparison.InvariantCultureIgnoreCase)) {
61-
continue;
62-
}
63-
// Reject MayaLT -- it doesn't have plugins.
64-
if (product.StartsWith("mayalt", StringComparison.InvariantCultureIgnoreCase)) {
65-
continue;
66-
}
67-
// Parse the version number at the end. Check if it matches,
68-
// or if it's newer than the best so far.
69-
string thisNumber = product.Substring("maya".Length);
70-
if (thisNumber == desiredVersion) {
71-
mayaRoot = product;
72-
bestVersion = thisNumber;
73-
break;
74-
} else if (thisNumber.CompareTo(bestVersion) > 0) {
75-
mayaRoot = product;
76-
bestVersion = thisNumber;
77-
}
78-
}
79-
if (!string.IsNullOrEmpty(desiredVersion) && bestVersion != desiredVersion) {
80-
throw new MayaException(string.Format(
81-
"Unable to find maya {0} in its default installation path. Set MAYA_LOCATION.", desiredVersion));
82-
} else if (string.IsNullOrEmpty(bestVersion)) {
83-
throw new MayaException(string.Format(
84-
"Unable to find any version of maya. Set MAYA_LOCATION."));
85-
}
86-
87-
Location = AdskRoot + "/" + mayaRoot;
88-
if (string.IsNullOrEmpty(desiredVersion)) {
89-
Debug.Log("Using latest version of maya found in: " + Location);
90-
} else {
91-
Debug.Log(string.Format("Using maya {0} found in: {1}", desiredVersion, Location));
92-
}
93-
}
94-
95-
/// <summary>
96-
/// The path where all the different versions of Maya are installed
97-
/// by default. Depends on the platform.
98-
/// </summary>
99-
public const string AdskRoot =
100-
#if UNITY_EDITOR_OSX
101-
"/Applications/Autodesk"
102-
#elif UNITY_EDITOR_LINUX
103-
"/usr/autodesk"
104-
#else // WINDOWS
105-
"C:/Program Files/Autodesk"
106-
#endif
107-
;
108-
109-
/// <summary>
110-
/// The value that you might set MAYA_LOCATION to if you wanted to
111-
/// use this version of Maya.
112-
/// </summary>
113-
public string Location { get; private set; }
114-
115-
/// <summary>
116-
/// The path of the Maya executable.
117-
/// </summary>
118-
public string MayaExe {
119-
get {
120-
#if UNITY_EDITOR_OSX
121-
// MAYA_LOCATION on mac is set by Autodesk to be the
122-
// Contents directory. But let's make it easier on people
123-
// and allow just having it be the app bundle or a
124-
// directory that holds the app bundle.
125-
if (Location.EndsWith(".app/Contents")) {
126-
return Location + "/MacOS/Maya";
127-
} else if (Location.EndsWith(".app")) {
128-
return Location + "/Contents/MacOS/Maya";
129-
} else {
130-
return Location + "/Maya.app/Contents/MacOS/Maya";
131-
}
132-
#elif UNITY_EDITOR_LINUX
133-
return Location + "/bin/maya";
134-
#else // WINDOWS
135-
return Location + "/bin/maya.exe";
136-
#endif
137-
}
138-
}
139-
};
140-
14134
// Use string to define escaped quote
14235
// Windows needs the backslash
14336
#if UNITY_EDITOR_OSX || UNITY_EDITOR_LINUX
@@ -301,12 +194,11 @@ private static void WriteFile(string FileName, List<string> Lines )
301194
}
302195
}
303196

304-
public static int ConfigureMaya(MayaLocation mayaLoc)
197+
public static int ConfigureMaya(string mayaPath)
305198
{
306199
int ExitCode = 0;
307200

308201
try {
309-
string mayaPath = mayaLoc.MayaExe;
310202
if (!System.IO.File.Exists(mayaPath))
311203
{
312204
Debug.LogError (string.Format ("No maya installation found at {0}", mayaPath));
@@ -442,14 +334,129 @@ public static bool InstallMaya(bool verbose = false)
442334

443335
class IntegrationsUI
444336
{
337+
/// <summary>
338+
/// The path where all the different versions of Maya are installed
339+
/// by default. Depends on the platform.
340+
/// </summary>
341+
public const string DefaultAdskRoot =
342+
#if UNITY_EDITOR_OSX
343+
"/Applications/Autodesk"
344+
#elif UNITY_EDITOR_LINUX
345+
"/usr/autodesk"
346+
#else // WINDOWS
347+
"C:/Program Files/Autodesk"
348+
#endif
349+
;
350+
351+
/// <summary>
352+
/// Find the Maya installation that has your desired version, or
353+
/// the newest version if the 'desired' is an empty string.
354+
///
355+
/// If MAYA_LOCATION is set, the desired version is ignored.
356+
/// </summary>
357+
public static string GetMayaLocation(string desiredVersion = "") {
358+
359+
// if there is UI (i.e. we aren't in batchmode), then pop up a dialog
360+
// for the Maya location
361+
if(UnityEditorInternal.InternalEditorUtility.isHumanControllingUs
362+
&& !UnityEditorInternal.InternalEditorUtility.inBatchMode){
363+
364+
return EditorUtility.OpenFolderPanel ("Select Maya Root Folder", DefaultAdskRoot, "");
365+
}
366+
367+
// If the location is given by the environment, use it.
368+
var location = System.Environment.GetEnvironmentVariable ("MAYA_LOCATION");
369+
if (!string.IsNullOrEmpty(location)) {
370+
location = location.TrimEnd('/');
371+
Debug.Log("Using maya set by MAYA_LOCATION: " + location);
372+
return location;
373+
}
374+
375+
// List that directory and find the right version:
376+
// either the newest version, or the exact version we wanted.
377+
string mayaRoot = "";
378+
string bestVersion = "";
379+
var adskRoot = new System.IO.DirectoryInfo(DefaultAdskRoot);
380+
foreach(var productDir in adskRoot.GetDirectories()) {
381+
var product = productDir.Name;
382+
383+
// Only accept those that start with 'maya' in either case.
384+
if (!product.StartsWith("maya", StringComparison.InvariantCultureIgnoreCase)) {
385+
continue;
386+
}
387+
// Reject MayaLT -- it doesn't have plugins.
388+
if (product.StartsWith("mayalt", StringComparison.InvariantCultureIgnoreCase)) {
389+
continue;
390+
}
391+
// Parse the version number at the end. Check if it matches,
392+
// or if it's newer than the best so far.
393+
string thisNumber = product.Substring("maya".Length);
394+
if (thisNumber == desiredVersion) {
395+
mayaRoot = product;
396+
bestVersion = thisNumber;
397+
break;
398+
} else if (thisNumber.CompareTo(bestVersion) > 0) {
399+
mayaRoot = product;
400+
bestVersion = thisNumber;
401+
}
402+
}
403+
if (!string.IsNullOrEmpty(desiredVersion) && bestVersion != desiredVersion) {
404+
throw new Integrations.MayaException(string.Format(
405+
"Unable to find maya {0} in its default installation path. Set MAYA_LOCATION.", desiredVersion));
406+
} else if (string.IsNullOrEmpty(bestVersion)) {
407+
throw new Integrations.MayaException(string.Format(
408+
"Unable to find any version of maya. Set MAYA_LOCATION."));
409+
}
410+
411+
location = DefaultAdskRoot + "/" + mayaRoot;
412+
if (string.IsNullOrEmpty(desiredVersion)) {
413+
Debug.Log("Using latest version of maya found in: " + location);
414+
} else {
415+
Debug.Log(string.Format("Using maya {0} found in: {1}", desiredVersion, location));
416+
}
417+
return location;
418+
}
419+
420+
/// <summary>
421+
/// The path of the Maya executable.
422+
/// </summary>
423+
public static string GetMayaExe (string desiredVersion = "") {
424+
var location = GetMayaLocation (desiredVersion);
425+
if (string.IsNullOrEmpty(location)) {
426+
return null;
427+
}
428+
429+
#if UNITY_EDITOR_OSX
430+
// MAYA_LOCATION on mac is set by Autodesk to be the
431+
// Contents directory. But let's make it easier on people
432+
// and allow just having it be the app bundle or a
433+
// directory that holds the app bundle.
434+
if (location.EndsWith(".app/Contents")) {
435+
return location + "/MacOS/Maya";
436+
} else if (location.EndsWith(".app")) {
437+
return location + "/Contents/MacOS/Maya";
438+
} else {
439+
return location + "/Maya.app/Contents/MacOS/Maya";
440+
}
441+
#elif UNITY_EDITOR_LINUX
442+
return location + "/bin/maya";
443+
#else // WINDOWS
444+
return location + "/bin/maya.exe";
445+
#endif
446+
}
447+
445448
public static void InstallMayaIntegration ()
446449
{
450+
var mayaExe = GetMayaExe ();
451+
if (string.IsNullOrEmpty (mayaExe)) {
452+
return;
453+
}
454+
447455
if (!Integrations.InstallMaya(verbose: true)) {
448456
return;
449457
}
450458

451-
var mayaLoc = new Integrations.MayaLocation();
452-
int exitCode = Integrations.ConfigureMaya (mayaLoc);
459+
int exitCode = Integrations.ConfigureMaya (mayaExe);
453460

454461
string title, message;
455462
if (exitCode != 0) {

Assets/FbxExporters/Editor/UnitTests/IntegrationsTest.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,11 @@ void LogNonEmptyString(string name, string str) {
2828
[Test]
2929
public void BasicTest() {
3030
// Note: This test assumes that Maya is actually installed in a default location.
31-
Assert.IsTrue(Directory.Exists(Editor.Integrations.MayaVersion.AdskRoot));
31+
Assert.IsTrue(Directory.Exists(Editor.IntegrationsUI.DefaultAdskRoot));
3232

33-
var maya = new Editor.Integrations.MayaVersion();
34-
35-
LogNonEmptyString("location", maya.Location);
36-
LogNonEmptyString("binary ", maya.MayaExe);
33+
// test getting the maya location
34+
LogNonEmptyString ("location", Editor.IntegrationsUI.GetMayaLocation ());
35+
LogNonEmptyString ("binary", Editor.IntegrationsUI.GetMayaExe ());
3736

3837
Assert.IsFalse(Editor.Integrations.IsHeadlessInstall());
3938

0 commit comments

Comments
 (0)