Skip to content

Commit 719ef37

Browse files
authored
Merge pull request #194 from Unity-Technologies/Uni-28914_Adding_an_option_for_launching_after_installation
Uni-28914 [ADDED] a check box to launch after installation
2 parents 7dfd6ad + 32d889a commit 719ef37

File tree

2 files changed

+66
-12
lines changed

2 files changed

+66
-12
lines changed

Assets/FbxExporters/Editor/FbxExportSettings.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,12 @@ public override void OnInspectorGUI() {
152152
FbxExporters.Editor.IntegrationsUI.InstallDCCIntegration ();
153153
}
154154

155+
exportSettings.launchAfterInstallation = EditorGUILayout.Toggle(
156+
new GUIContent("Launch 3D Application:",
157+
"Launch the selected application after unity integration is completed."),
158+
exportSettings.launchAfterInstallation
159+
);
160+
155161
GUILayout.FlexibleSpace ();
156162
GUILayout.EndScrollView ();
157163
GUILayout.EndVertical();
@@ -238,6 +244,7 @@ public static string kDefaultAdskRoot {
238244
// Note: default values are set in LoadDefaults().
239245
public bool mayaCompatibleNames;
240246
public bool centerObjects;
247+
public bool launchAfterInstallation;
241248

242249
public int selectedDCCApp = 0;
243250

@@ -265,6 +272,7 @@ protected override void LoadDefaults()
265272
{
266273
mayaCompatibleNames = true;
267274
centerObjects = true;
275+
launchAfterInstallation = true;
268276
convertToModelSavePath = kDefaultSavePath;
269277
dccOptionPaths = null;
270278
dccOptionNames = null;

Assets/FbxExporters/Editor/InstallIntegration.cs

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,22 @@ public static string GetProjectPath()
6363
/// <returns><c>true</c> if folder is already unzipped at the specified path; otherwise, <c>false</c>.</returns>
6464
/// <param name="path">Path.</param>
6565
public abstract bool FolderAlreadyUnzippedAtPath (string path);
66+
67+
/// <summary>
68+
/// Launches application at given path
69+
/// </summary>
70+
/// <param name="AppPath"></param>
71+
public static void LaunchDCCApplication(string AppPath)
72+
{
73+
System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
74+
myProcess.StartInfo.FileName = AppPath;
75+
myProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
76+
myProcess.StartInfo.CreateNoWindow = false;
77+
myProcess.StartInfo.UseShellExecute = false;
78+
79+
myProcess.EnableRaisingEvents = false;
80+
myProcess.Start();
81+
}
6682
}
6783

6884

@@ -117,10 +133,14 @@ private static string ESCAPED_QUOTE {
117133
}
118134
}
119135

120-
private static string MAYA_COMMANDS { get {
121-
return string.Format("configureUnityFbxForMaya {0}{1}{0} {0}{2}{0} {0}{3}{0} {0}{4}{0} {0}{5}{0} {6}; scriptJob -idleEvent quit;",
136+
private static string MAYA_CONFIG_COMMAND { get {
137+
return string.Format("configureUnityFbxForMaya {0}{1}{0} {0}{2}{0} {0}{3}{0} {0}{4}{0} {0}{5}{0} {6};",
122138
ESCAPED_QUOTE, GetProjectPath(), GetAppPath(), GetTempSavePath(),
123-
GetExportSettingsPath(), GetMayaInstructionPath(), (IsHeadlessInstall()?1:0));
139+
GetExportSettingsPath(), GetMayaInstructionPath(), (IsHeadlessInstall() ? 1 : 0));
140+
}}
141+
142+
private static string MAYA_CLOSE_COMMAND { get {
143+
return string.Format("scriptJob -idleEvent quit;");
124144
}}
125145
private static Char[] FIELD_SEPARATORS = new Char[] {':'};
126146

@@ -307,24 +327,45 @@ public static int ConfigureMaya(string mayaPath)
307327
myProcess.StartInfo.CreateNoWindow = true;
308328
myProcess.StartInfo.UseShellExecute = false;
309329

330+
string commandString;
331+
310332
switch (Application.platform) {
311333
case RuntimePlatform.WindowsEditor:
312-
myProcess.StartInfo.Arguments = string.Format("-command \"{0}\"", MAYA_COMMANDS);
334+
commandString = "-command \"{0}\"";
313335
break;
314336
case RuntimePlatform.OSXEditor:
315-
myProcess.StartInfo.Arguments = string.Format(@"-command '{0}'", MAYA_COMMANDS);
337+
commandString = @"-command '{0}'";
316338
break;
317339
default:
318340
throw new NotImplementedException ();
319341
}
320342

343+
if (EditorTools.ExportSettings.instance.launchAfterInstallation)
344+
{
345+
myProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
346+
myProcess.StartInfo.CreateNoWindow = false;
347+
myProcess.StartInfo.Arguments = string.Format(commandString, MAYA_CONFIG_COMMAND);
348+
}
349+
else
350+
{
351+
myProcess.StartInfo.Arguments = string.Format(commandString, MAYA_CONFIG_COMMAND + MAYA_CLOSE_COMMAND);
352+
}
353+
321354
myProcess.EnableRaisingEvents = true;
322355
myProcess.Start();
323-
myProcess.WaitForExit();
324-
ExitCode = myProcess.ExitCode;
325-
Debug.Log(string.Format("Ran maya: [{0}]\nWith args [{1}]\nResult {2}",
326-
mayaPath, myProcess.StartInfo.Arguments, ExitCode));
327-
}
356+
357+
if (!EditorTools.ExportSettings.instance.launchAfterInstallation)
358+
{
359+
myProcess.WaitForExit();
360+
ExitCode = myProcess.ExitCode;
361+
Debug.Log(string.Format("Ran maya: [{0}]\nWith args [{1}]\nResult {2}",
362+
mayaPath, myProcess.StartInfo.Arguments, ExitCode));
363+
}
364+
else
365+
{
366+
ExitCode = 0;
367+
}
368+
}
328369
catch (Exception e)
329370
{
330371
UnityEngine.Debug.LogError(string.Format ("Exception failed to start Maya ({0})", e.Message));
@@ -532,8 +573,13 @@ public static int InstallMaxPlugin(string maxExe){
532573
myProcess.WaitForExit();
533574
ExitCode = myProcess.ExitCode;
534575

576+
if (EditorTools.ExportSettings.instance.launchAfterInstallation)
577+
{
578+
LaunchDCCApplication(maxExe);
579+
}
580+
535581
// TODO (UNI-29910): figure out what exactly causes this exit code + how to resolve
536-
if(ExitCode == -1073740791){
582+
if (ExitCode == -1073740791){
537583
Debug.Log(string.Format("Detected 3ds max exitcode {0} -- safe to ignore", ExitCode));
538584
ExitCode = 0;
539585
}
@@ -545,7 +591,7 @@ public static int InstallMaxPlugin(string maxExe){
545591
{
546592
UnityEngine.Debug.LogError(string.Format ("Exception failed to start Max ({0})", e.Message));
547593
ExitCode = -1;
548-
}
594+
}
549595
return ExitCode;
550596
}
551597

0 commit comments

Comments
 (0)