@@ -14,6 +14,7 @@ class Integrations
14
14
private const string VERSION_FIELD = "**Version**" ;
15
15
private const string VERSION_TAG = "{Version}" ;
16
16
private const string PROJECT_TAG = "{UnityProject}" ;
17
+ private static string MAYA_COMMANDS { get { return string . Format ( @"configureUnityOneClick {1}{0}{1};" , Integrations . GetProjectPath ( ) , @"" + ( char ) 34 ) ; } }
17
18
18
19
private static Char [ ] FIELD_SEPARATORS = new Char [ ] { ':' } ;
19
20
@@ -36,6 +37,21 @@ private static string GetUserFolder()
36
37
#endif
37
38
}
38
39
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
+
39
55
private static string GetModulePath ( string version )
40
56
{
41
57
string result = System . IO . Path . Combine ( GetUserFolder ( ) , REL_MAYA_MODULES_PATH ) ;
@@ -154,7 +170,41 @@ private static void WriteFile(string FileName, List<string> Lines )
154
170
}
155
171
}
156
172
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 )
158
208
{
159
209
// check if package installed
160
210
string moduleTemplatePath = GetModuleTemplatePath ( version ) ;
@@ -249,15 +299,12 @@ public static bool InstallMaya(string version, bool verbose=true)
249
299
250
300
public static void InstallMaya2017 ( )
251
301
{
252
- const bool verbose = true ;
253
302
const string version = Integrations . MAYA_VERSION ;
254
303
255
304
Debug . Log ( string . Format ( "Installing Maya {0} Integration" , version ) ) ;
256
305
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 ) ) ;
261
308
}
262
309
}
263
310
}
@@ -266,19 +313,24 @@ namespace Editors
266
313
{
267
314
class IntegrationsUI
268
315
{
269
- const string MenuItemName = "FbxExporters/Install Maya" + Integrations . MAYA_VERSION + " Integration" ;
316
+ const string MenuItemName1 = "FbxExporters/Install Maya" + Integrations . MAYA_VERSION + " Integration" ;
270
317
271
- [ MenuItem ( MenuItemName , false , 0 ) ]
272
- public static void OnMenuItem ( )
318
+ [ MenuItem ( MenuItemName1 , false , 0 ) ]
319
+ public static void OnMenuItem1 ( )
273
320
{
274
321
if ( Integrations . InstallMaya ( Integrations . MAYA_VERSION ) )
275
322
{
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
+ }
279
332
280
- EditorUtility . DisplayDialog ( title , message , "Ok" ) ;
281
- Debug . Log ( message ) ;
333
+ UnityEditor . EditorUtility . DisplayDialog ( title , message , "Ok" ) ;
282
334
}
283
335
}
284
336
}
0 commit comments