Skip to content

Commit ce688f0

Browse files
committed
generalize variable names
- rename variables with Maya to DCC - add FindMaxInstalls() function to populate dropdown with default max installs
1 parent c45409c commit ce688f0

File tree

1 file changed

+71
-45
lines changed

1 file changed

+71
-45
lines changed

Assets/FbxExporters/Editor/FbxExportSettings.cs

Lines changed: 71 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -106,26 +106,26 @@ public override void OnInspectorGUI() {
106106
"Select the version of Maya where you would like to install the Unity integration."));
107107

108108
// dropdown to select Maya version to use
109-
var options = ExportSettings.GetMayaOptions();
109+
var options = ExportSettings.GetDCCOptions();
110110
// make sure we never initially have browse selected
111-
if (exportSettings.selectedMayaApp == options.Length - 1) {
112-
exportSettings.selectedMayaApp = 0;
111+
if (exportSettings.selectedDCCApp == options.Length - 1) {
112+
exportSettings.selectedDCCApp = 0;
113113
}
114-
int oldValue = exportSettings.selectedMayaApp;
115-
exportSettings.selectedMayaApp = EditorGUILayout.Popup(exportSettings.selectedMayaApp, options);
116-
if (exportSettings.selectedMayaApp == options.Length - 1) {
114+
int oldValue = exportSettings.selectedDCCApp;
115+
exportSettings.selectedDCCApp = EditorGUILayout.Popup(exportSettings.selectedDCCApp, options);
116+
if (exportSettings.selectedDCCApp == options.Length - 1) {
117117
var ext = "exe";
118118
#if UNITY_EDITOR_OSX
119119
ext = "app";
120120
#endif
121-
string mayaPath = EditorUtility.OpenFilePanel ("Select Maya Application", ExportSettings.kDefaultAdskRoot, ext);
121+
string dccPath = EditorUtility.OpenFilePanel ("Select DCC Application", ExportSettings.kDefaultAdskRoot, ext);
122122

123123
// check that the path is valid and references the maya executable
124-
if (!string.IsNullOrEmpty (mayaPath)) {
125-
if (!Path.GetFileNameWithoutExtension (mayaPath).ToLower ().Equals ("maya")) {
124+
if (!string.IsNullOrEmpty (dccPath)) {
125+
if (!Path.GetFileNameWithoutExtension (dccPath).ToLower ().Equals ("maya")) {
126126
// clicked on the wrong application, try to see if we can still find
127127
// maya in this directory.
128-
var mayaDir = new DirectoryInfo(Path.GetDirectoryName(mayaPath));
128+
var mayaDir = new DirectoryInfo(Path.GetDirectoryName(dccPath));
129129
#if UNITY_EDITOR_OSX
130130
var files = mayaDir.GetDirectories("*." + ext);
131131
#else
@@ -135,21 +135,21 @@ public override void OnInspectorGUI() {
135135
foreach (var file in files) {
136136
var filename = Path.GetFileNameWithoutExtension (file.Name).ToLower ();
137137
if (filename.Equals ("maya")) {
138-
mayaPath = file.FullName.Replace("\\","/");
138+
dccPath = file.FullName.Replace("\\","/");
139139
foundMaya = true;
140140
break;
141141
}
142142
}
143143
if (!foundMaya) {
144144
Debug.LogError (string.Format("Could not find Maya at: \"{0}\"", mayaDir.FullName));
145-
exportSettings.selectedMayaApp = oldValue;
145+
exportSettings.selectedDCCApp = oldValue;
146146
return;
147147
}
148148
}
149-
ExportSettings.AddMayaOption (mayaPath);
149+
ExportSettings.AddDCCOption (dccPath);
150150
Repaint ();
151151
} else {
152-
exportSettings.selectedMayaApp = oldValue;
152+
exportSettings.selectedDCCApp = oldValue;
153153
}
154154
}
155155
GUILayout.EndHorizontal ();
@@ -206,7 +206,7 @@ public class ExportSettings : ScriptableSingleton<ExportSettings>
206206
[HideInInspector]
207207
public bool keepOriginalAfterConvert;
208208

209-
public int selectedMayaApp = 0;
209+
public int selectedDCCApp = 0;
210210

211211
[SerializeField]
212212
public UnityEngine.Object turntableScene;
@@ -226,10 +226,10 @@ public class ExportSettings : ScriptableSingleton<ExportSettings>
226226

227227
// List of names in order that they appear in option list
228228
[SerializeField]
229-
private List<string> mayaOptionNames;
229+
private List<string> dccOptionNames;
230230
// List of paths in order that they appear in the option list
231231
[SerializeField]
232-
private List<string> mayaOptionPaths;
232+
private List<string> dccOptionPaths;
233233

234234
protected override void LoadDefaults()
235235
{
@@ -238,8 +238,8 @@ protected override void LoadDefaults()
238238
keepOriginalAfterConvert = false;
239239
convertToModelSavePath = kDefaultSavePath;
240240
turntableScene = null;
241-
mayaOptionPaths = null;
242-
mayaOptionNames = null;
241+
dccOptionPaths = null;
242+
dccOptionNames = null;
243243
}
244244

245245
/// <summary>
@@ -248,7 +248,7 @@ protected override void LoadDefaults()
248248
/// <returns>The unique name.</returns>
249249
/// <param name="name">Name.</param>
250250
private static string GetUniqueName(string name){
251-
if (!instance.mayaOptionNames.Contains(name)) {
251+
if (!instance.dccOptionNames.Contains(name)) {
252252
return name;
253253
}
254254
var format = "{1} ({0})";
@@ -269,22 +269,44 @@ private static string GetUniqueName(string name){
269269
do {
270270
uniqueName = string.Format (format, index, name);
271271
index++;
272-
} while (instance.mayaOptionNames.Contains(name));
272+
} while (instance.dccOptionNames.Contains(name));
273273

274274
return uniqueName;
275275
}
276276

277+
/// <summary>
278+
/// Find 3DsMax installations at default install path.
279+
/// Add results to given dictionary.
280+
/// </summary>
281+
private static void FindMaxInstalls(){
282+
var maxOptionName = instance.dccOptionNames;
283+
var maxOptionPath = instance.dccOptionPaths;
284+
285+
// List that directory and find the right version:
286+
// either the newest version, or the exact version we wanted.
287+
var adskRoot = new System.IO.DirectoryInfo(kDefaultAdskRoot);
288+
foreach(var productDir in adskRoot.GetDirectories()) {
289+
var product = productDir.Name;
290+
291+
// Only accept those that start with 'maya' in either case.
292+
if (!product.StartsWith("3ds max", StringComparison.InvariantCultureIgnoreCase)) {
293+
continue;
294+
}
295+
string version = product.Substring ("3ds max ".Length);
296+
maxOptionPath.Add (string.Format("{0}/{1}", productDir.FullName.Replace ("\\", "/"), "3dsmax.exe"));
297+
maxOptionName.Add (GetUniqueName("3Ds Max " + version));
298+
}
299+
}
300+
277301
/// <summary>
278302
/// Find Maya installations at default install path.
279303
/// Add results to given dictionary.
280304
///
281305
/// If MAYA_LOCATION is set, add this to the list as well.
282306
/// </summary>
283307
private static void FindMayaInstalls() {
284-
instance.mayaOptionPaths = new List<string> ();
285-
instance.mayaOptionNames = new List<string> ();
286-
var mayaOptionName = instance.mayaOptionNames;
287-
var mayaOptionPath = instance.mayaOptionPaths;
308+
var mayaOptionName = instance.dccOptionNames;
309+
var mayaOptionPath = instance.dccOptionPaths;
288310

289311
// If the location is given by the environment, use it.
290312
var location = System.Environment.GetEnvironmentVariable ("MAYA_LOCATION");
@@ -340,57 +362,61 @@ private static string GetMayaExePath(string location)
340362
#endif
341363
}
342364

343-
public static GUIContent[] GetMayaOptions(){
344-
if (instance.mayaOptionNames == null ||
345-
instance.mayaOptionNames.Count != instance.mayaOptionPaths.Count ||
346-
instance.mayaOptionNames.Count == 0) {
365+
public static GUIContent[] GetDCCOptions(){
366+
if (instance.dccOptionNames == null ||
367+
instance.dccOptionNames.Count != instance.dccOptionPaths.Count ||
368+
instance.dccOptionNames.Count == 0) {
369+
370+
instance.dccOptionPaths = new List<string> ();
371+
instance.dccOptionNames = new List<string> ();
347372
FindMayaInstalls ();
373+
FindMaxInstalls ();
348374
}
349375

350376
// remove options that no longer exist
351377
List<int> toDelete = new List<int>();
352-
for(int i = 0; i < instance.mayaOptionPaths.Count; i++) {
353-
var mayaPath = instance.mayaOptionPaths [i];
378+
for(int i = 0; i < instance.dccOptionPaths.Count; i++) {
379+
var mayaPath = instance.dccOptionPaths [i];
354380
if (!File.Exists (mayaPath)) {
355-
if (i == instance.selectedMayaApp) {
356-
instance.selectedMayaApp = 0;
381+
if (i == instance.selectedDCCApp) {
382+
instance.selectedDCCApp = 0;
357383
}
358-
instance.mayaOptionNames.RemoveAt (i);
384+
instance.dccOptionNames.RemoveAt (i);
359385
toDelete.Add (i);
360386
}
361387
}
362388
foreach (var index in toDelete) {
363-
instance.mayaOptionPaths.RemoveAt (index);
389+
instance.dccOptionPaths.RemoveAt (index);
364390
}
365391

366-
GUIContent[] optionArray = new GUIContent[instance.mayaOptionPaths.Count+1];
367-
for(int i = 0; i < instance.mayaOptionPaths.Count; i++){
392+
GUIContent[] optionArray = new GUIContent[instance.dccOptionPaths.Count+1];
393+
for(int i = 0; i < instance.dccOptionPaths.Count; i++){
368394
optionArray [i] = new GUIContent(
369-
instance.mayaOptionNames[i],
370-
instance.mayaOptionPaths[i]
395+
instance.dccOptionNames[i],
396+
instance.dccOptionPaths[i]
371397
);
372398
}
373399
optionArray [optionArray.Length - 1] = new GUIContent("Browse...");
374400

375401
return optionArray;
376402
}
377403

378-
public static void AddMayaOption(string newOption){
404+
public static void AddDCCOption(string newOption){
379405
// on OSX we get a path ending in .app, which is not quite the exe
380406
#if UNITY_EDITOR_OSX
381407
newOption = GetMayaExePath(newOption);
382408
#endif
383409

384-
var mayaOptionPaths = instance.mayaOptionPaths;
410+
var mayaOptionPaths = instance.dccOptionPaths;
385411
if (mayaOptionPaths.Contains(newOption)) {
386-
instance.selectedMayaApp = mayaOptionPaths.IndexOf (newOption);
412+
instance.selectedDCCApp = mayaOptionPaths.IndexOf (newOption);
387413
return;
388414
}
389415
// get the version
390416
var version = AskMayaVersion(newOption);
391-
instance.mayaOptionNames.Add (GetUniqueName("Maya "+version));
417+
instance.dccOptionNames.Add (GetUniqueName("Maya "+version));
392418
mayaOptionPaths.Add (newOption);
393-
instance.selectedMayaApp = mayaOptionPaths.Count - 1;
419+
instance.selectedDCCApp = mayaOptionPaths.Count - 1;
394420
}
395421

396422
/// <summary>
@@ -418,7 +444,7 @@ static string AskMayaVersion(string exePath) {
418444

419445
public static string GetSelectedMayaPath()
420446
{
421-
return instance.mayaOptionPaths [instance.selectedMayaApp];
447+
return instance.dccOptionPaths [instance.selectedDCCApp];
422448
}
423449

424450
public static string GetTurnTableSceneName(){

0 commit comments

Comments
 (0)