Skip to content

Commit 5984802

Browse files
authored
Merge pull request #49 from Unity-Technologies/Uni-21916-no-cut-n-paste-required
Uni-21916 no cut-n-paste required
2 parents bff0fdd + 1d38b55 commit 5984802

File tree

4 files changed

+85
-17
lines changed

4 files changed

+85
-17
lines changed

Assets/FbxExporters/Editor/InstallIntegration.cs

Lines changed: 74 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,15 @@ class Integrations
1414
private const string VERSION_FIELD = "**Version**";
1515
private const string VERSION_TAG = "{Version}";
1616
private const string PROJECT_TAG = "{UnityProject}";
17-
17+
private static string MAYA_COMMANDS { get {
18+
#if UNITY_EDITOR_OSX || UNITY_EDITOR_LINUX
19+
return string.Format(@"configureUnityOneClick {1}{0}{1};",
20+
Integrations.GetProjectPath(), @"" + (char) 34);
21+
#else
22+
return string.Format("configureUnityOneClick \\{1}{0}\\{1};",
23+
Integrations.GetProjectPath().Replace("\\","/"), @"" + (char) 34);
24+
#endif
25+
}}
1826
private static Char[] FIELD_SEPARATORS = new Char[] {':'};
1927

2028
private const string MODULE_TEMPLATE_PATH = "Integrations/Autodesk/maya"+VERSION_TAG+"/unityoneclick.mod";
@@ -154,7 +162,56 @@ private static void WriteFile(string FileName, List<string> Lines )
154162
}
155163
}
156164

157-
public static bool InstallMaya(string version, bool verbose=true)
165+
public static int ConfigureMaya(string version)
166+
{
167+
int ExitCode = 0;
168+
169+
try {
170+
System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
171+
myProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
172+
myProcess.StartInfo.CreateNoWindow = true;
173+
myProcess.StartInfo.UseShellExecute = false;
174+
175+
#if UNITY_EDITOR_OSX
176+
myProcess.StartInfo.FileName = "open";
177+
string mayaPath = string.Format ("/Applications/Autodesk/maya{0}/Maya.app", version);
178+
179+
if (!System.IO.Directory.Exists(mayaPath))
180+
{
181+
Debug.LogError (string.Format ("No maya installation found at {0}",mayaPath));
182+
return -1;
183+
}
184+
185+
string mayaCommandLine = string.Format(@"{0} --args -command '{1}'", mayaPath, MAYA_COMMANDS);
186+
myProcess.StartInfo.Arguments = "-a " + mayaCommandLine;
187+
#elif UNITY_EDITOR_LINUX
188+
throw new NotImplementedException();
189+
#else
190+
string mayaPath = string.Format ("C:/Program Files/Autodesk/Maya{0}/bin/maya.exe", version);
191+
192+
if (!System.IO.File.Exists(mayaPath))
193+
{
194+
Debug.LogError (string.Format ("No maya installation found at {0}", mayaPath));
195+
return -1;
196+
}
197+
198+
myProcess.StartInfo.FileName = mayaPath;
199+
myProcess.StartInfo.Arguments = string.Format("-command \"{0}\"", MAYA_COMMANDS);
200+
#endif
201+
myProcess.EnableRaisingEvents = true;
202+
myProcess.Start();
203+
myProcess.WaitForExit();
204+
ExitCode = myProcess.ExitCode;
205+
}
206+
catch (Exception e)
207+
{
208+
UnityEngine.Debug.LogError(string.Format ("Exception failed to start Maya ({0})", e.Message));
209+
ExitCode = -1;
210+
}
211+
return ExitCode;
212+
}
213+
214+
public static bool InstallMaya(string version, bool verbose = false)
158215
{
159216
// check if package installed
160217
string moduleTemplatePath = GetModuleTemplatePath(version);
@@ -249,15 +306,12 @@ public static bool InstallMaya(string version, bool verbose=true)
249306

250307
public static void InstallMaya2017()
251308
{
252-
const bool verbose = true;
253309
const string version = Integrations.MAYA_VERSION;
254310

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

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));
313+
if (!InstallMaya (version)) {
314+
Debug.LogError (string.Format ("Failed to install Maya {0} Integration.", version));
261315
}
262316
}
263317
}
@@ -266,19 +320,24 @@ namespace Editors
266320
{
267321
class IntegrationsUI
268322
{
269-
const string MenuItemName = "FbxExporters/Install Maya" + Integrations.MAYA_VERSION + " Integration" ;
323+
const string MenuItemName1 = "FbxExporters/Install Maya" + Integrations.MAYA_VERSION + " Integration";
270324

271-
[MenuItem (MenuItemName, false, 0)]
272-
public static void OnMenuItem ()
325+
[MenuItem (MenuItemName1, false, 0)]
326+
public static void OnMenuItem1 ()
273327
{
274328
if (Integrations.InstallMaya(Integrations.MAYA_VERSION))
275329
{
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);
330+
int exitCode = Integrations.ConfigureMaya (Integrations.MAYA_VERSION);
331+
332+
string title = string.Format("Completed installation of Maya{0} Integration.", Integrations.MAYA_VERSION);
333+
string message = "Maya will close when it has finished configuring integration.";
334+
335+
if (exitCode!=0)
336+
{
337+
message = string.Format("Failed to configure Maya, please check logs (exitcode={0})", exitCode);
338+
}
279339

280-
EditorUtility.DisplayDialog (title, message, "Ok");
281-
Debug.Log(message);
340+
UnityEditor.EditorUtility.DisplayDialog (title, message, "Ok");
282341
}
283342
}
284343
}

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

Assets/Integrations/Autodesk/maya2017/plug-ins/unityOneClickPlugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
kPluginInfo = { 'name': version.pluginName(), 'version': version.versionName(), 'vendor': version.vendorName() }
2626
kVerbose = True
27-
kHeadlessInstall = maya.cmds.optionVar( exists='UnityOneClick_Headless' )
27+
kHeadlessInstall = maya.cmds.optionVar( exists='UnityOneClick_Headless' ) and maya.cmds.optionVar( q='UnityOneClick_Headless' ) == 1
2828

2929
# initialize the script plug-in
3030
def initializePlugin(mobject):
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)