Editor/BuildSettings.cs
/// <summary>
/// Builds the project and depending on settings zips it, and executes the batch file.
/// </summary>
/// <param name="path">A path for the build. If null or empty will be asked at the start of the method.</param>
/// <param name="keepBuildTarget">Should the platform be switched back once the build is done.</param>
/// <returns>Report of the whole process.</returns>
Builds the project and depending on settings zips it, and executes the batch file.
Builds the project and depending on settings zips it and executes the batch file .
public string Build(string path = "", bool keepBuildTarget = false)
        {
            if (string.IsNullOrEmpty(path))
            {
                path = BuilderHelper.GetDeployPath();
                if (string.IsNullOrEmpty(path)) return "";
            }
            BuildTargetGroup defaultBuildTargetGroup = EditorUserBuildSettings.selectedBuildTargetGroup;
            BuildTarget defaultBuildTarget = EditorUserBuildSettings.activeBuildTarget;
            buildDirectory = $"{path}/{directory}";
            var newReport = new StringBuilder($"\n----- Starting '{buildName}' build at {DateTime.Now}\n" +
                                           $"- Directory: {buildDirectory}\n- Build group: {buildGroup}\n" +
                                           $"- Build target: {buildTarget}");
            Stopwatch stopwatch = Stopwatch.StartNew();
            var deployed = Deploy(scenes, buildDirectory, buildName, buildGroup, buildTarget);
            stopwatch.Stop();
            newReport.Append(
                $"\n--- Build {(deployed ? "completed" : "failed")} at {DateTime.Now.ToString()} in {stopwatch.ElapsedMilliseconds / 1000} seconds");
            if (!deployed)
            {
                if (keepBuildTarget)
                {
                    var targetReport = BuilderHelper.SwitchBuildTarget(defaultBuildTargetGroup, defaultBuildTarget);
                    newReport.Append($"\n-- {targetReport}");
                }
                newReport.Append($"\n----- Done at {DateTime.Now.ToString()}");
                report = newReport.ToString(); 
                return report;
            }
            if (createZipFile)
            {
                newReport.Append($"\n--- Zipping {buildDirectory} at {DateTime.Now.ToString()}");
                stopwatch.Restart();
                var zipped = Zip(buildDirectory);
                stopwatch.Stop();
                zipFile = zipped ? $"{buildDirectory}.zip" : "";
                newReport.Append($"\n--- {(zipped ? "Zipped" : "Failed to zip")} to '{zipFile}' " +
                                 $"at {DateTime.Now.ToString()} in {stopwatch.ElapsedMilliseconds / 1000} seconds");
                if (!zipped)
                {
                    if (keepBuildTarget)
                    {
                        var targetReport = BuilderHelper.SwitchBuildTarget(defaultBuildTargetGroup, defaultBuildTarget);
                        newReport.Append($"\n-- {targetReport}");
                    }
                    newReport.Append($"\n----- Done at {DateTime.Now.ToString()}");
                    report = newReport.ToString(); 
                    return report;
                }
            }
            else
            {
                newReport.Append("\n---Skipped zipping");
            }
            if (useBatchFile)
            {
                newReport.Append($"\n--- Executing batch file '{AssetDatabase.GetAssetPath(batchFile)}' " +
                                 $"at {DateTime.Now.ToString()}");
                stopwatch.Restart();
                var executed = PrepareAndExecuteBatchFile();
                stopwatch.Stop();
                newReport.Append($"\n--- Batch file {(executed ? "was executed" : "failed execution")} " +
                                 $"at {DateTime.Now.ToString()} in {stopwatch.ElapsedMilliseconds / 1000} seconds");
            }
            else
            {
                newReport.Append("\n---Skipped batch execution");
            }
            if (keepBuildTarget)
            {
                var targetReport = BuilderHelper.SwitchBuildTarget(defaultBuildTargetGroup, defaultBuildTarget);
                newReport.Append($"\n-- {targetReport}");
            }
            newReport.Append($"\n----- Done at {DateTime.Now.ToString()}");
            report = newReport.ToString(); 
            return report;
        }
