Пример #1
0
    public static void BuildAndroidFromUI(bool autoRun = false)
    {
        try {
            AltUnityTesterEditor.InitEditorConfiguration();
            InitBuildSetup(UnityEditor.BuildTargetGroup.Android);
            UnityEngine.Debug.Log("Starting Android build..." + UnityEditor.PlayerSettings.productName + " : " + UnityEditor.PlayerSettings.bundleVersion);
            UnityEditor.BuildPlayerOptions buildPlayerOptions = new UnityEditor.BuildPlayerOptions();
            buildPlayerOptions.locationPathName = AltUnityTesterEditor.EditorConfiguration.OutputPathName + ".apk";
            buildPlayerOptions.scenes           = GetScenesForBuild();

            buildPlayerOptions.target = UnityEditor.BuildTarget.Android;
            if (autoRun)
            {
                buildPlayerOptions.options = UnityEditor.BuildOptions.Development | UnityEditor.BuildOptions.AutoRunPlayer;
            }
            else
            {
                buildPlayerOptions.options = UnityEditor.BuildOptions.Development;
            }
            var results = UnityEditor.BuildPipeline.BuildPlayer(buildPlayerOptions);



#if UNITY_2017
            if (results.Equals(""))
            {
                UnityEngine.Debug.Log("No Build Errors");
            }
            else
            {
                UnityEngine.Debug.LogError("Build Error!");
            }
#else
            if (results.summary.totalErrors == 0)
            {
                UnityEngine.Debug.Log("No Build Errors");
            }
            else
            {
                UnityEngine.Debug.LogError("Build Error! " + results.steps + "\n Result: " + results.summary.result +
                                           "\n Stripping info: " + results.strippingInfo);
            }
#endif

            UnityEngine.Debug.Log("Finished. " + UnityEditor.PlayerSettings.productName + " : " + UnityEditor.PlayerSettings.bundleVersion);
        } catch (System.Exception e) {
            UnityEngine.Debug.LogError(e);
        } finally {
            built = true;
            ResetBuildSetup(UnityEditor.BuildTargetGroup.Android);
        }
    }
