Skip to content

Commit e05e53e

Browse files
committed
add function to find default maya installs
1 parent 1b9fe89 commit e05e53e

File tree

1 file changed

+41
-5
lines changed

1 file changed

+41
-5
lines changed

Assets/FbxExporters/Editor/FbxExportSettings.cs

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,49 @@ protected override void LoadDefaults()
200200
mayaAppOptions = null;
201201
}
202202

203+
/// <summary>
204+
/// Find Maya installations at default install path.
205+
/// Add results to given dictionary.
206+
///
207+
/// If MAYA_LOCATION is set, add this to the list as well.
208+
/// </summary>
209+
private static System.Collections.Generic.Dictionary<string, string> FindMayaInstalls() {
210+
System.Collections.Generic.Dictionary<string, string> mayaAppOptions =
211+
new System.Collections.Generic.Dictionary<string, string> ();
212+
213+
// If the location is given by the environment, use it.
214+
var location = System.Environment.GetEnvironmentVariable ("MAYA_LOCATION");
215+
if (!string.IsNullOrEmpty(location)) {
216+
location = location.TrimEnd('/');
217+
mayaAppOptions.Add (location, "MAYA_LOCATION");
218+
}
219+
220+
// List that directory and find the right version:
221+
// either the newest version, or the exact version we wanted.
222+
var adskRoot = new System.IO.DirectoryInfo(kDefaultAdskRoot);
223+
foreach(var productDir in adskRoot.GetDirectories()) {
224+
var product = productDir.Name;
225+
226+
// Only accept those that start with 'maya' in either case.
227+
if (!product.StartsWith("maya", StringComparison.InvariantCultureIgnoreCase)) {
228+
continue;
229+
}
230+
// Reject MayaLT -- it doesn't have plugins.
231+
if (product.StartsWith("mayalt", StringComparison.InvariantCultureIgnoreCase)) {
232+
continue;
233+
}
234+
mayaAppOptions.Add (productDir.FullName, product);
235+
}
236+
return mayaAppOptions;
237+
}
238+
203239
public static GUIContent[] GetMayaOptions(){
204240
if (instance.mayaAppOptions == null) {
205-
instance.mayaAppOptions = new System.Collections.Generic.Dictionary<string, string> ();
206-
instance.mayaAppOptions.Add ("c:/", "Maya2017");
207-
instance.mayaAppOptions.Add ("d:/", "Maya2018");
208-
209-
instance.mayaOptionPaths = new System.Collections.Generic.List<string> (){ "c:/", "d:/" };
241+
instance.mayaAppOptions = FindMayaInstalls ();
242+
instance.mayaOptionPaths = new System.Collections.Generic.List<string> ();
243+
foreach (var key in instance.mayaAppOptions.Keys) {
244+
instance.mayaOptionPaths.Add (key);
245+
}
210246
}
211247
GUIContent[] optionArray = new GUIContent[instance.mayaAppOptions.Count+1];
212248
for(int i = 0; i < instance.mayaOptionPaths.Count; i++){

0 commit comments

Comments
 (0)