Skip to content

Commit 29c242f

Browse files
committed
refactor to add abstract DCCIntegration class
that both MayaIntegration and MaxIntegration inherit from. Also renamed Integrations to MayaIntegration
1 parent 3a2b994 commit 29c242f

File tree

3 files changed

+124
-144
lines changed

3 files changed

+124
-144
lines changed

Assets/FbxExporters/Editor/InstallIntegration.cs

Lines changed: 108 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,13 @@
22
using UnityEditor;
33
using System;
44
using System.Collections.Generic;
5-
using FbxExporters.EditorTools;
65

76
namespace FbxExporters.Editor
87
{
9-
class Integrations
8+
abstract class DCCIntegration
109
{
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; }
2212

2313
private static string m_integrationFolderPath = null;
2414
public static string INTEGRATION_FOLDER_PATH
@@ -38,6 +28,53 @@ public static string INTEGRATION_FOLDER_PATH
3828
}
3929
}
4030

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+
4178
public const string MODULE_TEMPLATE_PATH = "Integrations/Autodesk/maya/" + MODULE_FILENAME + ".txt";
4279

4380
#if UNITY_EDITOR_OSX
@@ -123,7 +160,7 @@ public static string GetMayaInstructionPath()
123160
/// <returns>The full maya instruction path.</returns>
124161
public static string GetFullMayaInstructionPath()
125162
{
126-
return Application.dataPath + "/" + FbxExporters.Editor.Integrations.GetMayaInstructionPath ();
163+
return Application.dataPath + "/" + FbxExporters.Editor.MayaIntegration.GetMayaInstructionPath ();
127164
}
128165

129166
/// <summary>
@@ -369,10 +406,33 @@ public static bool InstallMaya(bool verbose = false)
369406

370407
return true;
371408
}
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+
}
372430
}
373431

374-
class MaxIntegration
432+
class MaxIntegration : DCCIntegration
375433
{
434+
public override string DccDisplayName { get { return "3Ds Max"; } }
435+
376436
private const string MaxScriptsPath = "Integrations/Autodesk/max/scripts/";
377437

378438
private const string PluginName = "UnityFbxForMaxPlugin.ms";
@@ -387,31 +447,15 @@ class MaxIntegration
387447
private const string ProjectTag = "UnityProject";
388448
private const string ExportSettingsTag = "UnityFbxExportSettings";
389449

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"; } }
407451

408452
/// <summary>
409453
/// Gets the absolute Unity path for relative path in Integrations folder.
410454
/// </summary>
411455
/// <returns>The absolute path.</returns>
412456
/// <param name="relPath">Relative path.</param>
413457
public static string GetAbsPath(string relPath){
414-
return Integrations.INTEGRATION_FOLDER_PATH + "/" + relPath;
458+
return MayaIntegration.INTEGRATION_FOLDER_PATH + "/" + relPath;
415459
}
416460

417461
private static string GetInstallScript(){
@@ -471,6 +515,21 @@ public static int InstallMaxPlugin(string maxExe){
471515
}
472516
return ExitCode;
473517
}
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+
}
474533
}
475534

476535
class IntegrationsUI
@@ -498,9 +557,6 @@ private static void ShowSuccessDialog(string dcc, int exitCode){
498557
UnityEditor.EditorUtility.DisplayDialog (title, message, "Ok");
499558
}
500559

501-
const string MayaIntegrationZipPath = "FbxExporters/UnityFbxForMaya.zip";
502-
const string MaxIntegrationZipPath = "FbxExporters/UnityFbxForMax.zip";
503-
504560
private static string DefaultIntegrationSavePath
505561
{
506562
get{
@@ -518,76 +574,38 @@ public static void InstallDCCIntegration ()
518574
}
519575

520576
string dccType = System.IO.Path.GetFileNameWithoutExtension (dccExe).ToLower();
577+
DCCIntegration dccIntegration;
521578
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 ();
537584
}
538585

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);
546589
}
547590

548-
private static void GetIntegrationFolder(ExportSettings.DCCType dcc){
591+
private static void GetIntegrationFolder(DCCIntegration dcc){
549592
// decompress zip file if it exists, otherwise try using default location
550-
var zipPath = GetIntegrationZipFullPath(dcc);
593+
var zipPath = dcc.GetIntegrationZipFullPath();
551594
if (System.IO.File.Exists (zipPath)) {
552595
var result = DecompressIntegrationZipFile (zipPath, dcc);
553596
if (!result) {
554597
// could not find integration
555598
return;
556599
}
557600
} 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);
572602
}
573603
}
574604

