public override BuildStepResult RunBuildStep(BuildContext context)
        {
            m_TemporaryFileTracker = new TemporaryFileTracker();
            if (!Prepare(context, this, false, m_TemporaryFileTracker, out var failure, out var options))
            {
                return(failure);
            }

            var report = UnityEditor.BuildPipeline.BuildPlayer(options);

            return(ReturnBuildPlayerResult(context, this, report));
        }
        public override BuildStepResult RunBuildStep(BuildContext context)
        {
            m_TemporaryFileTracker = new TemporaryFileTracker();
            if (!BuildStepBuildClassicPlayer.Prepare(context, this, true, m_TemporaryFileTracker, out var failure, out var buildPlayerOptions))
            {
                return(failure);
            }

            //@TODO: Allow debugging should be based on profile...
            buildPlayerOptions.options = BuildOptions.Development | BuildOptions.AllowDebugging | BuildOptions.ConnectToHost;

            var report = UnityEditor.BuildPipeline.BuildPlayer(buildPlayerOptions);

            return(BuildStepBuildClassicPlayer.ReturnBuildPlayerResult(context, this, report));
        }
        public override BuildStepResult RunStep(BuildContext context)
        {
            m_TemporaryFileTracker = new TemporaryFileTracker();
            if (!BuildStepBuildClassicPlayer.Prepare(context, this, true, m_TemporaryFileTracker, out var failure, out var options))
            {
                return(failure);
            }

            //@TODO: Allow debugging should  be based on profile...
            //@TODO: BuildOptions.AutoRunPlayer shouldn't be enabled, it is just a workaround until Run is properly supported
            options.options = BuildOptions.Development | BuildOptions.AllowDebugging | BuildOptions.ConnectToHost | BuildOptions.AutoRunPlayer;

            var report = UnityEditor.BuildPipeline.BuildPlayer(options);

            return(BuildStepBuildClassicPlayer.ReturnBuildPlayerResult(context, this, report));
        }
        public static bool Prepare(BuildContext context, BuildStep step, bool liveLink, TemporaryFileTracker tracker, out BuildStepResult failure, out BuildPlayerOptions buildPlayerOptions)
        {
            buildPlayerOptions = default;
            var profile = step.GetRequiredComponent <ClassicBuildProfile>(context);

            if (profile.Target <= 0)
            {
                failure = BuildStepResult.Failure(step, $"Invalid build target '{profile.Target.ToString()}'.");
                return(false);
            }

            if (profile.Target != EditorUserBuildSettings.activeBuildTarget)
            {
                failure = BuildStepResult.Failure(step, $"{nameof(EditorUserBuildSettings.activeBuildTarget)} must be switched before {nameof(BuildStepBuildClassicPlayer)} step.");
                return(false);
            }

            var scenesList = step.GetRequiredComponent <SceneList>(context).GetScenePathsForBuild();

            if (scenesList.Length == 0)
            {
                failure = BuildStepResult.Failure(step, "There are no scenes to build.");
                return(false);
            }

            var outputPath = step.GetOutputBuildDirectory(context);

            if (!Directory.Exists(outputPath))
            {
                Directory.CreateDirectory(outputPath);
            }

            var productName      = step.GetRequiredComponent <GeneralSettings>(context).ProductName;
            var extension        = profile.GetExecutableExtension();
            var locationPathName = Path.Combine(outputPath, productName + extension);

            buildPlayerOptions = new BuildPlayerOptions()
            {
                scenes           = scenesList,
                target           = profile.Target,
                locationPathName = locationPathName,
                targetGroup      = UnityEditor.BuildPipeline.GetBuildTargetGroup(profile.Target),
            };

            buildPlayerOptions.options = BuildOptions.None;
            switch (profile.Configuration)
            {
            case BuildConfiguration.Debug:
                buildPlayerOptions.options |= BuildOptions.AllowDebugging | BuildOptions.Development;
                break;

            case BuildConfiguration.Develop:
                buildPlayerOptions.options |= BuildOptions.Development;
                break;
            }

            var sourceBuild = step.GetOptionalComponent <InternalSourceBuildConfiguration>(context);

            if (sourceBuild.Enabled)
            {
                buildPlayerOptions.options |= BuildOptions.InstallInBuildFolder;
            }

            if (UseAutoRunPlayer(context))
            {
                UnityEngine.Debug.Log($"Using BuildOptions.AutoRunPlayer, since RunStep is not provided for {profile.Target}");
                buildPlayerOptions.options |= BuildOptions.AutoRunPlayer;
            }

            if (liveLink)
            {
                File.WriteAllText(tracker.TrackFile(k_BootstrapFilePath), BuildContextInternals.GetBuildSettingsGUID(context));
            }
            else
            {
                // Make sure we didn't leak a bootstrap file from a previous crashed build
                tracker.EnsureFileDoesntExist(k_BootstrapFilePath);
            }

            failure = default;
            return(true);
        }
        public static bool Prepare(BuildContext context, IBuildStep step, bool liveLink, TemporaryFileTracker tracker, out BuildStepResult failure, out BuildPlayerOptions options)
        {
            options = default;
            var settings = context.BuildSettings;
            var profile  = settings.GetComponent <ClassicBuildProfile>();

            if (profile.Target <= 0)
            {
                failure = BuildStepResult.Failure(step, $"Invalid build target in build settings object {settings.name}.");
                return(false);
            }

            if (profile.Target != EditorUserBuildSettings.activeBuildTarget)
            {
                failure = BuildStepResult.Failure(step, $"ActiveBuildTarget must be switched before the Build Player step {settings.name}.");
                return(false);
            }


            var scenesList = settings.GetComponent <SceneList>().GetScenePathsForBuild();

            if (scenesList.Length == 0)
            {
                failure = BuildStepResult.Failure(step, "There are no scenes to build.");
                return(false);
            }

            var outputPath = OutputBuildDirectory.GetOutputDirectoryFor(context);

            if (!Directory.Exists(outputPath))
            {
                Directory.CreateDirectory(outputPath);
            }

            var productName      = settings.GetComponent <GeneralSettings>().ProductName;
            var extension        = profile.GetExecutableExtension();
            var locationPathName = Path.Combine(outputPath, productName + extension);

            options = new BuildPlayerOptions()
            {
                scenes           = scenesList,
                target           = profile.Target,
                locationPathName = locationPathName,
                targetGroup      = UnityEditor.BuildPipeline.GetBuildTargetGroup(profile.Target),
            };

            options.options = BuildOptions.None;
            switch (profile.Configuration)
            {
            case BuildConfiguration.Debug:
                options.options |= BuildOptions.AllowDebugging | BuildOptions.Development;
                break;

            case BuildConfiguration.Develop:
                options.options |= BuildOptions.Development;
                break;
            }

            InternalSourceBuildConfiguration sourceBuild;

            if (settings.TryGetComponent(out sourceBuild) && sourceBuild.Enabled)
            {
                options.options |= BuildOptions.InstallInBuildFolder;
            }

            if (liveLink)
            {
                var guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(context.BuildSettings));
                File.WriteAllText(tracker.TrackFile(k_BootstrapFilePath), guid);
            }
            else
            {
                // Make sure we didn't leak a bootstrap file from a previous crashed build
                tracker.EnsureFileDoesntExist(k_BootstrapFilePath);
            }

            failure = default;
            return(true);
        }