Skip to content

Commit e5b1bf5

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/master' into Uni-25868-release
# Conflicts: # Assets/FbxExporters/README.txt # Assets/Integrations/Autodesk/maya/scripts/unityOneClick/version.py
2 parents 14a6804 + aa55f0b commit e5b1bf5

28 files changed

+428
-43
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
[Bb]in/
1111
[Dd]ebug/
1212

13+
[Aa]ssets/FbxExporters/unityoneclick_for_maya.zip
14+
1315
# vim temp files
1416
*.swp
1517
*.swo

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public static string GetVersionFromReadme()
124124
}
125125

126126
try{
127-
var versionHeader = "**Version**:";
127+
var versionHeader = "VERSION:";
128128
var lines = File.ReadAllLines (absPath);
129129
foreach (var line in lines) {
130130
if (line.StartsWith(versionHeader)) {

Assets/FbxExporters/Editor/InstallIntegration.cs

Lines changed: 174 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,34 @@ class Integrations
1010
private const string MODULE_FILENAME = "unityoneclick";
1111
private const string PACKAGE_NAME = "FbxExporters";
1212
private const string VERSION_FILENAME = "README.txt";
13-
private const string VERSION_FIELD = "**Version**";
13+
private const string VERSION_FIELD = "VERSION";
1414
private const string VERSION_TAG = "{Version}";
1515
private const string PROJECT_TAG = "{UnityProject}";
16+
private const string INTEGRATION_TAG = "{UnityIntegrationsPath}";
1617

17-
private const string FBX_EXPORT_SETTINGS_PATH = "FbxExporters/Integrations/Autodesk/maya/scripts/unityFbxExportSettings.mel";
18+
private const string FBX_EXPORT_SETTINGS_PATH = "/Integrations/Autodesk/maya/scripts/unityFbxExportSettings.mel";
1819

1920
private const string MAYA_INSTRUCTION_FILENAME = "_safe_to_delete/_temp.txt";
2021

21-
private const string MODULE_TEMPLATE_PATH = "FbxExporters/Integrations/Autodesk/maya/" + MODULE_FILENAME + ".txt";
22+
private static string m_integrationFolderPath = null;
23+
public static string INTEGRATION_FOLDER_PATH
24+
{
25+
get{
26+
if (string.IsNullOrEmpty (m_integrationFolderPath)) {
27+
m_integrationFolderPath = Application.dataPath;
28+
}
29+
return m_integrationFolderPath;
30+
}
31+
set{
32+
if (!string.IsNullOrEmpty (value) && System.IO.Directory.Exists (value)) {
33+
m_integrationFolderPath = value;
34+
} else {
35+
Debug.LogError (string.Format("Failed to set integration folder path, invalid directory \"{0}\"", value));
36+
}
37+
}
38+
}
39+
40+
public const string MODULE_TEMPLATE_PATH = "Integrations/Autodesk/maya/" + MODULE_FILENAME + ".txt";
2241

2342
#if UNITY_EDITOR_OSX
2443
private const string MAYA_MODULES_PATH = "Library/Preferences/Autodesk/Maya/modules";
@@ -28,12 +47,6 @@ class Integrations
2847
private const string MAYA_MODULES_PATH = "maya/modules";
2948
#endif
3049

31-
public class MayaException : System.Exception {
32-
public MayaException() { }
33-
public MayaException(string message) : base(message) { }
34-
public MayaException(string message, System.Exception inner) : base(message, inner) { }
35-
}
36-
3750
// Use string to define escaped quote
3851
// Windows needs the backslash
3952
#if UNITY_EDITOR_OSX || UNITY_EDITOR_LINUX
@@ -70,7 +83,7 @@ public static string GetModulePath()
7083

7184
public static string GetModuleTemplatePath()
7285
{
73-
return System.IO.Path.Combine(Application.dataPath, MODULE_TEMPLATE_PATH);
86+
return System.IO.Path.Combine(INTEGRATION_FOLDER_PATH, MODULE_TEMPLATE_PATH);
7487
}
7588

7689
public static string GetAppPath()
@@ -119,7 +132,7 @@ public static string GetFullMayaInstructionPath()
119132
/// <returns>The export settings path.</returns>
120133
public static string GetExportSettingsPath()
121134
{
122-
return FBX_EXPORT_SETTINGS_PATH;
135+
return INTEGRATION_FOLDER_PATH + FBX_EXPORT_SETTINGS_PATH;
123136
}
124137

125138
public static string GetPackageVersion()
@@ -326,7 +339,8 @@ public static bool InstallMaya(bool verbose = false)
326339
Dictionary<string,string> Tokens = new Dictionary<string,string>()
327340
{
328341
{VERSION_TAG, GetPackageVersion() },
329-
{PROJECT_TAG, GetProjectPath() }
342+
{PROJECT_TAG, GetProjectPath() },
343+
{INTEGRATION_TAG, INTEGRATION_FOLDER_PATH },
330344
};
331345

332346
// parse template, replace "{UnityProject}" with project path
@@ -365,13 +379,35 @@ public static string GetMayaExe () {
365379
return FbxExporters.EditorTools.ExportSettings.GetSelectedMayaPath ();
366380
}
367381

382+
const string IntegrationZipPath = "FbxExporters/unityoneclick_for_maya.zip";
383+
384+
private static string DefaultIntegrationSavePath
385+
{
386+
get{
387+
return Application.dataPath;
388+
}
389+
}
390+
391+
private static string LastIntegrationSavePath = DefaultIntegrationSavePath;
392+
368393
public static void InstallMayaIntegration ()
369394
{
370395
var mayaExe = GetMayaExe ();
371396
if (string.IsNullOrEmpty (mayaExe)) {
372397
return;
373398
}
374399

400+
// decompress zip file if it exists, otherwise try using default location
401+
if (System.IO.File.Exists (GetIntegrationZipFullPath())) {
402+
var result = DecompressIntegrationZipFile ();
403+
if (!result) {
404+
// could not find integration
405+
return;
406+
}
407+
} else {
408+
Integrations.INTEGRATION_FOLDER_PATH = DefaultIntegrationSavePath;
409+
}
410+
375411
if (!Integrations.InstallMaya(verbose: true)) {
376412
return;
377413
}
@@ -388,5 +424,131 @@ public static void InstallMayaIntegration ()
388424
}
389425
UnityEditor.EditorUtility.DisplayDialog (title, message, "Ok");
390426
}
427+
428+
private static bool DecompressIntegrationZipFile()
429+
{
430+
// prompt user to enter location to unzip file
431+
var unzipFolder = EditorUtility.OpenFolderPanel("Select Location to Save Maya Integration",LastIntegrationSavePath,"");
432+
if (string.IsNullOrEmpty (unzipFolder)) {
433+
// user has cancelled, do nothing
434+
return false;
435+
}
436+
437+
// check that this is a valid location to unzip the file
438+
if (!DirectoryHasWritePermission (unzipFolder)) {
439+
// display dialog to try again or cancel
440+
var result = UnityEditor.EditorUtility.DisplayDialog ("No Write Permission",
441+
string.Format("Directory \"{0}\" does not have write access", unzipFolder),
442+
"Select another Directory",
443+
"Cancel"
444+
);
445+
446+
if (result) {
447+
InstallMayaIntegration ();
448+
} else {
449+
return false;
450+
}
451+
}
452+
453+
LastIntegrationSavePath = unzipFolder;
454+
455+
// if file already unzipped in this location, then prompt user
456+
// if they would like to continue unzipping or use what is there
457+
if (FolderAlreadyUnzippedAtPath (unzipFolder)) {
458+
var result = UnityEditor.EditorUtility.DisplayDialogComplex ("Integrations Exist at Path",
459+
string.Format ("Directory \"{0}\" already contains the decompressed integration", unzipFolder),
460+
"Overwrite",
461+
"Use Existing",
462+
"Cancel"
463+
);
464+
465+
if (result == 0) {
466+
DecompressZip (GetIntegrationZipFullPath(), unzipFolder);
467+
} else if (result == 2) {
468+
return false;
469+
}
470+
} else {
471+
// unzip Integration folder
472+
DecompressZip (GetIntegrationZipFullPath(), unzipFolder);
473+
}
474+
475+
Integrations.INTEGRATION_FOLDER_PATH = unzipFolder;
476+
477+
return true;
478+
}
479+
480+
/// <summary>
481+
/// Gets the integration zip full path as an absolute Unity-style path.
482+
/// </summary>
483+
/// <returns>The integration zip full path.</returns>
484+
private static string GetIntegrationZipFullPath()
485+
{
486+
return Application.dataPath + "/" + IntegrationZipPath;
487+
}
488+
489+
/// <summary>
490+
/// Determines if folder is already unzipped at the specified path
491+
/// by checking if unityoneclick.txt exists at expected location.
492+
/// </summary>
493+
/// <returns><c>true</c> if folder is already unzipped at the specified path; otherwise, <c>false</c>.</returns>
494+
/// <param name="path">Path.</param>
495+
public static bool FolderAlreadyUnzippedAtPath(string path)
496+
{
497+
return System.IO.File.Exists (System.IO.Path.Combine (path, Integrations.MODULE_TEMPLATE_PATH));
498+
}
499+
500+
/// <summary>
501+
/// Make sure we can write to this directory.
502+
/// Try creating a file in path directory, if it raises an error, then we can't
503+
/// write here.
504+
/// TODO: find a more reliable way to check this
505+
/// </summary>
506+
/// <returns><c>true</c>, if possible to write to path, <c>false</c> otherwise.</returns>
507+
/// <param name="path">Path.</param>
508+
public static bool DirectoryHasWritePermission(string path)
509+
{
510+
try
511+
{
512+
using (System.IO.FileStream fs = System.IO.File.Create(
513+
System.IO.Path.Combine(
514+
path,
515+
System.IO.Path.GetRandomFileName()
516+
),
517+
1,
518+
System.IO.FileOptions.DeleteOnClose)
519+
)
520+
{ }
521+
return true;
522+
}
523+
catch(Exception)
524+
{
525+
return false;
526+
}
527+
}
528+
529+
public static void DecompressZip(string zipPath, string destPath){
530+
System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
531+
var ZIPAPP = "7z.exe";
532+
#if UNITY_EDITOR_OSX
533+
ZIPAPP = "7za";
534+
#endif
535+
myProcess.StartInfo.FileName = EditorApplication.applicationContentsPath + "/Tools/" + ZIPAPP;
536+
myProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
537+
myProcess.StartInfo.CreateNoWindow = true;
538+
myProcess.StartInfo.UseShellExecute = false;
539+
540+
// Command line flags used:
541+
// x : extract the zip contents so that they maintain the file hierarchy
542+
// -o : specify where to extract contents
543+
// -r : recurse subdirectories
544+
// -y : auto yes to all questions (without this Unity freezes as the process waits for a response)
545+
myProcess.StartInfo.Arguments = string.Format("x \"{0}\" -o\"{1}\" -r -y", zipPath, destPath);
546+
myProcess.EnableRaisingEvents = true;
547+
myProcess.Start();
548+
myProcess.WaitForExit();
549+
550+
// in case we unzip inside the Assets folder, make sure it updates
551+
AssetDatabase.Refresh ();
552+
}
391553
}
392554
}