575-
private static bool DecompressIntegrationZipFile(string zipPath, ExportSettings.DCCType dcc)
605+
private static bool DecompressIntegrationZipFile(string zipPath, DCCIntegration dcc)
576606
{
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-
589607
// 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,"");
591609
if (string.IsNullOrEmpty (unzipFolder)) {
592610
// user has cancelled, do nothing
593611
return false;
@@ -613,7 +631,7 @@ private static bool DecompressIntegrationZipFile(string zipPath, ExportSettings.
613631

614632
// if file already unzipped in this location, then prompt user
615633
// if they would like to continue unzipping or use what is there
616-
if (FolderAlreadyUnzippedAtPath (unzipFolder, dcc)) {
634+
if (dcc.FolderAlreadyUnzippedAtPath (unzipFolder)) {
617635
var result = UnityEditor.EditorUtility.DisplayDialogComplex ("Integrations Exist at Path",
618636
string.Format ("Directory \"{0}\" already contains the decompressed integration", unzipFolder),
619637
"Overwrite",
@@ -631,49 +649,11 @@ private static bool DecompressIntegrationZipFile(string zipPath, ExportSettings.
631649
DecompressZip (zipPath, unzipFolder);
632650
}
633651

634-
SetIntegrationFolderPath(unzipFolder, dcc);
652+
dcc.SetIntegrationFolderPath(unzipFolder);
635653

636654
return true;
637655
}
638656

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-
677657
/// <summary>
678658
/// Make sure we can write to this directory.
679659
/// Try creating a file in path directory, if it raises an error, then we can't

Assets/FbxExporters/Editor/ReviewLastSavedModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static void OnPostprocessAllAssets(
3333
foreach (var assetPath in importedAssets) {
3434
if (assetPath.StartsWith(tempSavePath) && assetPath.EndsWith(".fbx")) {
3535
// if the instruction file exists, then run the turntable and delete the file
36-
string instructionFile = FbxExporters.Editor.Integrations.GetFullMayaInstructionPath ();
36+
string instructionFile = FbxExporters.Editor.MayaIntegration.GetFullMayaInstructionPath ();
3737
if(System.IO.File.Exists(instructionFile)){
3838
LastSavedModel ();
3939
System.IO.File.Delete (instructionFile);

Assets/FbxExporters/Editor/UnitTests/IntegrationsTest.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,25 @@ void LogNonEmptyString(string name, string str) {
2727

2828
[Test]
2929
public void BasicTest() {
30-
Assert.IsFalse(Editor.Integrations.IsHeadlessInstall());
30+
Assert.IsFalse(Editor.MayaIntegration.IsHeadlessInstall());
3131

32-
LogNonEmptyString("module path", Editor.Integrations.GetModulePath());
33-
LogNonEmptyString("module template path", Editor.Integrations.GetModuleTemplatePath());
32+
LogNonEmptyString("module path", Editor.MayaIntegration.GetModulePath());
33+
LogNonEmptyString("module template path", Editor.MayaIntegration.GetModuleTemplatePath());
3434

35-
LogNonEmptyString("app path", Editor.Integrations.GetAppPath());
36-
LogNonEmptyString("project path", Editor.Integrations.GetProjectPath());
37-
LogNonEmptyString("package path", Editor.Integrations.GetPackagePath());
38-
LogNonEmptyString("package version", Editor.Integrations.GetPackageVersion());
39-
LogNonEmptyString("temp path", Editor.Integrations.GetTempSavePath());
40-
LogNonEmptyString("export settings path", Editor.Integrations.GetExportSettingsPath ());
41-
LogNonEmptyString ("instruction path", Editor.Integrations.GetMayaInstructionPath ());
42-
LogNonEmptyString ("full instruction path", Editor.Integrations.GetFullMayaInstructionPath ());
35+
LogNonEmptyString("app path", Editor.MayaIntegration.GetAppPath());
36+
LogNonEmptyString("project path", Editor.MayaIntegration.GetProjectPath());
37+
LogNonEmptyString("package path", Editor.MayaIntegration.GetPackagePath());
38+
LogNonEmptyString("package version", Editor.MayaIntegration.GetPackageVersion());
39+
LogNonEmptyString("temp path", Editor.MayaIntegration.GetTempSavePath());
40+
LogNonEmptyString("export settings path", Editor.MayaIntegration.GetExportSettingsPath ());
41+
LogNonEmptyString ("instruction path", Editor.MayaIntegration.GetMayaInstructionPath ());
42+
LogNonEmptyString ("full instruction path", Editor.MayaIntegration.GetFullMayaInstructionPath ());
4343

4444
// test that the paths don't contain backslashes
45-
Assert.IsFalse(Editor.Integrations.GetAppPath().Contains("\\"));
46-
Assert.IsFalse(Editor.Integrations.GetProjectPath().Contains("\\"));
47-
Assert.IsFalse(Editor.Integrations.GetTempSavePath().Contains("\\"));
48-
Assert.IsFalse(Editor.Integrations.GetExportSettingsPath ().Contains("\\"));
45+
Assert.IsFalse(Editor.MayaIntegration.GetAppPath().Contains("\\"));
46+
Assert.IsFalse(Editor.MayaIntegration.GetProjectPath().Contains("\\"));
47+
Assert.IsFalse(Editor.MayaIntegration.GetTempSavePath().Contains("\\"));
48+
Assert.IsFalse(Editor.MayaIntegration.GetExportSettingsPath ().Contains("\\"));
4949
}
5050
}
5151
}

0 commit comments

Comments
 (0)