Skip to content

Commit 9e96413

Browse files
committed
Uni-21916 no cut-n-paste required
1 parent bff0fdd commit 9e96413

File tree

3 files changed

+76
-15
lines changed

3 files changed

+76
-15
lines changed

Assets/FbxExporters/Editor/InstallIntegration.cs

Lines changed: 66 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class Integrations
1414
private const string VERSION_FIELD = "**Version**";
1515
private const string VERSION_TAG = "{Version}";
1616
private const string PROJECT_TAG = "{UnityProject}";
17+
private static string MAYA_COMMANDS { get { return string.Format(@"configureUnityOneClick {1}{0}{1};", Integrations.GetProjectPath(), @"" + (char) 34); } }
1718

1819
private static Char[] FIELD_SEPARATORS = new Char[] {':'};
1920

@@ -36,6 +37,21 @@ private static string GetUserFolder()
3637
#endif
3738
}
3839

40+
public static string BuildCommandLineArgs (List<string> argsList)
41+
{
42+
System.Text.StringBuilder sb = new System.Text.StringBuilder ();
43+
44+
foreach (string arg in argsList) {
45+
sb.Append ("\"\"" + arg.Replace ("\"", @"\" + "\"") + "\"\" ");
46+
}
47+
48+
if (sb.Length > 0) {
49+
sb = sb.Remove (sb.Length - 1, 1);
50+
}
51+
52+
return sb.ToString ();
53+
}
54+
3955
private static string GetModulePath(string version)
4056
{
4157
string result = System.IO.Path.Combine(GetUserFolder(), REL_MAYA_MODULES_PATH);
@@ -154,7 +170,41 @@ private static void WriteFile(string FileName, List<string> Lines )
154170
}
155171
}
156172

157-
public static bool InstallMaya(string version, bool verbose=true)
173+
public static int ConfigureMaya(string version)
174+
{
175+
int ExitCode = 0;
176+
177+
try {
178+
System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
179+
myProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
180+
myProcess.StartInfo.CreateNoWindow = true;
181+
myProcess.StartInfo.UseShellExecute = false;
182+
183+
#if UNITY_EDITOR_OSX
184+
myProcess.StartInfo.FileName = "open";
185+
string mayaCommandLine = string.Format(@"/Applications/Autodesk/maya{0}/Maya.app --args -command '{1}'", version, MAYA_COMMANDS);
186+
myProcess.StartInfo.Arguments = "-a " + mayaCommandLine;
187+
#elif UNITY_EDITOR_LINUX
188+
throw new NotImplementedException();
189+
#else
190+
myProcess.StartInfo.FileName = "C:/Windows/system32/cmd.exe";
191+
string mayaCommandLine = string.Format("C:/Program Files/Autodesk/Maya{0}/maya.exe -command '{1}'", version, MAYA_COMMANDS);
192+
myProcess.StartInfo.Arguments = "/c " + mayaCommandLine;
193+
#endif
194+
myProcess.EnableRaisingEvents = true;
195+
myProcess.Start();
196+
myProcess.WaitForExit();
197+
ExitCode = myProcess.ExitCode;
198+
}
199+
catch (Exception e)
200+
{
201+
UnityEngine.Debug.LogError(string.Format ("Exception failed to start Maya ({0})", e.Message));
202+
ExitCode = -1;
203+
}
204+
return ExitCode;
205+
}
206+
207+
public static bool InstallMaya(string version, bool verbose = false)
158208
{
159209
// check if package installed
160210
string moduleTemplatePath = GetModuleTemplatePath(version);
@@ -249,15 +299,12 @@ public static bool InstallMaya(string version, bool verbose=true)
249299

250300
public static void InstallMaya2017()
251301
{
252-
const bool verbose = true;
253302
const string version = Integrations.MAYA_VERSION;
254303

255304
Debug.Log(string.Format("Installing Maya {0} Integration", version));
256305

257-
if (InstallMaya (version, verbose)) {
258-
if (verbose) Debug.Log (string.Format ("Completed installation of Maya {0} Integration.", version));
259-
} else {
260-
if (verbose) Debug.Log (string.Format ("Failed to install Maya {0} Integration.", version));
306+
if (!InstallMaya (version)) {
307+
Debug.LogError (string.Format ("Failed to install Maya {0} Integration.", version));
261308
}
262309
}
263310
}
@@ -266,19 +313,24 @@ namespace Editors
266313
{
267314
class IntegrationsUI
268315
{
269-
const string MenuItemName = "FbxExporters/Install Maya" + Integrations.MAYA_VERSION + " Integration" ;
316+
const string MenuItemName1 = "FbxExporters/Install Maya" + Integrations.MAYA_VERSION + " Integration";
270317

271-
[MenuItem (MenuItemName, false, 0)]
272-
public static void OnMenuItem ()
318+
[MenuItem (MenuItemName1, false, 0)]
319+
public static void OnMenuItem1 ()
273320
{
274321
if (Integrations.InstallMaya(Integrations.MAYA_VERSION))
275322
{
276-
string title = string.Format("Completed installation of Maya {0} Integration.", Integrations.MAYA_VERSION);
277-
string commands = string.Format("optionVar -stringValue \"UnityProject\" \"{0}\"; loadPlugin unityOneClickPlugin; pluginInfo -edit -autoload true unityOneClickPlugin;",Integrations.GetProjectPath());
278-
string message = string.Format("Please run the following MEL commands to configure auto-loading of the plugin in Maya.\n\n{0}\n", commands);
323+
int exitCode = Integrations.ConfigureMaya (Integrations.MAYA_VERSION);
324+
325+
string title = string.Format("Completed installation of Maya{0} Integration.", Integrations.MAYA_VERSION);
326+
string message = "Maya will close when it has finished configuring integration.";
327+
328+
if (exitCode!=0)
329+
{
330+
message = string.Format("Failed to configure Maya, please check logs (exitcode={0})", exitCode);
331+
}
279332

280-
EditorUtility.DisplayDialog (title, message, "Ok");
281-
Debug.Log(message);
333+
UnityEditor.EditorUtility.DisplayDialog (title, message, "Ok");
282334
}
283335
}
284336
}

Assets/FbxExporters/README.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ else
4545
echo "Maya2017 not installed"
4646
else
4747
# To configure without user interface prepend the following command: optionVar -intValue \"UnityOneClick_Headless\" 1;
48-
"${MAYA_PATH}" -command "optionVar -stringValue \"UnityProject\" \"${PROJECT_PATH}\"; loadPlugin unityOneClickPlugin; pluginInfo -edit -autoload true unityOneClickPlugin; quit;"
48+
"${MAYA_PATH}" -command "configureUnityOneClick \"${PROJECT_PATH}\";"
4949
fi
5050
fi
5151

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
global proc configureUnityOneClick(string $unityProject)
2+
{
3+
optionVar -stringValue "UnityProject" "{0}";
4+
loadPlugin unityOneClickPlugin;
5+
pluginInfo -edit -autoload true unityOneClickPlugin;
6+
scriptJob -idleEvent quit;
7+
8+
return;
9+
}

0 commit comments

Comments
 (0)