From da156d9be2e2401a8da5380acd1f502f65c97a37 Mon Sep 17 00:00:00 2001
From: krisrok <3404365+krisrok@users.noreply.github.com>
Date: Fri, 8 Aug 2025 11:26:52 +0200
Subject: [PATCH] Add a quick "custom" build command
Expects a editor script with in the format of:
```cs
using System.Diagnostics;
using System.IO;
using System.Linq;
using UnityEditor;
using UnityEngine;
public static class UnityLauncherProToolsCustom
{
[MenuItem("Tools/Build custom")]
public static void BuildCustom()
{
var settings = new BuildPlayerOptions();
settings.scenes = GetScenes();
settings.locationPathName = Path.GetFullPath(Path.Combine(Application.dataPath, "..", "..", "..", "Build", PlayerSettings.productName + ".exe"));
settings.target = EditorUserBuildSettings.activeBuildTarget;
var report = BuildPipeline.BuildPlayer(settings);
if (report.summary.result == UnityEditor.Build.Reporting.BuildResult.Succeeded)
Process.Start(Path.GetDirectoryName(settings.locationPathName));
}
static string[] GetScenes()
{
return EditorBuildSettings.scenes.Where(scene => scene.enabled).Select(scene => scene.path).ToArray();
}
}
```
---
UnityLauncherPro/MainWindow.xaml | 1 +
UnityLauncherPro/MainWindow.xaml.cs | 6 ++++++
UnityLauncherPro/Tools.cs | 29 ++++++++++++++++++++++++++++-
3 files changed, 35 insertions(+), 1 deletion(-)
diff --git a/UnityLauncherPro/MainWindow.xaml b/UnityLauncherPro/MainWindow.xaml
index 49083d2..60e54d0 100644
--- a/UnityLauncherPro/MainWindow.xaml
+++ b/UnityLauncherPro/MainWindow.xaml
@@ -227,6 +227,7 @@
diff --git a/UnityLauncherPro/MainWindow.xaml.cs b/UnityLauncherPro/MainWindow.xaml.cs
index 5bce4e5..f46d689 100644
--- a/UnityLauncherPro/MainWindow.xaml.cs
+++ b/UnityLauncherPro/MainWindow.xaml.cs
@@ -3226,6 +3226,12 @@ private void MenuBatchBuildIOS_Click(object sender, RoutedEventArgs e)
Tools.BuildProject(proj, Platform.iOS);
}
+ private void MenuBatchBuildCustom_Click(object sender, RoutedEventArgs e)
+ {
+ var proj = GetSelectedProject();
+ Tools.BuildProjectCustom(proj);
+ }
+
private void ChkCheckPlasticBranch_Checked(object sender, RoutedEventArgs e)
{
if (this.IsActive == false) return; // dont run code on window init
diff --git a/UnityLauncherPro/Tools.cs b/UnityLauncherPro/Tools.cs
index 861f5e6..8dddfee 100644
--- a/UnityLauncherPro/Tools.cs
+++ b/UnityLauncherPro/Tools.cs
@@ -2104,7 +2104,34 @@ static string[] GetScenes()
}
- // runs unity SimpleWebServer.exe and launches default Browser into project build/ folder'
+ public static void BuildProjectCustom(Project proj)
+ {
+ Console.WriteLine("Building " + proj.Title + " (custom)");
+ SetStatus("Build process started: " + DateTime.Now.ToString("HH:mm:ss"));
+
+ // get selected project unity exe path
+ var unityExePath = Tools.GetUnityExePath(proj.Version);
+ if (unityExePath == null) return;
+
+ // create commandline string for building and launch it
+ //var buildcmd = $"\"{unityExePath}\" -quit -batchmode -nographics -projectPath \"{proj.Path}\" -executeMethod \"Builder.BuildAndroid\" -buildTarget android -logFile -";
+ // TODO test without nographics : https://forum.unity.com/threads/batch-build-one-scene-is-black-works-in-normal-file-build.1282823/#post-9456524
+ var buildParams = $" -quit -batchmode -nographics -projectPath \"{proj.Path}\" -executeMethod \"UnityLauncherProToolsCustom.BuildCustom\"";
+ Console.WriteLine("buildcmd= " + buildParams);
+
+ // launch build
+ var proc = Tools.LaunchExe(unityExePath, buildParams);
+
+ // wait for process exit then open output folder
+ proc.Exited += (o, i) =>
+ {
+ SetStatus("Build process finished: " + DateTime.Now.ToString("HH:mm:ss"));
+ // TODO set color based on results
+ SetBuildStatus(Colors.Green);
+ };
+ }
+
+ // runs unity SimpleWebServer.exe and launches default Browser into project build/ folder'
public static void LaunchWebGL(Project proj, string relativeFolder)
{
var projPath = proj?.Path.Replace('/', '\\');