Exemple #1
0
    private static bool Make(bool autoRun, string buildNumber, bool makeBundleBasedPlayer, bool includeBundles, bool includeBundlesCache, bool quickPlayer)
    {
        if (makeBundleBasedPlayer)
        {
            if (!EditorApplication.SaveCurrentSceneIfUserWantsTo())
            {
                return(false);
            }
        }

        string buildLocation = EditorUserBuildSettings.GetBuildLocation(BuildUtils.SelectedBuildTarget);

        if (string.IsNullOrEmpty(buildLocation))
        {
            buildLocation = BuildUtils.OpenSaveBuildPanel(BuildUtils.SelectedBuildTarget, "Select build location for " + BuildUtils.SelectedBuildTarget, null, null, null);
        }
        else
        {
            string directory = Path.GetDirectoryName(buildLocation);
            string file      = Path.GetFileNameWithoutExtension(buildLocation);
            string extension = Path.GetExtension(buildLocation);
            if (!string.IsNullOrEmpty(extension))
            {
                extension = extension.Substring(1);                 // Remove the initial dot
            }
            buildLocation = BuildUtils.OpenSaveBuildPanel(BuildUtils.SelectedBuildTarget,
                                                          "Select build location for " + BuildUtils.SelectedBuildTarget, directory, file, extension);
        }

        if (!string.IsNullOrEmpty(buildLocation))
        {
            EditorUserBuildSettings.SetBuildLocation(BuildUtils.SelectedBuildTarget, buildLocation);
        }
        else
        {
            return(false);
        }

        var buildParams = new Builder.Params();

        buildParams.BuildNumber = buildNumber;

        if (autoRun)
        {
            buildParams.Options |= BuildOptions.AutoRunPlayer;
        }
        else
        {
            buildParams.Options |= BuildOptions.ShowBuiltPlayer;
        }

        if (makeBundleBasedPlayer)
        {
            buildParams.ExtraOptions |= Builder.Params.ExtraBuildOptions.BundleBasedPlayer;

            if (includeBundles)
            {
                buildParams.ExtraOptions |= Builder.Params.ExtraBuildOptions.IncludeBundles;
            }

            if (includeBundlesCache)
            {
                buildParams.ExtraOptions |= Builder.Params.ExtraBuildOptions.IncludeBundlesCache;
            }

            if (quickPlayer)
            {
                buildParams.ExtraOptions |= Builder.Params.ExtraBuildOptions.QuickBundlePlayer;
            }
        }

        try
        {
            Build.Make(buildParams);
        }
        catch (System.OperationCanceledException) { }
        catch (Builder.ContinueRequiredException) { }

        return(true);
    }