Skip to content

Commit 249fc45

Browse files
committed
add launch webgl server context menu to projects, add missing tooltip to 2 setting toggles, modify LaunchExe() to accept params
1 parent 7fccc4c commit 249fc45

File tree

3 files changed

+76
-6
lines changed

3 files changed

+76
-6
lines changed

UnityLauncherPro/MainWindow.xaml

+4-2
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,8 @@
350350
<MenuItem x:Name="menuItemShowProjectInExplorer" Header="Show in Explorer" Click="MenuItemShowProjectInExplorer_Click" />
351351
<Separator/>
352352
<MenuItem x:Name="menuItemKillProcess" Header="Kill Process" Click="MenuItemKillProcess_Click" />
353+
<Separator/>
354+
<MenuItem x:Name="menuStartWebGLServer" Header="Start webgl server" Click="MenuStartWebGLServer_Click" />
353355
</ContextMenu>
354356
</DataGrid.ContextMenu>
355357

@@ -702,8 +704,8 @@
702704
<CheckBox x:Name="chkAllowSingleInstanceOnly" Content="Allow single instance only" Foreground="{DynamicResource ButtonForeground}" Checked="ChkAllowSingleInstanceOnly_CheckedChanged" Unchecked="ChkAllowSingleInstanceOnly_CheckedChanged" Margin="0,0,0,3" ToolTip="Activates already running instance, instead of starting new exe (not working if app is minized to taskbar)"/>
703705
<CheckBox x:Name="chkEnableProjectRename" Content="Enable Project Renaming (Not recommended for beginners)" Foreground="{DynamicResource ButtonForeground}" Margin="0,0,0,3" ToolTip="Can use F2 to rename project folders, Note that project will disappears from list on refresh, unless you open it (since its new path, not in unity recent projects registry)" Checked="ChkEnableProjectRename_Checked" Unchecked="ChkEnableProjectRename_Checked"/>
704706
<CheckBox x:Name="chkAskNameForQuickProject" Content="Ask name for New Project" Foreground="{DynamicResource ButtonForeground}" Checked="ChkAskNameForQuickProject_Checked" Unchecked="ChkAskNameForQuickProject_Checked" Margin="0,0,0,3" ToolTip="If disabled, uses automatic quick project naming"/>
705-
<CheckBox x:Name="chkStreamerMode" Content="Streamer Mode (hide project names and folders)" Foreground="{DynamicResource ButtonForeground}" Margin="0,0,0,3" ToolTip="" Checked="ChkStreamerMode_Checked" Unchecked="ChkStreamerMode_Checked"/>
706-
<CheckBox x:Name="chkShowPlatform" Content="Show current target platform (if exists in .csproj)" Foreground="{DynamicResource ButtonForeground}" Margin="0,0,0,3" ToolTip="" Checked="ChkShowPlatform_Checked" Unchecked="ChkShowPlatform_Checked"/>
707+
<CheckBox x:Name="chkStreamerMode" Content="Streamer Mode (hide project names and folders)" Foreground="{DynamicResource ButtonForeground}" Margin="0,0,0,3" ToolTip="Hide project names and folders in main view" Checked="ChkStreamerMode_Checked" Unchecked="ChkStreamerMode_Checked"/>
708+
<CheckBox x:Name="chkShowPlatform" Content="Show current target platform (if exists in .csproj)" Foreground="{DynamicResource ButtonForeground}" Margin="0,0,0,3" ToolTip="Shows target platform column" Checked="ChkShowPlatform_Checked" Unchecked="ChkShowPlatform_Checked"/>
707709

708710
<StackPanel Grid.Row="3" Orientation="Horizontal">
709711
<Label Content="Root Folder for New Projects" Foreground="{DynamicResource ButtonForeground}" />

UnityLauncherPro/MainWindow.xaml.cs

+46-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public partial class MainWindow : Window
3838
Updates[] updatesSource;
3939
UnityInstallation[] unityInstallationsSource;
4040

41-
public static Dictionary<string, string> unityInstalledVersions = new Dictionary<string, string>();
41+
public static Dictionary<string, string> unityInstalledVersions = new Dictionary<string, string>(); // versionID and installation folder
4242
const string contextRegRoot = "Software\\Classes\\Directory\\Background\\shell";
4343
public static readonly string launcherArgumentsFile = "LauncherArguments.txt";
4444
string _filterString = null;
@@ -1635,7 +1635,52 @@ private void BtnClearBuildReport_Click(object sender, RoutedEventArgs e)
16351635
gridBuildReport.ItemsSource = null;
16361636
}
16371637