Пример #2
0
    static void buildLinux()
    {
        UnityEditor.BuildPlayerOptions buildPlayerOptions = new UnityEditor.BuildPlayerOptions();
        buildPlayerOptions.scenes = new[] { "Assets/Scenes/SampleScene.unity" };
        string dir = "builds/linuxClient";

        Directory.CreateDirectory(dir);

        buildPlayerOptions.locationPathName = dir + "/clientLinux.x86_64";
        buildPlayerOptions.target           = BuildTarget.StandaloneLinux64;
        buildPlayerOptions.options          = BuildOptions.None;

        BuildPipeline.BuildPlayer(buildPlayerOptions);
    }
            internal static BuildPlayerOptions GetBuildPlayerOptionsInternal(bool askForBuildLocation, BuildPlayerOptions defaultBuildPlayerOptions)
            {
                var options = defaultBuildPlayerOptions;

                bool updateExistingBuild = false;

                BuildTarget      buildTarget      = EditorUserBuildSettingsUtils.CalculateSelectedBuildTarget();
                BuildTargetGroup buildTargetGroup = EditorUserBuildSettings.selectedBuildTargetGroup;

                // Pick location for the build
                string newLocation = "";

                //Check if Lz4 is supported for the current buildtargetgroup and enable it if need be
                if (PostprocessBuildPlayer.SupportsLz4Compression(buildTargetGroup, buildTarget))
                {
                    if (EditorUserBuildSettings.GetCompressionType(buildTargetGroup) == Compression.Lz4)
                    {
                        options.options |= BuildOptions.CompressWithLz4;
                    }
                    else if (EditorUserBuildSettings.GetCompressionType(buildTargetGroup) == Compression.Lz4HC)
                    {
                        options.options |= BuildOptions.CompressWithLz4HC;
                    }
                }

                bool developmentBuild = EditorUserBuildSettings.development;

                if (developmentBuild)
                {
                    options.options |= BuildOptions.Development;
                }
                if (EditorUserBuildSettings.datalessPlayer && developmentBuild)
                {
                    options.options |= BuildOptionsExperimental.DatalessPlayer;
                }
                if (EditorUserBuildSettings.allowDebugging && developmentBuild)
                {
                    options.options |= BuildOptions.AllowDebugging;
                }
                if (EditorUserBuildSettings.symlinkLibraries)
                {
                    options.options |= BuildOptions.SymlinkLibraries;
                }
                if (EditorUserBuildSettings.enableHeadlessMode)
                {
                    options.options |= BuildOptions.EnableHeadlessMode;
                }
                if (EditorUserBuildSettings.connectProfiler && (developmentBuild || buildTarget == BuildTarget.WSAPlayer))
                {
                    options.options |= BuildOptions.ConnectWithProfiler;
                }
                if (EditorUserBuildSettings.buildScriptsOnly)
                {
                    options.options |= BuildOptions.BuildScriptsOnly;
                }

                if (IsInstallInBuildFolderOption())
                {
                    options.options |= BuildOptions.InstallInBuildFolder;
                }
                else
                {
                    if (askForBuildLocation && !PickBuildLocation(buildTargetGroup, buildTarget, options.options, out updateExistingBuild))
                    {
                        throw new BuildMethodException();
                    }

                    newLocation = EditorUserBuildSettings.GetBuildLocation(buildTarget);

                    if (newLocation.Length == 0)
                    {
                        throw new BuildMethodException("Build location for buildTarget " + buildTarget.ToString() + "is not valid.");
                    }

                    if (!askForBuildLocation)
                    {
                        switch (UnityEditorInternal.InternalEditorUtility.BuildCanBeAppended(buildTarget, newLocation))
                        {
                        case CanAppendBuild.Unsupported:
                            break;

                        case CanAppendBuild.Yes:
                            updateExistingBuild = true;
                            break;

                        case CanAppendBuild.No:
                            if (!PickBuildLocation(buildTargetGroup, buildTarget, options.options, out updateExistingBuild))
                            {
                                throw new BuildMethodException();
                            }

                            newLocation = EditorUserBuildSettings.GetBuildLocation(buildTarget);
                            if (!BuildLocationIsValid(newLocation))
                            {
                                throw new BuildMethodException("Build location for buildTarget " + buildTarget.ToString() + "is not valid.");
                            }

                            break;
                        }
                    }
                }

                if (updateExistingBuild)
                {
                    options.options |= BuildOptions.AcceptExternalModificationsToPlayer;
                }

                options.target                  = buildTarget;
                options.targetGroup             = buildTargetGroup;
                options.locationPathName        = EditorUserBuildSettings.GetBuildLocation(buildTarget);
                options.assetBundleManifestPath = null;

                // Build a list of scenes that are enabled
                ArrayList scenesList = new ArrayList();

                EditorBuildSettingsScene[] editorScenes = EditorBuildSettings.scenes;
                foreach (EditorBuildSettingsScene scene in editorScenes)
                {
                    if (scene.enabled)
                    {
                        scenesList.Add(scene.path);
                    }
                }

                options.scenes = scenesList.ToArray(typeof(string)) as string[];

                return(options);
            }
 /// <summary>
 /// Default implementation for calculating build options before building the player.
 /// </summary>
 /// <param name="defaultBuildPlayerOptions"></param>
 /// <returns></returns>
 public static BuildPlayerOptions GetBuildPlayerOptions(BuildPlayerOptions defaultBuildPlayerOptions)
 {
     return(GetBuildPlayerOptionsInternal(true, defaultBuildPlayerOptions));
 }
            /// <summary>
            /// Default implementation of the build player method.
            /// </summary>
            /// <param name="options"></param>
            public static void BuildPlayer(BuildPlayerOptions options)
            {
                if (!UnityConnect.instance.canBuildWithUPID)
                {
                    if (!EditorUtility.DisplayDialog("Missing Project ID", "Because you are not a member of this project this build will not access Unity services.\nDo you want to continue?", "Yes", "No"))
                    {
                        throw new BuildMethodException();
                    }
                }

                if (!BuildPipeline.IsBuildTargetSupported(options.targetGroup, options.target))
                {
                    throw new BuildMethodException("Build target is not supported.");
                }

                string module = ModuleManager.GetTargetStringFrom(EditorUserBuildSettings.selectedBuildTargetGroup, options.target);
                IBuildWindowExtension buildWindowExtension = ModuleManager.GetBuildWindowExtension(module);

                if (buildWindowExtension != null && (options.options & BuildOptions.AutoRunPlayer) != 0 && !buildWindowExtension.EnabledBuildAndRunButton())
                {
                    throw new BuildMethodException();
                }

                if (Unsupported.IsBleedingEdgeBuild())
                {
                    var sb = new System.Text.StringBuilder();
                    sb.AppendLine("This version of Unity is a BleedingEdge build that has not seen any manual testing.");
                    sb.AppendLine("You should consider this build unstable.");
                    sb.AppendLine("We strongly recommend that you use a normal version of Unity instead.");

                    if (EditorUtility.DisplayDialog("BleedingEdge Build", sb.ToString(), "Cancel", "OK"))
                    {
                        throw new BuildMethodException();
                    }
                }

                // See if we need to switch platforms and delay the build.  We do this whenever
                // we're trying to build for a target different from the active one so as to ensure
                // that the compiled script code we have loaded is built for the same platform we
                // are building for.  As we can't reload while our editor stuff is still executing,
                // we need to defer to after the next script reload then.
                bool delayToAfterScriptReload = false;

                if (EditorUserBuildSettings.activeBuildTarget != options.target ||
                    EditorUserBuildSettings.activeBuildTargetGroup != options.targetGroup)
                {
                    if (!EditorUserBuildSettings.SwitchActiveBuildTargetAsync(options.targetGroup, options.target))
                    {
                        // Switching the build target failed.  No point in trying to continue
                        // with a build.
                        var errStr = string.Format("Could not switch to build target '{0}', '{1}'.",
                                                   BuildPipeline.GetBuildTargetGroupDisplayName(options.targetGroup),
                                                   BuildPlatforms.instance.GetBuildTargetDisplayName(options.targetGroup, options.target));
                        throw new BuildMethodException(errStr);
                    }

                    if (EditorApplication.isCompiling)
                    {
                        delayToAfterScriptReload = true;
                    }
                }

                // Trigger build.
                // Note: report will be null, if delayToAfterScriptReload = true
                var report = BuildPipeline.BuildPlayerInternalNoCheck(options.scenes, options.locationPathName, null, options.targetGroup, options.target, options.options, delayToAfterScriptReload);


                if (report != null)
                {
                    var resultStr = String.Format("Build completed with a result of '{0}'", report.summary.result.ToString("g"));

                    switch (report.summary.result)
                    {
                    case Build.Reporting.BuildResult.Unknown:
                        Debug.LogWarning(resultStr);
                        break;

                    case Build.Reporting.BuildResult.Failed:
                        DeleteBuildFolderIfEmpty(report.summary.outputPath);
                        Debug.LogError(resultStr);
                        throw new BuildMethodException(report.SummarizeErrors());

                    default:
                        Debug.Log(resultStr);
                        break;
                    }

                    buildCompletionHandler?.Invoke(report);
                }
            }
