Skip to content

Commit e1fc9b5

Browse files
committed
add basic project launching, override enter key on datagrid, add getselectedproject() and getunityexepath()
1 parent 7c0da0d commit e1fc9b5

File tree

2 files changed

+124
-4
lines changed

2 files changed

+124
-4
lines changed

UnityLauncherPro/MainWindow.xaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
66
xmlns:local="clr-namespace:UnityLauncherPro"
77
mc:Ignorable="d"
8-
Title="UnityLauncherPro" Height="650" Width="600" WindowStartupLocation="CenterScreen" Background="{DynamicResource DarkestBackground}" MinWidth="600" MinHeight="650" AllowsTransparency="True" WindowStyle="None" Margin="0" KeyDown="OnWindowKeyDown" Closing="Window_Closing" SizeChanged="Window_SizeChanged" >
8+
Title="UnityLauncherPro" Height="650" Width="600" WindowStartupLocation="CenterScreen" Background="{DynamicResource DarkestBackground}" MinWidth="600" MinHeight="650" AllowsTransparency="True" WindowStyle="None" Margin="0" KeyDown="OnWindowKeyDown" Closing="Window_Closing" SizeChanged="Window_SizeChanged" PreviewKeyDown="Window_PreviewKeyDown" >
99

1010
<Window.Resources>
11+
12+
1113
<!-- tabs -->
1214
<Style x:Key="TabItemStyle1" TargetType="{x:Type TabItem}">
1315
<Setter Property="Template">
@@ -360,7 +362,7 @@
360362
<Label Foreground="{DynamicResource ButtonForeground}">_Run Unity</Label>
361363
</Button>
362364

363-
<Button Grid.Column="2" Style="{StaticResource CustomButton}" x:Name="btnLaunchProject" Background="{DynamicResource ButtonBackground}" Foreground="#FFC1C1C1" Margin="8,0,0,0" BorderBrush="{x:Null}" >
365+
<Button Grid.Column="2" Style="{StaticResource CustomButton}" x:Name="btnLaunchProject" Background="{DynamicResource ButtonBackground}" Foreground="#FFC1C1C1" Margin="8,0,0,0" BorderBrush="{x:Null}" Click="BtnLaunchProject_Click" >
364366
<Label Foreground="{DynamicResource ButtonForeground}">_Open Project</Label>
365367
</Button>
366368

UnityLauncherPro/MainWindow.xaml.cs

Lines changed: 120 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.ComponentModel;
3+
using System.Diagnostics;
34
using System.Drawing; // for notifyicon
45
using System.IO;
56
using System.Windows;
@@ -336,5 +337,122 @@ private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
336337
Properties.Settings.Default.windowHeight = (int)win.Height;
337338
Properties.Settings.Default.Save();
338339
}
339-
}
340-
}
340+
341+
private void BtnLaunchProject_Click(object sender, RoutedEventArgs e)
342+
{
343+
LaunchProject(GetSelectedProject());
344+
}
345+
346+
void LaunchProject(Project proj)
347+
{
348+
// validate
349+
if (proj == null) return;
350+
if (Directory.Exists(proj.Path) == false) return;
351+
352+
Console.WriteLine("launching " + proj.Title);
353+
354+
// there is no assets path, probably we want to create new project then
355+
var assetsFolder = Path.Combine(proj.Path, "Assets");
356+
if (Directory.Exists(assetsFolder) == false)
357+
{
358+
// TODO could ask if want to create project..?
359+
Directory.CreateDirectory(assetsFolder);
360+
}
361+
362+
/*
363+
// TODO when opening project, check for crashed backup scene first
364+
if (openProject == true)
365+
{
366+
var cancelLaunch = CheckCrashBackupScene(projectPath);
367+
if (cancelLaunch == true)
368+
{
369+
return;
370+
}
371+
}*/
372+
373+
374+
// we dont have this version installed (or no version info available)
375+
var unityExePath = GetSelectedUnityExePath(proj.Version);
376+
if (unityExePath == null)
377+
{
378+
Console.WriteLine("Missing unity version " + proj.Version);
379+
// SetStatus("Missing Unity version: " + version);
380+
// TODO
381+
//if (openProject == true) DisplayUpgradeDialog(version, projectPath);
382+
return;
383+
}
384+
385+
/*
386+
if (openProject == true)
387+
{
388+
SetStatus("Launching project in Unity " + version);
389+
}
390+
else
391+
{
392+
SetStatus("Launching Unity " + version);
393+
}*/
394+
395+
396+
try
397+
{
398+
Process myProcess = new Process();
399+
var cmd = "\"" + unityExePath + "\"";
400+
myProcess.StartInfo.FileName = cmd;
401+
402+
//if (openProject == true)
403+
{
404+
var pars = " -projectPath " + "\"" + proj.Path + "\"";
405+
406+
// TODO check for custom launch parameters and append them
407+
//string customArguments = GetSelectedRowData("_launchArguments");
408+
//if (string.IsNullOrEmpty(customArguments) == false)
409+
//{
410+
// pars += " " + customArguments;
411+
//}
412+
413+
myProcess.StartInfo.Arguments = pars;// TODO args + commandLineArguments;
414+
}
415+
myProcess.Start();
416+
417+
/*
418+
if (Properties.Settings.Default.closeAfterProject)
419+
{
420+
Environment.Exit(0);
421+
}*/
422+
}
423+
catch (Exception e)
424+
{
425+
Console.WriteLine(e);
426+
}
427+
}
428+
429+
430+
string GetSelectedUnityExePath(string version)
431+
{
432+
for (int i = 0, len = unityInstallationsSource.Length; i < len; i++)
433+
{
434+
if (version == unityInstallationsSource[i].Version) return unityInstallationsSource[i].Path;
435+
}
436+
return null;
437+
}
438+
439+
440+
Project GetSelectedProject()
441+
{
442+
return (Project)gridRecent.SelectedItem;
443+
}
444+
445+
private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
446+
{
447+
// override Enter for datagrid
448+
if (e.Key == Key.Return && e.KeyboardDevice.Modifiers == ModifierKeys.None)
449+
{
450+
e.Handled = true;
451+
LaunchProject(GetSelectedProject());
452+
return;
453+
}
454+
455+
base.OnKeyDown(e);
456+
}
457+
} // class
458+
} //namespace

0 commit comments

Comments
 (0)