From e51c8155cc1a5835f128aa7307154a86671ea5c0 Mon Sep 17 00:00:00 2001 From: unitycoder Date: Sat, 17 Feb 2018 22:44:46 +0800 Subject: [PATCH] pass all arguments to launcher when running from commandline --- UnityLauncher/Form1.cs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/UnityLauncher/Form1.cs b/UnityLauncher/Form1.cs index 80a0614..4add1a0 100644 --- a/UnityLauncher/Form1.cs +++ b/UnityLauncher/Form1.cs @@ -64,24 +64,34 @@ void Start() string[] args = Environment.GetCommandLineArgs(); if (args != null && args.Length > 2) { + // first argument needs to be -projectPath var commandLineArgs = args[1]; if (commandLineArgs == "-projectPath") { SetStatus("Launching from commandline.."); + // path var projectPathArgument = args[2]; + var version = Tools.GetProjectVersion(projectPathArgument); - // try launching it - LaunchProject(projectPathArgument, version, true); + // take extra arguments also + var commandLineArguments = ""; + for (int i = 3, len = args.Length; i < len; i++) + { + commandLineArguments += " " + args[i]; + } - SetStatus("Ready"); + // try launching it + LaunchProject(projectPathArgument, version, openProject: true, commandLineArguments: commandLineArguments); // quit after launch if enabled in settings if (Properties.Settings.Default.closeAfterExplorer == true) { Application.Exit(); } + + SetStatus("Ready"); } else { @@ -329,7 +339,7 @@ void UpdateRecentProjectsList() SetStatus("Ready"); } - void LaunchProject(string projectPath, string version, bool openProject = true) + void LaunchProject(string projectPath, string version, bool openProject = true, string commandLineArguments = "") { if (Directory.Exists(projectPath) == true) { @@ -372,7 +382,7 @@ void LaunchProject(string projectPath, string version, bool openProject = true) pars += " " + customArguments; } - myProcess.StartInfo.Arguments = pars; + myProcess.StartInfo.Arguments = pars + commandLineArguments; } myProcess.Start();