public static void BuildProject()
        {
            // Gather values from args
            var options = ArgumentsParser.GetValidatedOptions();

            // Gather values from project
            var scenes = EditorBuildSettings.scenes.Where(scene => scene.enabled).Select(s => s.path).ToArray();

            BuildOptions  selectedOptions = BuildOptions.None;
            string        definesString   = PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup);
            List <string> allDefines      = definesString.Split(';').ToList();

            if (options.ContainsKey("buildType") && options["buildType"].Equals("server", StringComparison.OrdinalIgnoreCase))
            {
                selectedOptions |= BuildOptions.EnableHeadlessMode;
                Console.WriteLine("Creating Server Build");
                // allDefines.Add("UNITY_SERVER");
                allDefines.Remove("UNITY_CLIENT");
            }
            else
            {
                Console.WriteLine("Creating Client Build");
                // allDefines.Remove("UNITY_SERVER");
                if (!allDefines.Contains("UNITY_CLIENT"))
                {
                    allDefines.Add("UNITY_CLIENT");
                }
            }
            PlayerSettings.SetScriptingDefineSymbolsForGroup(
                EditorUserBuildSettings.selectedBuildTargetGroup,
                string.Join(";", allDefines.ToArray()));

            if (options.ContainsKey("development"))
            {
                EditorUserBuildSettings.development     = true;
                EditorUserBuildSettings.allowDebugging  = true;
                EditorUserBuildSettings.connectProfiler = true;

                selectedOptions |= BuildOptions.Development |
                                   BuildOptions.AllowDebugging |
                                   BuildOptions.ConnectWithProfiler;
            }

            // Define BuildPlayer Options
            var buildOptions = new BuildPlayerOptions
            {
                scenes           = scenes,
                locationPathName = options["customBuildPath"],
                target           = (BuildTarget)Enum.Parse(typeof(BuildTarget), options["buildTarget"]),
                options          = selectedOptions,
            };

            // Perform build
            BuildReport buildReport = BuildPipeline.BuildPlayer(buildOptions);

            // Reset build defines
            PlayerSettings.SetScriptingDefineSymbolsForGroup(
                EditorUserBuildSettings.selectedBuildTargetGroup,
                definesString);
        }
Beispiel #2
0
        public static void BuildProject()
        {
            // Gather values from args
            var options = ArgumentsParser.GetValidatedOptions();

            // Gather values from project
            var scenes = EditorBuildSettings.scenes.Where(scene => scene.enabled).Select(s => s.path).ToArray();

            // Define BuildPlayer Options
            var buildOptions = new BuildPlayerOptions {
                scenes           = scenes,
                locationPathName = options["customBuildPath"],
                target           = (BuildTarget)Enum.Parse(typeof(BuildTarget), options["buildTarget"]),
            };

            // Set version for this build
            VersionApplicator.SetVersion(options["version"]);

            // Perform build
            BuildReport buildReport = BuildPipeline.BuildPlayer(buildOptions);

            // Summary
            BuildSummary summary = buildReport.summary;

            StdOutReporter.ReportSummary(summary);

            // Result
            BuildResult result = summary.result;

            StdOutReporter.ExitWithResult(result);
        }
