@@ -14,7 +14,15 @@ 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
-
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
+ } }
18
26
private static Char [ ] FIELD_SEPARATORS = new Char [ ] { ':' } ;
19
27
20
28
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 )
154
162
}
155
163
}
156
164
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 )
158
215
{
159
216
// check if package installed
160
217
string moduleTemplatePath = GetModuleTemplatePath ( version ) ;
@@ -249,15 +306,12 @@ public static bool InstallMaya(string version, bool verbose=true)
249
306
250
307
public static void InstallMaya2017 ( )
251
308
{
252
- const bool verbose = true ;
253
309
const string version = Integrations . MAYA_VERSION ;
254
310
255
311
Debug . Log ( string . Format ( "Installing Maya {0} Integration" , version ) ) ;
256
312
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 ) ) ;
261
315
}
262
316
}
263
317
}
@@ -266,19 +320,24 @@ namespace Editors
266
320
{
267
321
class IntegrationsUI
268
322
{
269
- const string MenuItemName = "FbxExporters/Install Maya" + Integrations . MAYA_VERSION + " Integration" ;
323
+ const string MenuItemName1 = "FbxExporters/Install Maya" + Integrations . MAYA_VERSION + " Integration" ;
270
324
271
- [ MenuItem ( MenuItemName , false , 0 ) ]
272
- public static void OnMenuItem ( )
325
+ [ MenuItem ( MenuItemName1 , false , 0 ) ]
326
+ public static void OnMenuItem1 ( )
273
327
{
274
328
if ( Integrations . InstallMaya ( Integrations . MAYA_VERSION ) )
275
329
{
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
+ }
279
339
280
- EditorUtility . DisplayDialog ( title , message , "Ok" ) ;
281
- Debug . Log ( message ) ;
340
+ UnityEditor . EditorUtility . DisplayDialog ( title , message , "Ok" ) ;
282
341
}
283
342
}
284
343
}
0 commit comments