Skip to content

Commit ea31495

Browse files
committed
install integration for MayaLT
-add MayaLTIntegration install class deriving from MayaIntegration. In addition to installing the module file and setting up the optionVars, it adds a function call to the userSetup.mel script to setup the UI when MayaLT starts.
1 parent e7b2497 commit ea31495

File tree

2 files changed

+180
-44
lines changed

2 files changed

+180
-44
lines changed

Assets/FbxExporters/Editor/InstallIntegration.cs

Lines changed: 164 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -70,41 +70,46 @@ class MayaIntegration : DCCIntegration
7070
{
7171
public override string DccDisplayName { get { return "Maya"; } }
7272

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+
7482
private const string PACKAGE_NAME = "FbxExporters";
7583
private const string VERSION_FILENAME = "README.txt";
7684
private const string VERSION_FIELD = "VERSION";
7785
private const string VERSION_TAG = "{Version}";
7886
private const string PROJECT_TAG = "{UnityProject}";
7987
private const string INTEGRATION_TAG = "{UnityIntegrationsPath}";
8088

81-
private const string FBX_EXPORT_SETTINGS_PATH = "/Integrations/Autodesk/maya/scripts/unityFbxExportSettings.mel";
82-
8389
private const string MAYA_INSTRUCTION_FILENAME = "_safe_to_delete/_temp.txt";
8490

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 {
9392
get {
9493
switch (Application.platform) {
9594
case RuntimePlatform.WindowsEditor:
96-
return "maya/modules";
95+
return "maya";
9796
case RuntimePlatform.OSXEditor:
98-
return "Library/Preferences/Autodesk/Maya/modules";
97+
return "Library/Preferences/Autodesk/Maya";
9998
default:
10099
throw new NotImplementedException ();
101100
}
102101
}
103102
}
104103

104+
private static string MAYA_MODULES_PATH {
105+
get {
106+
return System.IO.Path.Combine(GetUserFolder(), MAYA_DOCUMENTS_PATH + "/modules");
107+
}
108+
}
109+
105110
// Use string to define escaped quote
106111
// Windows needs the backslash
107-
private static string ESCAPED_QUOTE {
112+
protected static string ESCAPED_QUOTE {
108113
get {
109114
switch (Application.platform) {
110115
case RuntimePlatform.WindowsEditor:
@@ -117,14 +122,14 @@ private static string ESCAPED_QUOTE {
117122
}
118123
}
119124

120-
private static string MAYA_COMMANDS { get {
125+
protected virtual string MAYA_COMMANDS { get {
121126
return string.Format("configureUnityFbxForMaya {0}{1}{0} {0}{2}{0} {0}{3}{0} {0}{4}{0} {0}{5}{0} {6}; scriptJob -idleEvent quit;",
122127
ESCAPED_QUOTE, GetProjectPath(), GetAppPath(), GetTempSavePath(),
123128
GetExportSettingsPath(), GetMayaInstructionPath(), (IsHeadlessInstall()?1:0));
124129
}}
125130
private static Char[] FIELD_SEPARATORS = new Char[] {':'};
126131

127-
private static string GetUserFolder()
132+
protected static string GetUserFolder()
128133
{
129134
switch (Application.platform) {
130135
case RuntimePlatform.WindowsEditor:
@@ -141,12 +146,7 @@ public static bool IsHeadlessInstall ()
141146
return false;
142147
}
143148

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()
150150
{
151151
return System.IO.Path.Combine(INTEGRATION_FOLDER_PATH, MODULE_TEMPLATE_PATH);
152152
}
@@ -190,7 +190,7 @@ public static string GetFullMayaInstructionPath()
190190
/// Returns a relative path with forward slashes as path separators.
191191
/// </summary>
192192
/// <returns>The export settings path.</returns>
193-
public static string GetExportSettingsPath()
193+
public string GetExportSettingsPath()
194194
{
195195
return INTEGRATION_FOLDER_PATH + FBX_EXPORT_SETTINGS_PATH;
196196
}
@@ -290,7 +290,32 @@ private static void WriteFile(string FileName, List<string> Lines )
290290
}
291291
}
292292

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)
294319
{
295320
int ExitCode = 0;
296321

@@ -333,7 +358,7 @@ public static int ConfigureMaya(string mayaPath)
333358
return ExitCode;
334359
}
335360

336-
public static bool InstallMaya(bool verbose = false)
361+
public virtual bool InstallMaya(bool verbose = false)
337362
{
338363
// What's happening here is that we copy the module template to
339364
// the module path, basically:
@@ -350,30 +375,16 @@ public static bool InstallMaya(bool verbose = false)
350375
}
351376

352377
// 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;
354379
string moduleFilePath = System.IO.Path.Combine(modulePath, MODULE_FILENAME + ".mod");
355380
bool installed = false;
356381

357382
if (!System.IO.Directory.Exists(modulePath))
358383
{
359384
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")) {
374386
return false;
375387
}
376-
377388
installed = false;
378389
}
379390
else
@@ -436,11 +447,11 @@ public static bool InstallMaya(bool verbose = false)
436447

437448
public override int InstallIntegration (string mayaExe)
438449
{
439-
if (!MayaIntegration.InstallMaya(verbose: true)) {
450+
if (!InstallMaya(verbose: true)) {
440451
return -1;
441452
}
442453

443-
return MayaIntegration.ConfigureMaya (mayaExe);
454+
return ConfigureMaya (mayaExe);
444455
}
445456

446457
/// <summary>
@@ -451,7 +462,116 @@ public override int InstallIntegration (string mayaExe)
451462
/// <param name="path">Path.</param>
452463
public override bool FolderAlreadyUnzippedAtPath(string path)
453464
{
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);
455575
}
456576
}
457577

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
########################################################################
2+
# Copyright (c) 2017 Unity Technologies. All rights reserved.
3+
# NOTICE: All information contained herein is, and remains
4+
# the property of Unity Technologies Aps. and its suppliers,
5+
# if any. The intellectual and technical concepts contained
6+
# herein are proprietary to Unity Technologies Aps. and its
7+
# suppliers and may be covered by Canadian, U.S. and/or
8+
# Foreign Patents, patents in process, and are protected
9+
# by trade secret or copyright law. Dissemination of this
10+
# information or reproduction of this material is strictly
11+
# forbidden unless prior written permission is obtained from
12+
# Unity Technologies Aps.
13+
#
14+
########################################################################
15+
16+
+ MAYAVERSION:2017 UnityFbxForMayaLT {Version} {UnityIntegrationsPath}/Integrations/Autodesk/mayalt

0 commit comments

Comments
 (0)