1638+
private void MenuStartWebGLServer_Click(object sender, RoutedEventArgs e)
1639+
{
1640+
// runs unity SimpleWebServer.exe and launches default Browser into project build/ folder'
1641+
// TODO add setting for your default webgl folder inside Builds/ (examples, Builds/ or Builds/webgl/)
1642+
if (tabControl.SelectedIndex != 0) return;
1643+
1644+
var proj = GetSelectedProject();
1645+
var projPath = proj?.Path.Replace('/', '\\');
1646+
1647+
if (string.IsNullOrEmpty(projPath) == true) return;
1648+
1649+
var buildPath = Path.Combine(projPath, "Builds");
1650+
if (Directory.Exists(buildPath) == false) return;
1651+
1652+
if (unityInstalledVersions.ContainsKey(proj.Version) == false) return;
1653+
1654+
// get mono and server exe paths
1655+
var editorPath = Path.GetDirectoryName(unityInstalledVersions[proj.Version]);
1656+
1657+
var monoToolsPath = Path.Combine(editorPath, "Data/MonoBleedingEdge/bin");
1658+
if (Directory.Exists(monoToolsPath) == false) return;
16381659

1660+
var webglToolsPath = Path.Combine(editorPath, "Data/PlaybackEngines/WebGLSupport/BuildTools");
1661+
if (Directory.Exists(webglToolsPath) == false) return;
1662+
1663+
var monoExe = Path.Combine(monoToolsPath, "mono.exe");
1664+
if (File.Exists(monoExe) == false) return;
1665+
1666+
var webExe = Path.Combine(webglToolsPath, "SimpleWebServer.exe");
1667+
if (File.Exists(webExe) == false) return;
1668+
1669+
// pick random port for server
1670+
Random rnd = new Random();
1671+
int port = rnd.Next(50000, 61000);
1672+
1673+
// take process id from unity, if have it (then webserver closes automatically when unity is closed)
1674+
int pid = proj.Process == null ? -1 : proj.Process.Id;
1675+
var param = "\"" + webExe + "\" \"" + buildPath + "\" " + port + (pid == -1 ? "" : " " + pid); // server exe path, build folder and port
1676+
1677+
// then open browser
1678+
var serverLaunched = Tools.LaunchExe(monoExe, param);
1679+
if (serverLaunched == true)
1680+
{
1681+
Tools.OpenURL("http://localhost:" + port);
1682+
}
1683+
}
16391684
} // class
16401685
} //namespace
16411686

UnityLauncherPro/Tools.cs

+26-3
Original file line numberDiff line numberDiff line change
@@ -280,13 +280,31 @@ public static bool LaunchExplorer(string folder)
280280
}
281281

282282
// run any exe
283-
public static bool LaunchExe(string path)
283+
public static bool LaunchExe(string path, string param = null)
284284
{
285285
if (string.IsNullOrEmpty(path)) return false;
286286

287287
if (File.Exists(path) == true)
288288
{
289-
Process.Start(path);
289+
if (string.IsNullOrEmpty(param) == true)
290+
{
291+
Console.WriteLine(path);
292+
Process.Start(path);
293+
}
294+
else
295+
{
296+
var newProcess = new Process();
297+
try
298+
{
299+
newProcess.StartInfo.FileName = "\"" + path + "\"";
300+
newProcess.StartInfo.Arguments = param;
301+
newProcess.Start();
302+
}
303+
catch (Exception e)
304+
{
305+
Console.WriteLine(e);
306+
}
307+
}
290308
return true;
291309
}
292310
return false;
@@ -365,11 +383,16 @@ public static bool OpenReleaseNotes(string version)
365383
var url = Tools.GetUnityReleaseURL(version);
366384
if (string.IsNullOrEmpty(url)) return false;
367385

368-
Process.Start(url);
386+
OpenURL(url);
369387
result = true;
370388
return result;
371389
}
372390

391+
public static void OpenURL(string url)
392+
{
393+
Process.Start(url);
394+
}
395+
373396
public static void DownloadInBrowser(string url, string version)
374397
{
375398
string exeURL = ParseDownloadURLFromWebpage(version);

0 commit comments

Comments
 (0)