Пример #6
0
 /// <summary>
 /// <para>Builds a player.</para>
 /// </summary>
 /// <param name="buildPlayerOptions">Provide various options to control the behavior of BuildPipeline.BuildPlayer.</param>
 /// <returns>
 /// <para>An error message if an error occurred.</para>
 /// </returns>
 public static string BuildPlayer(BuildPlayerOptions buildPlayerOptions) =>
 BuildPlayer(buildPlayerOptions.scenes, buildPlayerOptions.locationPathName, buildPlayerOptions.assetBundleManifestPath, buildPlayerOptions.target, buildPlayerOptions.options);
Пример #7
0
 public static BuildReport BuildPlayer(BuildPlayerOptions buildPlayerOptions)
 {
     return(BuildPlayer(buildPlayerOptions.scenes, buildPlayerOptions.locationPathName, buildPlayerOptions.assetBundleManifestPath, buildPlayerOptions.targetGroup, buildPlayerOptions.target, buildPlayerOptions.options, buildPlayerOptions.extraScriptingDefines));
 }
Пример #8
0
 public static string BuildPlayer(BuildPlayerOptions buildPlayerOptions)
 {
     return(BuildPipeline.BuildPlayer(buildPlayerOptions.scenes, buildPlayerOptions.locationPathName, buildPlayerOptions.assetBundleManifestPath, buildPlayerOptions.targetGroup, buildPlayerOptions.target, buildPlayerOptions.options));
 }