2
2
using UnityEditor ;
3
3
using System ;
4
4
using System . Collections . Generic ;
5
- using FbxExporters . EditorTools ;
6
5
7
6
namespace FbxExporters . Editor
8
7
{
9
- class Integrations
8
+ abstract class DCCIntegration
10
9
{
11
- private const string MODULE_FILENAME = "unityoneclick" ;
12
- private const string PACKAGE_NAME = "FbxExporters" ;
13
- private const string VERSION_FILENAME = "README.txt" ;
14
- private const string VERSION_FIELD = "VERSION" ;
15
- private const string VERSION_TAG = "{Version}" ;
16
- private const string PROJECT_TAG = "{UnityProject}" ;
17
- private const string INTEGRATION_TAG = "{UnityIntegrationsPath}" ;
18
-
19
- private const string FBX_EXPORT_SETTINGS_PATH = "/Integrations/Autodesk/maya/scripts/unityFbxExportSettings.mel" ;
20
-
21
- private const string MAYA_INSTRUCTION_FILENAME = "_safe_to_delete/_temp.txt" ;
10
+ public abstract string DccDisplayName { get ; }
11
+ public abstract string IntegrationZipPath { get ; }
22
12
23
13
private static string m_integrationFolderPath = null ;
24
14
public static string INTEGRATION_FOLDER_PATH
@@ -38,6 +28,53 @@ public static string INTEGRATION_FOLDER_PATH
38
28
}
39
29
}
40
30
31
+ public void SetIntegrationFolderPath ( string path ) {
32
+ INTEGRATION_FOLDER_PATH = path ;
33
+ }
34
+
35
+ /// <summary>
36
+ /// Gets the integration zip full path as an absolute Unity-style path.
37
+ /// </summary>
38
+ /// <returns>The integration zip full path.</returns>
39
+ public string GetIntegrationZipFullPath ( )
40
+ {
41
+ return Application . dataPath + "/" + IntegrationZipPath ;
42
+ }
43
+
44
+ /// <summary>
45
+ /// Installs the integration using the provided executable.
46
+ /// </summary>
47
+ /// <returns>The integration.</returns>
48
+ /// <param name="exe">Exe.</param>
49
+ public abstract int InstallIntegration ( string exe ) ;
50
+
51
+ /// <summary>
52
+ /// Determines if folder is already unzipped at the specified path.
53
+ /// </summary>
54
+ /// <returns><c>true</c> if folder is already unzipped at the specified path; otherwise, <c>false</c>.</returns>
55
+ /// <param name="path">Path.</param>
56
+ public abstract bool FolderAlreadyUnzippedAtPath ( string path ) ;
57
+ }
58
+
59
+
60
+ class MayaIntegration : DCCIntegration
61
+ {
62
+ public override string DccDisplayName { get { return "Maya" ; } }
63
+
64
+ private const string MODULE_FILENAME = "unityoneclick" ;
65
+ private const string PACKAGE_NAME = "FbxExporters" ;
66
+ private const string VERSION_FILENAME = "README.txt" ;
67
+ private const string VERSION_FIELD = "VERSION" ;
68
+ private const string VERSION_TAG = "{Version}" ;
69
+ private const string PROJECT_TAG = "{UnityProject}" ;
70
+ private const string INTEGRATION_TAG = "{UnityIntegrationsPath}" ;
71
+
72
+ private const string FBX_EXPORT_SETTINGS_PATH = "/Integrations/Autodesk/maya/scripts/unityFbxExportSettings.mel" ;
73
+
74
+ private const string MAYA_INSTRUCTION_FILENAME = "_safe_to_delete/_temp.txt" ;
75
+
76
+ public override string IntegrationZipPath { get { return "FbxExporters/UnityFbxForMaya.zip" ; } }
77
+
41
78
public const string MODULE_TEMPLATE_PATH = "Integrations/Autodesk/maya/" + MODULE_FILENAME + ".txt" ;
42
79
43
80
#if UNITY_EDITOR_OSX
@@ -123,7 +160,7 @@ public static string GetMayaInstructionPath()
123
160
/// <returns>The full maya instruction path.</returns>
124
161
public static string GetFullMayaInstructionPath ( )
125
162
{
126
- return Application . dataPath + "/" + FbxExporters . Editor . Integrations . GetMayaInstructionPath ( ) ;
163
+ return Application . dataPath + "/" + FbxExporters . Editor . MayaIntegration . GetMayaInstructionPath ( ) ;
127
164
}
128
165
129
166
/// <summary>
@@ -369,10 +406,33 @@ public static bool InstallMaya(bool verbose = false)
369
406
370
407
return true ;
371
408
}
409
+
410
+
411
+ public override int InstallIntegration ( string mayaExe )
412
+ {
413
+ if ( ! MayaIntegration . InstallMaya ( verbose : true ) ) {
414
+ return - 1 ;
415
+ }
416
+
417
+ return MayaIntegration . ConfigureMaya ( mayaExe ) ;
418
+ }
419
+
420
+ /// <summary>
421
+ /// Determines if folder is already unzipped at the specified path
422
+ /// by checking if unityoneclick.txt exists at expected location.
423
+ /// </summary>
424
+ /// <returns><c>true</c> if folder is already unzipped at the specified path; otherwise, <c>false</c>.</returns>
425
+ /// <param name="path">Path.</param>
426
+ public override bool FolderAlreadyUnzippedAtPath ( string path )
427
+ {
428
+ return System . IO . File . Exists ( System . IO . Path . Combine ( path , MayaIntegration . MODULE_TEMPLATE_PATH ) ) ;
429
+ }
372
430
}
373
431
374
- class MaxIntegration
432
+ class MaxIntegration : DCCIntegration
375
433
{
434
+ public override string DccDisplayName { get { return "3Ds Max" ; } }
435
+
376
436
private const string MaxScriptsPath = "Integrations/Autodesk/max/scripts/" ;
377
437
378
438
private const string PluginName = "UnityFbxForMaxPlugin.ms" ;
@@ -387,31 +447,15 @@ class MaxIntegration
387
447
private const string ProjectTag = "UnityProject" ;
388
448
private const string ExportSettingsTag = "UnityFbxExportSettings" ;
389
449
390
- private static string m_integrationFolderPath = null ;
391
- public static string INTEGRATION_FOLDER_PATH
392
- {
393
- get {
394
- if ( string . IsNullOrEmpty ( m_integrationFolderPath ) ) {
395
- m_integrationFolderPath = Application . dataPath ;
396
- }
397
- return m_integrationFolderPath ;
398
- }
399
- set {
400
- if ( ! string . IsNullOrEmpty ( value ) && System . IO . Directory . Exists ( value ) ) {
401
- m_integrationFolderPath = value ;
402
- } else {
403
- Debug . LogError ( string . Format ( "Failed to set integration folder path, invalid directory \" {0}\" " , value ) ) ;
404
- }
405
- }
406
- }
450
+ public override string IntegrationZipPath { get { return "FbxExporters/UnityFbxForMax.zip" ; } }
407
451
408
452
/// <summary>
409
453
/// Gets the absolute Unity path for relative path in Integrations folder.
410
454
/// </summary>
411
455
/// <returns>The absolute path.</returns>
412
456
/// <param name="relPath">Relative path.</param>
413
457
public static string GetAbsPath ( string relPath ) {
414
- return Integrations . INTEGRATION_FOLDER_PATH + "/" + relPath ;
458
+ return MayaIntegration . INTEGRATION_FOLDER_PATH + "/" + relPath ;
415
459
}
416
460
417
461
private static string GetInstallScript ( ) {
@@ -471,6 +515,21 @@ public static int InstallMaxPlugin(string maxExe){
471
515
}
472
516
return ExitCode ;
473
517
}
518
+
519
+ public override int InstallIntegration ( string maxExe ) {
520
+ return MaxIntegration . InstallMaxPlugin ( maxExe ) ;
521
+ }
522
+
523
+ /// <summary>
524
+ /// Determines if folder is already unzipped at the specified path
525
+ /// by checking if plugin exists at expected location.
526
+ /// </summary>
527
+ /// <returns><c>true</c> if folder is already unzipped at the specified path; otherwise, <c>false</c>.</returns>
528
+ /// <param name="path">Path.</param>
529
+ public override bool FolderAlreadyUnzippedAtPath ( string path )
530
+ {
531
+ return System . IO . File . Exists ( System . IO . Path . Combine ( path , MaxIntegration . PluginPath ) ) ;
532
+ }
474
533
}
475
534
476
535
class IntegrationsUI
@@ -498,9 +557,6 @@ private static void ShowSuccessDialog(string dcc, int exitCode){
498
557
UnityEditor . EditorUtility . DisplayDialog ( title , message , "Ok" ) ;
499
558
}
500
559
501
- const string MayaIntegrationZipPath = "FbxExporters/UnityFbxForMaya.zip" ;
502
- const string MaxIntegrationZipPath = "FbxExporters/UnityFbxForMax.zip" ;
503
-
504
560
private static string DefaultIntegrationSavePath
505
561
{
506
562
get {
@@ -518,76 +574,38 @@ public static void InstallDCCIntegration ()
518
574
}
519
575
520
576
string dccType = System . IO . Path . GetFileNameWithoutExtension ( dccExe ) . ToLower ( ) ;
577
+ DCCIntegration dccIntegration ;
521
578
if ( dccType . Equals ( "maya" ) ) {
522
- GetIntegrationFolder ( ExportSettings . DCCType . Maya ) ;
523
- InstallMayaIntegration ( dccExe ) ;
524
- return ;
525
- }
526
- if ( dccType . Equals ( "3dsmax" ) ) {
527
- GetIntegrationFolder ( ExportSettings . DCCType . Max ) ;
528
- InstallMaxIntegration ( dccExe ) ;
529
- return ;
530
- }
531
- }
532
-
533
- public static void InstallMayaIntegration ( string mayaExe )
534
- {
535
- if ( ! Integrations . InstallMaya ( verbose : true ) ) {
536
- return ;
579
+ dccIntegration = new MayaIntegration ( ) ;
580
+ } else if ( dccType . Equals ( "3dsmax" ) ) {
581
+ dccIntegration = new MaxIntegration ( ) ;
582
+ } else {
583
+ throw new System . NotImplementedException ( ) ;
537
584
}
538
585
539
- int exitCode = Integrations . ConfigureMaya ( mayaExe ) ;
540
- ShowSuccessDialog ( "Maya" , exitCode ) ;
541
- }
542
-
543
- public static void InstallMaxIntegration ( string maxExe ) {
544
- int exitCode = MaxIntegration . InstallMaxPlugin ( maxExe ) ;
545
- ShowSuccessDialog ( "3DsMax" , exitCode ) ;
586
+ GetIntegrationFolder ( dccIntegration ) ;
587
+ int exitCode = dccIntegration . InstallIntegration ( dccExe ) ;
588
+ ShowSuccessDialog ( dccIntegration . DccDisplayName , exitCode ) ;
546
589
}
547
590
548
- private static void GetIntegrationFolder ( ExportSettings . DCCType dcc ) {
591
+ private static void GetIntegrationFolder ( DCCIntegration dcc ) {
549
592
// decompress zip file if it exists, otherwise try using default location
550
- var zipPath = GetIntegrationZipFullPath ( dcc ) ;
593
+ var zipPath = dcc . GetIntegrationZipFullPath ( ) ;
551
594
if ( System . IO . File . Exists ( zipPath ) ) {
552
595
var result = DecompressIntegrationZipFile ( zipPath , dcc ) ;
553
596
if ( ! result ) {
554
597
// could not find integration
555
598
return ;
556
599
}
557
600
} else {
558
- SetIntegrationFolderPath ( DefaultIntegrationSavePath , dcc ) ;
559
- }
560
- }
561
-
562
- private static void SetIntegrationFolderPath ( string path , ExportSettings . DCCType dcc ) {
563
- switch ( dcc ) {
564
- case ExportSettings . DCCType . Max :
565
- MaxIntegration . INTEGRATION_FOLDER_PATH = path ;
566
- break ;
567
- case ExportSettings . DCCType . Maya :
568
- Integrations . INTEGRATION_FOLDER_PATH = path ;
569
- break ;
570
- default :
571
- throw new System . NotImplementedException ( ) ;
601
+ dcc . SetIntegrationFolderPath ( DefaultIntegrationSavePath ) ;
572
602
}
573
603
}
574
604
575
- private static bool DecompressIntegrationZipFile ( string zipPath , ExportSettings . DCCType dcc )
605
+ private static bool DecompressIntegrationZipFile ( string zipPath , DCCIntegration dcc )
576
606
{
577
- var dccName = "DCC" ;
578
- switch ( dcc ) {
579
- case ExportSettings . DCCType . Max :
580
- dccName = "3Ds Max" ;
581
- break ;
582
- case ExportSettings . DCCType . Maya :
583
- dccName = "Maya" ;
584
- break ;
585
- default :
586
- throw new System . NotImplementedException ( ) ;
587
- }
588
-
589
607
// prompt user to enter location to unzip file
590
- var unzipFolder = EditorUtility . OpenFolderPanel ( string . Format ( "Select Location to Save {0} Integration" , dccName ) , LastIntegrationSavePath , "" ) ;
608
+ var unzipFolder = EditorUtility . OpenFolderPanel ( string . Format ( "Select Location to Save {0} Integration" , dcc . DccDisplayName ) , LastIntegrationSavePath , "" ) ;
591
609
if ( string . IsNullOrEmpty ( unzipFolder ) ) {
592
610
// user has cancelled, do nothing
593
611
return false ;
@@ -613,7 +631,7 @@ private static bool DecompressIntegrationZipFile(string zipPath, ExportSettings.
613
631
614
632
// if file already unzipped in this location, then prompt user
615
633
// if they would like to continue unzipping or use what is there
616
- if ( FolderAlreadyUnzippedAtPath ( unzipFolder , dcc ) ) {
634
+ if ( dcc . FolderAlreadyUnzippedAtPath ( unzipFolder ) ) {
617
635
var result = UnityEditor . EditorUtility . DisplayDialogComplex ( "Integrations Exist at Path" ,
618
636
string . Format ( "Directory \" {0}\" already contains the decompressed integration" , unzipFolder ) ,
619
637
"Overwrite" ,
@@ -631,49 +649,11 @@ private static bool DecompressIntegrationZipFile(string zipPath, ExportSettings.
631
649
DecompressZip ( zipPath , unzipFolder ) ;
632
650
}
633
651
634
- SetIntegrationFolderPath ( unzipFolder , dcc ) ;
652
+ dcc . SetIntegrationFolderPath ( unzipFolder ) ;
635
653
636
654
return true ;
637
655
}
638
656
639
- /// <summary>
640
- /// Gets the integration zip full path as an absolute Unity-style path.
641
- /// </summary>
642
- /// <returns>The integration zip full path.</returns>
643
- private static string GetIntegrationZipFullPath ( ExportSettings . DCCType dcc )
644
- {
645
- var relPath = "" ;
646
- switch ( dcc ) {
647
- case ExportSettings . DCCType . Max :
648
- relPath = MaxIntegrationZipPath ;
649
- break ;
650
- case ExportSettings . DCCType . Maya :
651
- relPath = MayaIntegrationZipPath ;
652
- break ;
653
- default :
654
- throw new System . NotImplementedException ( ) ;
655
- }
656
- return Application . dataPath + "/" + relPath ;
657
- }
658
-
659
- /// <summary>
660
- /// Determines if folder is already unzipped at the specified path
661
- /// by checking if unityoneclick.txt exists at expected location.
662
- /// </summary>
663
- /// <returns><c>true</c> if folder is already unzipped at the specified path; otherwise, <c>false</c>.</returns>
664
- /// <param name="path">Path.</param>
665
- public static bool FolderAlreadyUnzippedAtPath ( string path , ExportSettings . DCCType dcc )
666
- {
667
- switch ( dcc ) {
668
- case ExportSettings . DCCType . Max :
669
- return System . IO . File . Exists ( System . IO . Path . Combine ( path , MaxIntegration . PluginPath ) ) ;
670
- case ExportSettings . DCCType . Maya :
671
- return System . IO . File . Exists ( System . IO . Path . Combine ( path , Integrations . MODULE_TEMPLATE_PATH ) ) ;
672
- default :
673
- throw new System . NotImplementedException ( ) ;
674
- }
675
- }
676
-
677
657
/// <summary>
678
658
/// Make sure we can write to this directory.
679
659
/// Try creating a file in path directory, if it raises an error, then we can't
0 commit comments