//// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH // THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.//// add this code to an "Editor" folder in your Unity project and run it like this://// <fullPathToUnity.exe> -buildTarget <yourBuildTarget> -nographics -quit -batchmode -projectPath <projectPath> -logFile ./Log.txt -executeMethod UnityCommandLineEntryPoint.Build//// you'll need to look up how to do "Attach to Process" with your debugger of choice but it's not hard, you can find the right onw with trial and error//publicstaticclassUnityCommandLineEntryPoint{publicstaticvoidBuild(){if(CommandLineContainsFlag(GetCommandLine(),"-WaitForDebugger")){varprocess=System.Diagnostics.Process.GetCurrentProcess();while(!System.Diagnostics.Debugger.IsAttached){// // when you see this text in the unity logfile put breakpoint after the loop // and use your debugger's "Attach to Process" functionality to attach to the running process (it's usually called "Unity" or "Unity:<yourProjectName>")//System.Console.WriteLine($"{process.ProcessName}.{process.Id}: waiting for debugger...");System.Threading.Thread.Sleep(5000);}intputABreakpointHereAndAttachTheDebugger=0;}//// rest of your batch mode editor code goes after this// }publicstaticstring[]GetCommandLine(){returnEnvironment.GetCommandLineArgs();}/// <summary>/// checks command line for a parameter and returns its value /// param values are assumed to be the token following the parameter name/// e.g. /// -BuildFolder C:\Builds\Game/// |<---------->| = CmdParamName /// |<------------>| = outCmdParamValue/// </summary>/// <param name="CmdLineTokens">string array of command line tokens - cf.GetCommandLine()</param>/// <param name="CmdParamName">case insensitive param name to look for including any expected marker character e.g. "-buildfolder" </param>/// <param name="outCmdParamValue"> out param which will contain the exact string provided on the command line, or null if not found</param>/// <returns> true if CmdParamName and outCmdParamValue was set, else false</returns>publicstaticboolTryGetCommandLineParamValue(string[]CmdLineTokens,stringCmdParamName,outstringoutCmdParamValue){stringstrParamNameLower=CmdParamName.ToLower();for(inti=0;i<CmdLineTokens.Length;++i){if((strParamNameLower==CmdLineTokens[i].ToLower())&&((i+1)<CmdLineTokens.Length)){outCmdParamValue=CmdLineTokens[i+1];returntrue;}}outCmdParamValue=null;returnfalse;}/// <summary>/// checks command line for a flag and returns treu if found/// </summary>/// <param name="CmdLineTokens">string array of command line tokens - cf.GetCommandLine()</param>/// <param name="CmdFlagName">case insensitive param name to look for including any expected marker character e.g. "-buildfolder" </param>/// <returns>true if found, else false</returns>publicstaticboolCommandLineContainsFlag(string[]CmdLineTokens,stringCmdFlagName){stringstrFlagNameLower=CmdFlagName.ToLower();for(inti=0;i<CmdLineTokens.Length;++i){if(strFlagNameLower==CmdLineTokens[i].ToLower()){returntrue;}}returnfalse;}}
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.