Ejemplo n.º 1
0
        IEnumerator WaitUntilBuildFinishes(BuildReport report)
        {
            /* [NOTE] You might want to use a frame wait instead of a time based one:
             * Building is main thread, and we won't get a frame update until the build is complete.
             * So that would almost certainly wait until right after the build is done and next frame tick,
             * reducing the likely hood of data being unloaded / unavaliable due to
             * cleanup operations which could happen to the build report as variables on the stack are not counted as "in use" for the GC system
             */
            EditorWaitForSeconds waitForSeconds = new EditorWaitForSeconds(1f);

            while (BuildPipeline.isBuildingPlayer)
            {
                yield return(waitForSeconds);
            }

            AnalyticsHelper.BuildCompleted(report.summary.result, report.summary.totalTime);
            switch (report.summary.result)
            {
            case BuildResult.Cancelled: Debug.LogWarning("[Version and Build] Build cancelled! " + report.summary.totalTime); break;

            case BuildResult.Failed: Debug.LogError("[Version and Build] Build failed! " + report.summary.totalTime); break;

            case BuildResult.Succeeded: Debug.Log("[Version and Build] Build succeeded! " + report.summary.totalTime); break;

            case BuildResult.Unknown: Debug.Log("[Version and Build] Unknown build result! " + report.summary.totalTime); break;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Triggers the "Build Game" dialog
        /// </summary>
        /// <returns>True and the build path if everything goes well and the build is done, false and empty string otherwise.</returns>
        public static (bool, string) OpenBuildGameDialog(BuildTarget activeBuildTarget)
        {
            string path = string.Empty;

            try
            {
                string defaultOutputDirectory = PublisherUtils.GetFirstValidBuildPath();
                if (string.IsNullOrEmpty(defaultOutputDirectory) && CreateDefaultBuildsFolder)
                {
                    defaultOutputDirectory = DefaultBuildsFolderPath;
                    if (!Directory.Exists(defaultOutputDirectory))
                    {
                        Directory.CreateDirectory(defaultOutputDirectory);
                    }
                }

                path = EditorUtility.SaveFolderPanel(Localization.Tr("DIALOG_CHOOSE_BUILD_FOLDER"), defaultOutputDirectory, "");

                if (string.IsNullOrEmpty(path))
                {
                    return(false, string.Empty);
                }

                BuildPlayerOptions buildOptions = new BuildPlayerOptions();
                buildOptions.scenes           = EditorBuildSettingsScene.GetActiveSceneList(EditorBuildSettings.scenes);
                buildOptions.locationPathName = path;
                buildOptions.options          = BuildOptions.None;
                buildOptions.targetGroup      = BuildPipeline.GetBuildTargetGroup(activeBuildTarget);
                buildOptions.target           = activeBuildTarget;

                buildStartedFromTool = true;
                BuildReport report = BuildPipeline.BuildPlayer(buildOptions);
                buildStartedFromTool = false;

                AnalyticsHelper.BuildCompleted(report.summary.result, report.summary.totalTime);
                switch (report.summary.result)
                {
                case BuildResult.Cancelled:  //Debug.LogWarning("[Version and Build] Build cancelled! " + report.summary.totalTime);
                case BuildResult.Failed:     //Debug.LogError("[Version and Build] Build failed! " + report.summary.totalTime);
                    return(false, string.Empty);

                case BuildResult.Succeeded:   //Debug.Log("[Version and Build] Build succeeded! " + report.summary.totalTime);
                case BuildResult.Unknown:     //Debug.Log("[Version and Build] Unknown build result! " + report.summary.totalTime);
                    break;
                }
            }
            catch (BuildPlayerWindow.BuildMethodException /*e*/)
            {
                //Debug.LogError(e.Message);
                return(false, string.Empty);
            }
            return(true, path);
        }