/// <summary>
        /// Start a build using Unity's command line.
        /// </summary>
        public static async void StartCommandLineBuild()
        {
            // We don't need stack traces on all our logs. Makes things a lot easier to read.
            Application.SetStackTraceLogType(LogType.Log, StackTraceLogType.None);
            Debug.Log($"Starting command line build for {EditorUserBuildSettings.activeBuildTarget}...");
            EditorAssemblyReloadManager.LockReloadAssemblies = true;

            bool success;

            try
            {
                switch (EditorUserBuildSettings.activeBuildTarget)
                {
                case BuildTarget.WSAPlayer:
                    success = await UwpPlayerBuildTools.BuildPlayer(new UwpBuildInfo(true) { BuildAppx = true });

                    break;

                default:
                    var buildInfo = new BuildInfo(true) as IBuildInfo;
                    ParseBuildCommandLine(ref buildInfo);
                    var buildResult = BuildUnityPlayer(buildInfo);
                    success = buildResult.summary.result == BuildResult.Succeeded;
                    break;
                }
            }
            catch (Exception e)
            {
                Debug.LogError($"Build Failed!\n{e.Message}\n{e.StackTrace}");
                success = false;
            }

            Debug.Log($"Exiting command line build... Build success? {success}");
            EditorApplication.Exit(success ? 0 : 1);
        }
Esempio n. 2
0
        /// <summary>
        /// Do a build configured for UWP Applications to the specified path, returns the error from <see cref="UwpPlayerBuildTools.BuildUwpPlayer"/>
        /// </summary>
        /// <returns>True, if build was successful.</returns>
        public static bool BuildUnityPlayer(string buildDirectory, bool showDialog = true)
        {
            bool buildSuccess = false;

            if (CheckBuildScenes() == false)
            {
                return(false);
            }

            var buildInfo = new BuildInfo
            {
                // These properties should all match what the Standalone.proj file specifies
                OutputDirectory = buildDirectory,
                Scenes          = EditorBuildSettings.scenes.Where(scene => scene.enabled).Select(scene => scene.path),
                BuildTarget     = BuildTarget.WSAPlayer,
                WSASdk          = WSASDK.UWP,
                WSAUWPBuildType = EditorUserBuildSettings.wsaUWPBuildType,
                WSAUwpSdk       = EditorUserBuildSettings.wsaUWPSDK,

                // Configure a post build action that will compile the generated solution
                PostBuildAction = async(innerBuildInfo, buildReport) =>
                {
                    if (buildReport.summary.result != BuildResult.Succeeded)
                    {
                        EditorUtility.DisplayDialog($"{PlayerSettings.productName} WindowsStoreApp Build {buildReport.summary.result}!", "See console for details", "OK");
                    }
                    else
                    {
                        if (showDialog)
                        {
                            if (!EditorUtility.DisplayDialog(PlayerSettings.productName, "Build Complete", "OK", "Build AppX"))
                            {
                                EditorAssemblyReloadManager.LockReloadAssemblies = true;
                                await BuildAppxAsync(
                                    PlayerSettings.productName,
                                    BuildDeployPreferences.ForceRebuild,
                                    BuildDeployPreferences.BuildConfig,
                                    BuildDeployPreferences.BuildPlatform,
                                    BuildDeployPreferences.BuildDirectory,
                                    BuildDeployPreferences.IncrementBuildVersion);

                                EditorAssemblyReloadManager.LockReloadAssemblies = false;
                            }
                        }

                        buildSuccess = true;
                    }
                }
            };

            UwpPlayerBuildTools.RaiseOverrideBuildDefaults(ref buildInfo);
            UwpPlayerBuildTools.BuildUwpPlayer(buildInfo);

            return(buildSuccess);
        }