@@ -70,41 +70,46 @@ class MayaIntegration : DCCIntegration
70
70
{
71
71
public override string DccDisplayName { get { return "Maya" ; } }
72
72
73
- private const string MODULE_FILENAME = "UnityFbxForMaya" ;
73
+ public override string IntegrationZipPath { get { return "FbxExporters/UnityFbxForMaya.zip" ; } }
74
+
75
+ public const string TEMP_SAVE_PATH = "_safe_to_delete" ;
76
+
77
+ protected virtual string FBX_EXPORT_SETTINGS_PATH { get { return "/Integrations/Autodesk/maya/scripts/unityFbxExportSettings.mel" ; } }
78
+
79
+ protected virtual string MODULE_TEMPLATE_PATH { get { return "Integrations/Autodesk/maya/" + MODULE_FILENAME + ".txt" ; } }
80
+ protected virtual string MODULE_FILENAME { get { return "UnityFbxForMaya" ; } }
81
+
74
82
private const string PACKAGE_NAME = "FbxExporters" ;
75
83
private const string VERSION_FILENAME = "README.txt" ;
76
84
private const string VERSION_FIELD = "VERSION" ;
77
85
private const string VERSION_TAG = "{Version}" ;
78
86
private const string PROJECT_TAG = "{UnityProject}" ;
79
87
private const string INTEGRATION_TAG = "{UnityIntegrationsPath}" ;
80
88
81
- private const string FBX_EXPORT_SETTINGS_PATH = "/Integrations/Autodesk/maya/scripts/unityFbxExportSettings.mel" ;
82
-
83
89
private const string MAYA_INSTRUCTION_FILENAME = "_safe_to_delete/_temp.txt" ;
84
90
85
- public override string IntegrationZipPath { get { return "FbxExporters/UnityFbxForMaya.zip" ; } }
86
-
87
- public const string MODULE_TEMPLATE_PATH = "Integrations/Autodesk/maya/" + MODULE_FILENAME + ".txt" ;
88
-
89
- public const string TEMP_SAVE_PATH = "_safe_to_delete" ;
90
-
91
-
92
- private static string MAYA_MODULES_PATH {
91
+ protected static string MAYA_DOCUMENTS_PATH {
93
92
get {
94
93
switch ( Application . platform ) {
95
94
case RuntimePlatform . WindowsEditor :
96
- return "maya/modules " ;
95
+ return "maya" ;
97
96
case RuntimePlatform . OSXEditor :
98
- return "Library/Preferences/Autodesk/Maya/modules " ;
97
+ return "Library/Preferences/Autodesk/Maya" ;
99
98
default :
100
99
throw new NotImplementedException ( ) ;
101
100
}
102
101
}
103
102
}
104
103
104
+ private static string MAYA_MODULES_PATH {
105
+ get {
106
+ return System . IO . Path . Combine ( GetUserFolder ( ) , MAYA_DOCUMENTS_PATH + "/modules" ) ;
107
+ }
108
+ }
109
+
105
110
// Use string to define escaped quote
106
111
// Windows needs the backslash
107
- private static string ESCAPED_QUOTE {
112
+ protected static string ESCAPED_QUOTE {
108
113
get {
109
114
switch ( Application . platform ) {
110
115
case RuntimePlatform . WindowsEditor :
@@ -117,14 +122,14 @@ private static string ESCAPED_QUOTE {
117
122
}
118
123
}
119
124
120
- private static string MAYA_COMMANDS { get {
125
+ protected virtual string MAYA_COMMANDS { get {
121
126
return string . Format ( "configureUnityFbxForMaya {0}{1}{0} {0}{2}{0} {0}{3}{0} {0}{4}{0} {0}{5}{0} {6}; scriptJob -idleEvent quit;" ,
122
127
ESCAPED_QUOTE , GetProjectPath ( ) , GetAppPath ( ) , GetTempSavePath ( ) ,
123
128
GetExportSettingsPath ( ) , GetMayaInstructionPath ( ) , ( IsHeadlessInstall ( ) ? 1 : 0 ) ) ;
124
129
} }
125
130
private static Char [ ] FIELD_SEPARATORS = new Char [ ] { ':' } ;
126
131
127
- private static string GetUserFolder ( )
132
+ protected static string GetUserFolder ( )
128
133
{
129
134
switch ( Application . platform ) {
130
135
case RuntimePlatform . WindowsEditor :
@@ -141,12 +146,7 @@ public static bool IsHeadlessInstall ()
141
146
return false ;
142
147
}
143
148
144
- public static string GetModulePath ( )
145
- {
146
- return System . IO . Path . Combine ( GetUserFolder ( ) , MAYA_MODULES_PATH ) ;
147
- }
148
-
149
- public static string GetModuleTemplatePath ( )
149
+ public string GetModuleTemplatePath ( )
150
150
{
151
151
return System . IO . Path . Combine ( INTEGRATION_FOLDER_PATH , MODULE_TEMPLATE_PATH ) ;
152
152
}
@@ -190,7 +190,7 @@ public static string GetFullMayaInstructionPath()
190
190
/// Returns a relative path with forward slashes as path separators.
191
191
/// </summary>
192
192
/// <returns>The export settings path.</returns>
193
- public static string GetExportSettingsPath ( )
193
+ public string GetExportSettingsPath ( )
194
194
{
195
195
return INTEGRATION_FOLDER_PATH + FBX_EXPORT_SETTINGS_PATH ;
196
196
}
@@ -290,7 +290,32 @@ private static void WriteFile(string FileName, List<string> Lines )
290
290
}
291
291
}
292
292
293
- public static int ConfigureMaya ( string mayaPath )
293
+ /// <summary>
294
+ /// Creates the missing directories in path.
295
+ /// </summary>
296
+ /// <returns><c>true</c>, if directory was created, <c>false</c> otherwise.</returns>
297
+ /// <param name="path">Path to create.</param>
298
+ /// <param name="name">Display name of directory.</param>
299
+ protected static bool CreateDirectory ( string path , string name ) {
300
+ try
301
+ {
302
+ System . IO . Directory . CreateDirectory ( path ) ;
303
+ }
304
+ catch ( Exception xcp )
305
+ {
306
+ Debug . LogException ( xcp ) ;
307
+ Debug . LogError ( string . Format ( "Failed to create {0} Folder {1}" , name , path ) ) ;
308
+ return false ;
309
+ }
310
+
311
+ if ( ! System . IO . Directory . Exists ( path ) ) {
312
+ Debug . LogError ( string . Format ( "Failed to create {0} Folder {1}" , name , path ) ) ;
313
+ return false ;
314
+ }
315
+ return true ;
316
+ }
317
+
318
+ public int ConfigureMaya ( string mayaPath )
294
319
{
295
320
int ExitCode = 0 ;
296
321
@@ -333,7 +358,7 @@ public static int ConfigureMaya(string mayaPath)
333
358
return ExitCode ;
334
359
}
335
360
336
- public static bool InstallMaya ( bool verbose = false )
361
+ public virtual bool InstallMaya ( bool verbose = false )
337
362
{
338
363
// What's happening here is that we copy the module template to
339
364
// the module path, basically:
@@ -350,30 +375,16 @@ public static bool InstallMaya(bool verbose = false)
350
375
}
351
376
352
377
// Create the {USER} modules folder and empty it so it's ready to set up.
353
- string modulePath = GetModulePath ( ) ;
378
+ string modulePath = MAYA_MODULES_PATH ;
354
379
string moduleFilePath = System . IO . Path . Combine ( modulePath , MODULE_FILENAME + ".mod" ) ;
355
380
bool installed = false ;
356
381
357
382
if ( ! System . IO . Directory . Exists ( modulePath ) )
358
383
{
359
384
if ( verbose ) { Debug . Log ( string . Format ( "Creating Maya Modules Folder {0}" , modulePath ) ) ; }
360
-
361
- try
362
- {
363
- System . IO . Directory . CreateDirectory ( modulePath ) ;
364
- }
365
- catch ( Exception xcp )
366
- {
367
- Debug . LogException ( xcp ) ;
368
- Debug . LogError ( string . Format ( "Failed to create Maya Modules Folder {0}" , modulePath ) ) ;
369
- return false ;
370
- }
371
-
372
- if ( ! System . IO . Directory . Exists ( modulePath ) ) {
373
- Debug . LogError ( string . Format ( "Failed to create Maya Modules Folder {0}" , modulePath ) ) ;
385
+ if ( ! CreateDirectory ( modulePath , "Maya Modules" ) ) {
374
386
return false ;
375
387
}
376
-
377
388
installed = false ;
378
389
}
379
390
else
@@ -436,11 +447,11 @@ public static bool InstallMaya(bool verbose = false)
436
447
437
448
public override int InstallIntegration ( string mayaExe )
438
449
{
439
- if ( ! MayaIntegration . InstallMaya ( verbose : true ) ) {
450
+ if ( ! InstallMaya ( verbose : true ) ) {
440
451
return - 1 ;
441
452
}
442
453
443
- return MayaIntegration . ConfigureMaya ( mayaExe ) ;
454
+ return ConfigureMaya ( mayaExe ) ;
444
455
}
445
456
446
457
/// <summary>
@@ -451,7 +462,116 @@ public override int InstallIntegration (string mayaExe)
451
462
/// <param name="path">Path.</param>
452
463
public override bool FolderAlreadyUnzippedAtPath ( string path )
453
464
{
454
- return System . IO . File . Exists ( System . IO . Path . Combine ( path , MayaIntegration . MODULE_TEMPLATE_PATH ) ) ;
465
+ return System . IO . File . Exists ( System . IO . Path . Combine ( path , MODULE_TEMPLATE_PATH ) ) ;
466
+ }
467
+ }
468
+
469
+ class MayaLTIntegration : MayaIntegration
470
+ {
471
+ public override string DccDisplayName { get { return "Maya LT" ; } }
472
+
473
+ public override string IntegrationZipPath { get { return "FbxExporters/UnityFbxForMayaLT.zip" ; } }
474
+
475
+ protected override string MODULE_TEMPLATE_PATH { get { return "Integrations/Autodesk/mayalt/" + MODULE_FILENAME + ".txt" ; } }
476
+
477
+ protected override string MODULE_FILENAME { get { return "UnityFbxForMayaLT" ; } }
478
+
479
+ protected override string FBX_EXPORT_SETTINGS_PATH { get { return "/Integrations/Autodesk/mayalt/scripts/unityFbxExportSettings.mel" ; } }
480
+
481
+ protected string FBX_IMPORT_SETTINGS_PATH { get { return "/Integrations/Autodesk/mayalt/scripts/unityFbxImportSettings.mel" ; } }
482
+
483
+ private const string MAYA_USER_STARTUP_SCRIPT = "userSetup.mel" ;
484
+
485
+ private const string USER_STARTUP_CALL = "if(`exists setupUnityUI`){ setupUnityUI; }" ;
486
+
487
+ protected override string MAYA_COMMANDS { get {
488
+ return string . Format ( "configureUnityFbxForMayaLT {0}{1}{0} {0}{2}{0} {0}{3}{0} {4}; scriptJob -idleEvent quit;" ,
489
+ ESCAPED_QUOTE , GetProjectPath ( ) , GetExportSettingsPath ( ) , GetImportSettingsPath ( ) , ( IsHeadlessInstall ( ) ? 1 : 0 ) ) ;
490
+ } }
491
+
492
+
493
+ private static string MAYA_SCRIPTS_PATH {
494
+ get {
495
+ return System . IO . Path . Combine ( GetUserFolder ( ) , MAYA_DOCUMENTS_PATH + "/scripts" ) ;
496
+ }
497
+ }
498
+
499
+ /// <summary>
500
+ /// Gets the path to the import settings file.
501
+ /// Returns a relative path with forward slashes as path separators.
502
+ /// </summary>
503
+ /// <returns>The import settings path.</returns>
504
+ public string GetImportSettingsPath ( ) {
505
+ return INTEGRATION_FOLDER_PATH + FBX_IMPORT_SETTINGS_PATH ;
506
+ }
507
+
508
+ /// <summary>
509
+ /// Gets the user startup script path.
510
+ /// Returns a relative path with forward slashes as path separators.
511
+ /// </summary>
512
+ /// <returns>The user startup script path.</returns>
513
+ private static string GetUserStartupScriptPath ( ) {
514
+ return MAYA_SCRIPTS_PATH + "/" + MAYA_USER_STARTUP_SCRIPT ;
515
+ }
516
+
517
+ public override bool InstallMaya ( bool verbose = false )
518
+ {
519
+ if ( ! base . InstallMaya ( verbose ) ) {
520
+ return false ;
521
+ }
522
+
523
+ // setup user startup script
524
+ string mayaStartupScript = GetUserStartupScriptPath ( ) ;
525
+ string fileContents = string . Format ( "\n {0}" , USER_STARTUP_CALL ) ;
526
+
527
+ // make sure scripts directory exists
528
+ if ( ! System . IO . Directory . Exists ( MAYA_SCRIPTS_PATH ) )
529
+ {
530
+ if ( verbose ) { Debug . Log ( string . Format ( "Creating Maya Scripts Folder {0}" , MAYA_SCRIPTS_PATH ) ) ; }
531
+ if ( ! CreateDirectory ( MAYA_SCRIPTS_PATH , "Maya Scripts" ) ) {
532
+ return false ;
533
+ }
534
+ }
535
+ else if ( System . IO . File . Exists ( mayaStartupScript ) ) {
536
+ // script exists, check that the UI setup is being called
537
+ try {
538
+ using ( System . IO . StreamReader sr = new System . IO . StreamReader ( mayaStartupScript ) ) {
539
+ while ( sr . Peek ( ) >= 0 ) {
540
+ string line = sr . ReadLine ( ) ;
541
+ if ( line . Trim ( ) . Contains ( USER_STARTUP_CALL ) ) {
542
+ // startup call already in the file, nothing to do
543
+ return true ;
544
+ }
545
+ }
546
+ }
547
+ }
548
+ catch ( Exception e ) {
549
+ Debug . LogException ( e ) ;
550
+ Debug . LogError ( string . Format ( "Exception while reading user startup file ({0})" , e . Message ) ) ;
551
+ return false ;
552
+ }
553
+ }
554
+
555
+ // append text to file
556
+ try {
557
+ System . IO . File . AppendAllText ( mayaStartupScript , fileContents ) ;
558
+ }
559
+ catch ( Exception e )
560
+ {
561
+ Debug . LogException ( e ) ;
562
+ Debug . LogError ( string . Format ( "Exception while writing to user startup file ({0})" , e . Message ) ) ;
563
+ return false ;
564
+ }
565
+ return true ;
566
+ }
567
+
568
+ public override int InstallIntegration ( string mayaLTExe )
569
+ {
570
+ if ( ! InstallMaya ( verbose : true ) ) {
571
+ return - 1 ;
572
+ }
573
+
574
+ return ConfigureMaya ( mayaLTExe ) ;
455
575
}
456
576
}
457
577
0 commit comments