Beispiel #3
0
        public static void BuildProject()
        {
            // Gather values from args
            var options = ArgumentsParser.GetValidatedOptions();

            // Gather values from project
            var scenes = EditorBuildSettings.scenes.Where(scene => scene.enabled).Select(s => s.path).ToArray();

            // Get all buildOptions from options
            BuildOptions buildOptions = BuildOptions.None;

            foreach (string buildOptionString in Enum.GetNames(typeof(BuildOptions)))
            {
                if (options.ContainsKey(buildOptionString))
                {
                    BuildOptions buildOptionEnum = (BuildOptions)Enum.Parse(typeof(BuildOptions), buildOptionString);
                    buildOptions |= buildOptionEnum;
                }
            }

            // Define BuildPlayer Options
            var buildPlayerOptions = new BuildPlayerOptions {
                scenes           = scenes,
                locationPathName = options["customBuildPath"],
                target           = (BuildTarget)Enum.Parse(typeof(BuildTarget), options["buildTarget"]),
                options          = buildOptions
            };

            // Set version for this build
            VersionApplicator.SetVersion(options["buildVersion"]);
            VersionApplicator.SetAndroidVersionCode(options["androidVersionCode"]);

            // Apply Android settings
            if (buildPlayerOptions.target == BuildTarget.Android)
            {
                AndroidSettings.Apply(options);
            }

            // Execute default AddressableAsset content build, if the package is installed
#if USE_ADDRESSABLES
            AddressableAssetSettings.CleanPlayerContent();
            AddressableAssetSettings.BuildPlayerContent();
#endif

            // Perform build
            BuildReport buildReport = BuildPipeline.BuildPlayer(buildPlayerOptions);

            // Summary
            BuildSummary summary = buildReport.summary;
            StdOutReporter.ReportSummary(summary);

            // Result
            BuildResult result = summary.result;
            StdOutReporter.ExitWithResult(result);
        }
Beispiel #4
0
        public static void BuildProject()
        {
            // Gather values from args
            var options = ArgumentsParser.GetValidatedOptions();

            // Gather values from project
            var scenes = EditorBuildSettings.scenes.Where(scene => scene.enabled).Select(s => s.path).ToArray();

            // Get all buildOptions from options
            BuildOptions buildOptions = BuildOptions.None;

            foreach (string buildOptionString in Enum.GetNames(typeof(BuildOptions)))
            {
                if (options.ContainsKey(buildOptionString))
                {
                    BuildOptions buildOptionEnum = (BuildOptions)Enum.Parse(typeof(BuildOptions), buildOptionString);
                    buildOptions |= buildOptionEnum;
                }
            }

            // Define BuildPlayer Options
            var buildPlayerOptions = new BuildPlayerOptions {
                scenes           = scenes,
                locationPathName = options["customBuildPath"],
                target           = (BuildTarget)Enum.Parse(typeof(BuildTarget), options["buildTarget"]),
                options          = buildOptions
            };

            // Set version for this build
            VersionApplicator.SetVersion(options["buildVersion"]);
            VersionApplicator.SetAndroidVersionCode(options["androidVersionCode"]);

            // Apply Android settings
            if (buildPlayerOptions.target == BuildTarget.Android)
            {
                AndroidSettings.Apply(options);
            }

            // Execute default AddressableAsset content build, if the package is installed.
            // Version defines would be the best solution here, but Unity 2018 doesn't support that,
            // so we fall back to using reflection instead.
            var addressableAssetSettingsType = Type.GetType(
                "UnityEditor.AddressableAssets.Settings.AddressableAssetSettings,Unity.Addressables.Editor");

            if (addressableAssetSettingsType != null)
            {
                // ReSharper disable once PossibleNullReferenceException, used from try-catch
                void CallAddressablesMethod(string methodName, object[] args) => addressableAssetSettingsType
                .GetMethod(methodName, BindingFlags.Static | BindingFlags.Public)
                .Invoke(null, args);

                try
                {
                    CallAddressablesMethod("CleanPlayerContent", new object[] { null });
                    CallAddressablesMethod("BuildPlayerContent", Array.Empty <object>());
                }
                catch (Exception e)
                {
                    Debug.LogError($"Failed to run default addressables build:\n{e}");
                }
            }

            // Perform build
            BuildReport buildReport = BuildPipeline.BuildPlayer(buildPlayerOptions);

            // Summary
            BuildSummary summary = buildReport.summary;

            StdOutReporter.ReportSummary(summary);

            // Result
            BuildResult result = summary.result;

            StdOutReporter.ExitWithResult(result);
        }