public string Build ( string path = " " , bool keepBuildTarget = false ) { if ( string . IsNullOrEmpty ( path ) ) { path = BuilderHelper . GetDeployPath ( ) ; if ( string . IsNullOrEmpty ( path ) ) return " " ; } BuildTargetGroup defaultBuildTargetGroup = EditorUserBuildSettings . selectedBuildTargetGroup ; BuildTarget defaultBuildTarget = EditorUserBuildSettings . activeBuildTarget ; buildDirectory = $" { path } / { directory } " ; var newReport = new StringBuilder ( $" \n ----- Starting ' { buildName } ' build at  { DateTime . Now } \n " + $" - Directory:  { buildDirectory } \n - Build group:  { buildGroup } \n " + $" - Build target:  { buildTarget } " ) ; Stopwatch stopwatch = Stopwatch . StartNew ( ) ; var deployed = Deploy ( scenes , buildDirectory , buildName , buildGroup , buildTarget ) ; stopwatch . Stop ( ) ; newReport . Append ( $" \n --- Build  { ( deployed ? " " : " " ) }  at  { DateTime . Now . ToString ( ) }  in  { stopwatch . ElapsedMilliseconds / 1000 }  seconds " ) ; if ( ! deployed ) { if ( keepBuildTarget ) { var targetReport = BuilderHelper . SwitchBuildTarget ( defaultBuildTargetGroup , defaultBuildTarget ) ; newReport . Append ( $" \n --  { targetReport } " ) ; } newReport . Append ( $" \n ----- Done at  { DateTime . Now . ToString ( ) } " ) ; report = newReport . ToString ( ) ; return report ; } if ( createZipFile ) { newReport . Append ( $" \n --- Zipping  { buildDirectory }  at  { DateTime . Now . ToString ( ) } " ) ; stopwatch . Restart ( ) ; var zipped = Zip ( buildDirectory ) ; stopwatch . Stop ( ) ; zipFile = zipped ? $" { buildDirectory } .zip " : " " ; newReport . Append ( $" \n ---  { ( zipped ? " " : " " ) }  to ' { zipFile } '  " + $" at  { DateTime . Now . ToString ( ) }  in  { stopwatch . ElapsedMilliseconds / 1000 }  seconds " ) ; if ( ! zipped ) { if ( keepBuildTarget ) { var targetReport = BuilderHelper . SwitchBuildTarget ( defaultBuildTargetGroup , defaultBuildTarget ) ; newReport . Append ( $" \n --  { targetReport } " ) ; } newReport . Append ( $" \n ----- Done at  { DateTime . Now . ToString ( ) } " ) ; report = newReport . ToString ( ) ; return report ; } } else { newReport . Append ( " \n " ) ; } if ( useBatchFile ) { newReport . Append ( $" \n --- Executing batch file ' { AssetDatabase . GetAssetPath ( batchFile ) } '  " + $" at  { DateTime . Now . ToString ( ) } " ) ; stopwatch . Restart ( ) ; var executed = PrepareAndExecuteBatchFile ( ) ; stopwatch . Stop ( ) ; newReport . Append ( $" \n --- Batch file  { ( executed ? " " : " " ) } " + $" at  { DateTime . Now . ToString ( ) }  in  { stopwatch . ElapsedMilliseconds / 1000 }  seconds " ) ; } else { newReport . Append ( " \n " ) ; } if ( keepBuildTarget ) { var targetReport = BuilderHelper . SwitchBuildTarget ( defaultBuildTargetGroup , defaultBuildTarget ) ; newReport . Append ( $" \n --  { targetReport } " ) ; } newReport . Append ( $" \n ----- Done at  { DateTime . Now . ToString ( ) } " ) ; report = newReport . ToString ( ) ; return report ; }
Builds the project and depending on settings zips it, and executes the batch file.
Builds the project and depending on settings zips it and executes the batch file .
Report of the whole process.
Report of the whole process .
path
string
A path for the build. If null or empty will be asked at the start of the method.
A path for the build . If null or empty will be asked at the start of the method .
keepBuildTarget
bool
Should the platform be switched back once the build is done.
Should the platform be switched back once the build is done .