Assets/FbxExporters/README.txt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
1-
# FbxExporters
1+
FbxExporters Package
2+
====================
23

34
Copyright (c) 2017 Unity Technologies. All rights reserved.
45

56
See LICENSE.txt file for full license information.
67

7-
**Version**: sprint26
8+
VERSION: sprint26
89

910
Requirements
1011
------------
1112

12-
* [FBX SDK C# Bindings](https://github.com/Unity-Technologies/FbxSharp)
13+
The Unity Integration for Maya is designed to work with Maya 2017 or later.
1314

14-
Installing Maya Integration
15-
--------------------------------------------
15+
Please note that MayaLT is not supported at this time.
1616

17-
The easiest way to install the Maya integration is from the menu option in Unity.
17+
Installing Unity Integration for Maya
18+
-------------------------------------
1819

19-
FbxExporters -> Install Maya Integration
20+
The easiest way to install the Unity integration For Maya is from the FbxExports Settings panel in Unity.
21+
22+
MenuBar -> Edit -> Project Settings -> Fbx Export -> Install Unity Integration
2023

2124
This menu item locates and uses the most recent version of Maya installed. If you want
22-
to specify a custom version or location then set your MAYA_LOCATION environment
23-
before running Unity.
25+
to specify a custom version or location you can browse and locate your version.
2426

2527
Alternately, you can install the package and integrations from the command-line
2628
using a script, an example of which can be found in the scripts folder of the

0 commit comments

Comments
 (0)