|
4 | 4 | using UnityEngine;
|
5 | 5 | using UnityEditor;
|
6 | 6 | using System.Collections.Generic;
|
| 7 | +using System.Linq; |
7 | 8 |
|
8 | 9 | namespace FbxExporters.EditorTools {
|
9 | 10 |
|
@@ -251,131 +252,113 @@ private static string DefaultIntegrationSavePath {
|
251 | 252 | }
|
252 | 253 | }
|
253 | 254 |
|
254 |
| - /// <summary> |
255 |
| - /// The paths where all the different versions of Maya are installed |
256 |
| - /// by default. Depends on the platform. |
257 |
| - /// </summary> |
258 |
| - public static string[] DCCVendorLocations { |
259 |
| - get{ |
260 |
| - var environmentVariable = Environment.GetEnvironmentVariable("UNITY_FBX_3DAPP_VENDOR_LOCATIONS"); |
261 |
| - List<string> locationsList = new List<string>(); |
262 |
| - List<string> WindowsDefaultLocations = new List<string>() { "C:/Program Files/Autodesk", "D:/Program Files/Autodesk" }; |
263 |
| - List<string> OSXDefaultLocations = new List<string>() { "/Applications/Autodesk" }; |
264 |
| - bool foundVendorLocation = false; |
| 255 | + private static string GetVendorLocationFromEnv(string env) |
| 256 | + { |
| 257 | + string result = null; |
| 258 | + |
| 259 | + if (string.IsNullOrEmpty(env)) |
| 260 | + return null; |
| 261 | + |
| 262 | + string location = Environment.GetEnvironmentVariable(env); |
| 263 | + |
| 264 | + if (string.IsNullOrEmpty(location)) |
| 265 | + return null; |
| 266 | + |
| 267 | + if (!Directory.Exists(location)) |
| 268 | + return null; |
| 269 | + |
| 270 | + //Remove any extra slashes on the end |
| 271 | + //Maya would accept a single slash in either direction, so we should be able to |
| 272 | + location = location.Replace("\\", "/"); |
| 273 | + location.TrimEnd('/'); |
| 274 | + |
| 275 | + if (Application.platform == RuntimePlatform.WindowsEditor) |
| 276 | + { |
| 277 | + //If we are on Windows, we need only go up one location to get to the "Autodesk" folder. |
| 278 | + result = Directory.GetParent(location).ToString(); |
| 279 | + } |
| 280 | + else if (Application.platform == RuntimePlatform.OSXEditor) |
| 281 | + { |
| 282 | + //We can assume our path is: /Applications/Autodesk/maya2017/Maya.app/Contents |
| 283 | + //So we need to go up three folders. |
265 | 284 |
|
266 |
| - if (environmentVariable != null) |
| 285 | + var appFolder = Directory.GetParent(location); |
| 286 | + if (appFolder != null) |
267 | 287 | {
|
268 |
| - string[] locations = environmentVariable.Split(';'); |
269 |
| - for (int i = 0; i < locations.Length; i++) |
| 288 | + var versionFolder = Directory.GetParent(appFolder.ToString()); |
| 289 | + if (versionFolder != null) |
270 | 290 | {
|
271 |
| - if (Directory.Exists(locations[i])) |
| 291 | + var autoDeskFolder = Directory.GetParent(versionFolder.ToString()); |
| 292 | + if (autoDeskFolder != null) |
272 | 293 | {
|
273 |
| - locationsList.Add(locations[i]); |
| 294 | + result = autoDeskFolder.ToString(); |
274 | 295 | }
|
275 | 296 | }
|
276 |
| - //If we found anything, just return the list |
277 |
| - if (locationsList.Count > 0) |
278 |
| - { |
279 |
| - foundVendorLocation = true; |
280 |
| - } |
281 | 297 | }
|
| 298 | + } |
282 | 299 |
|
283 |
| - var location = System.Environment.GetEnvironmentVariable("MAYA_LOCATION"); |
284 |
| - if (!string.IsNullOrEmpty(location)) |
285 |
| - { |
286 |
| - string possibleLocation = null; |
287 |
| - if (Application.platform == RuntimePlatform.WindowsEditor) |
288 |
| - { |
289 |
| - //If we are on Windows, we need only go up one location to get to the "Autodesk" folder. |
290 |
| - if (Directory.GetParent(location) != null) |
291 |
| - { |
292 |
| - //'Directory.GetParent()' will take care of any double backslashes the user may have added |
293 |
| - possibleLocation = Directory.GetParent(location).ToString(); |
294 |
| - |
295 |
| - //We only need to remove duplicates of default locations if we are using the default locations- |
296 |
| - //We only use default locations if we do not use the user specified vendor locations |
297 |
| - if (!foundVendorLocation) |
298 |
| - { |
299 |
| - //Make sure the user defined path is not included in the default paths |
300 |
| - for (int i = 0; i < WindowsDefaultLocations.Count; i++) |
301 |
| - { |
302 |
| - //we don't want a minute difference in slashes or capitalization to throw off our check |
303 |
| - if (WindowsDefaultLocations[i] != null && |
304 |
| - possibleLocation != null && |
305 |
| - WindowsDefaultLocations[i].Replace("\\", "/").ToLower().Equals(possibleLocation.Replace("\\", "/").ToLower())) |
306 |
| - { |
307 |
| - possibleLocation = null; |
308 |
| - break; |
309 |
| - } |
310 |
| - } |
311 |
| - } |
312 |
| - } |
313 |
| - } |
314 |
| - else if (Application.platform == RuntimePlatform.OSXEditor) |
315 |
| - { |
316 |
| - //We can assume our path is: /Applications/Autodesk/maya2017/Maya.app/Contents |
317 |
| - //So we need to go up three folders. |
| 300 | + return result; |
| 301 | + } |
318 | 302 |
|
319 |
| - //Remove any extra slashes on the end |
320 |
| - //Maya would accept a single slash in either direction, so we should be able to |
321 |
| - location.TrimEnd('/'); |
322 |
| - location.TrimEnd('\\'); |
| 303 | + // Returns a set of valid vendor folder paths with no trailing '/' |
| 304 | + private static HashSet<string> GetCustomVendorLocations() |
| 305 | + { |
| 306 | + HashSet<string> result = new HashSet<string>(); |
323 | 307 |
|
324 |
| - var appFolder = Directory.GetParent(location); |
325 |
| - if (appFolder != null) |
326 |
| - { |
327 |
| - var versionFolder = Directory.GetParent(appFolder.ToString()); |
328 |
| - if (versionFolder != null) |
329 |
| - { |
330 |
| - var autoDeskFolder = Directory.GetParent(versionFolder.ToString()); |
331 |
| - if (autoDeskFolder != null) |
332 |
| - { |
333 |
| - possibleLocation = autoDeskFolder.ToString(); |
334 |
| - |
335 |
| - //Make sure the user defined path is not included in the default paths |
336 |
| - for (int i = 0; i < OSXDefaultLocations.Count; i++) |
337 |
| - { |
338 |
| - //we don't want a minute difference in slashes or capitalization to throw off our check |
339 |
| - if (OSXDefaultLocations[i].Replace("\\", "/").ToLower().Equals(possibleLocation.Replace("\\", "/").ToLower())) |
340 |
| - { |
341 |
| - possibleLocation = null; |
342 |
| - continue; |
343 |
| - } |
344 |
| - } |
345 |
| - } |
346 |
| - } |
347 |
| - } |
348 |
| - } |
349 |
| - else |
350 |
| - { |
351 |
| - throw new NotImplementedException(); |
352 |
| - } |
| 308 | + var environmentVariable = Environment.GetEnvironmentVariable("UNITY_FBX_3DAPP_VENDOR_LOCATIONS"); |
353 | 309 |
|
354 |
| - if (!string.IsNullOrEmpty(possibleLocation) && Directory.Exists(possibleLocation)) |
| 310 | + if (!string.IsNullOrEmpty(environmentVariable)) |
| 311 | + { |
| 312 | + string[] locations = environmentVariable.Split(';'); |
| 313 | + for (int i = 0; i < locations.Length; i++) |
| 314 | + { |
| 315 | + if (Directory.Exists(locations[i])) |
355 | 316 | {
|
356 |
| - locationsList.Add(possibleLocation.ToString()); |
| 317 | + result.Add(locations[i]); |
357 | 318 | }
|
358 | 319 | }
|
| 320 | + } |
| 321 | + |
| 322 | + |
| 323 | + return result; |
| 324 | + } |
359 | 325 |
|
360 |
| - if (foundVendorLocation) |
| 326 | + private static HashSet<string> GetDefaultVendorLocations() |
| 327 | + { |
| 328 | + if (Application.platform == RuntimePlatform.WindowsEditor) |
| 329 | + return new HashSet<string>() { "C:/Program Files/Autodesk", "D:/Program Files/Autodesk" }; |
| 330 | + else if (Application.platform == RuntimePlatform.OSXEditor) |
| 331 | + return new HashSet<string>() { "/Applications/Autodesk" }; |
| 332 | + |
| 333 | + throw new NotImplementedException(); |
| 334 | + } |
| 335 | + |
| 336 | + /// <summary> |
| 337 | + /// Retrieve available vendor locations. |
| 338 | + /// If there is valid alternative vendor locations, do not use defaults |
| 339 | + /// always use MAYA_LOCATION when available |
| 340 | + /// </summary> |
| 341 | + public static string[] DCCVendorLocations |
| 342 | + { |
| 343 | + get |
| 344 | + { |
| 345 | + HashSet<string> result = GetCustomVendorLocations(); |
| 346 | + |
| 347 | + if (result == null || result.Count < 1) |
361 | 348 | {
|
362 |
| - return locationsList.ToArray(); |
| 349 | + result = GetDefaultVendorLocations(); |
363 | 350 | }
|
364 | 351 |
|
365 |
| - switch (Application.platform) |
| 352 | + var additionalLocation = GetVendorLocationFromEnv("MAYA_LOCATION"); |
| 353 | + |
| 354 | + if (!string.IsNullOrEmpty(additionalLocation)) |
366 | 355 | {
|
367 |
| - case RuntimePlatform.WindowsEditor: |
368 |
| - locationsList.AddRange(WindowsDefaultLocations); |
369 |
| - break; |
370 |
| - case RuntimePlatform.OSXEditor: |
371 |
| - locationsList.AddRange(OSXDefaultLocations); |
372 |
| - break; |
373 |
| - default: |
374 |
| - throw new NotImplementedException(); |
| 356 | + result.Add(additionalLocation); |
375 | 357 | }
|
376 |
| - return locationsList.ToArray(); |
| 358 | + |
| 359 | + return result.ToArray<string>(); |
377 | 360 | }
|
378 |
| - } |
| 361 | + } |
379 | 362 |
|
380 | 363 | // Note: default values are set in LoadDefaults().
|
381 | 364 | public bool mayaCompatibleNames = true;
|
|
0 commit comments