2020-04-21 22:08:08 +00:00
|
|
|
|
using System;
|
2019-11-30 23:23:56 +00:00
|
|
|
|
using System.Linq;
|
2021-04-02 09:11:56 +00:00
|
|
|
|
using System.Reflection;
|
2020-04-21 22:08:08 +00:00
|
|
|
|
using UnityBuilderAction.Input;
|
|
|
|
|
using UnityBuilderAction.Reporting;
|
|
|
|
|
using UnityBuilderAction.Versioning;
|
2019-11-30 23:23:56 +00:00
|
|
|
|
using UnityEditor;
|
|
|
|
|
using UnityEditor.Build.Reporting;
|
2021-04-02 09:11:56 +00:00
|
|
|
|
using UnityEngine;
|
2021-03-19 17:50:39 +00:00
|
|
|
|
|
2019-12-07 22:43:37 +00:00
|
|
|
|
namespace UnityBuilderAction
|
2019-11-30 23:23:56 +00:00
|
|
|
|
{
|
2019-12-07 22:43:37 +00:00
|
|
|
|
static class Builder
|
2019-11-30 23:23:56 +00:00
|
|
|
|
{
|
2019-12-07 22:43:37 +00:00
|
|
|
|
public static void BuildProject()
|
|
|
|
|
{
|
|
|
|
|
// Gather values from args
|
2020-04-21 22:08:08 +00:00
|
|
|
|
var options = ArgumentsParser.GetValidatedOptions();
|
2019-11-30 23:23:56 +00:00
|
|
|
|
|
2019-12-07 22:43:37 +00:00
|
|
|
|
// Gather values from project
|
|
|
|
|
var scenes = EditorBuildSettings.scenes.Where(scene => scene.enabled).Select(s => s.path).ToArray();
|
2021-01-05 18:19:16 +00:00
|
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-11-30 23:23:56 +00:00
|
|
|
|
|
2023-04-15 17:23:51 +00:00
|
|
|
|
#if UNITY_2021_2_OR_NEWER
|
|
|
|
|
// Determine subtarget
|
|
|
|
|
StandaloneBuildSubtarget buildSubtarget;
|
|
|
|
|
if (!options.TryGetValue("standaloneBuildSubtarget", out var subtargetValue) || !Enum.TryParse(subtargetValue, out buildSubtarget)) {
|
|
|
|
|
buildSubtarget = default;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2019-12-07 22:43:37 +00:00
|
|
|
|
// Define BuildPlayer Options
|
2021-01-05 18:19:16 +00:00
|
|
|
|
var buildPlayerOptions = new BuildPlayerOptions {
|
2019-12-07 22:43:37 +00:00
|
|
|
|
scenes = scenes,
|
|
|
|
|
locationPathName = options["customBuildPath"],
|
|
|
|
|
target = (BuildTarget) Enum.Parse(typeof(BuildTarget), options["buildTarget"]),
|
2023-04-15 17:23:51 +00:00
|
|
|
|
options = buildOptions,
|
|
|
|
|
#if UNITY_2021_2_OR_NEWER
|
|
|
|
|
subtarget = (int) buildSubtarget
|
|
|
|
|
#endif
|
2019-12-07 22:43:37 +00:00
|
|
|
|
};
|
2019-11-30 23:23:56 +00:00
|
|
|
|
|
2020-04-21 22:08:08 +00:00
|
|
|
|
// Set version for this build
|
2020-08-16 19:09:34 +00:00
|
|
|
|
VersionApplicator.SetVersion(options["buildVersion"]);
|
2020-07-06 01:41:21 +00:00
|
|
|
|
|
|
|
|
|
// Apply Android settings
|
2021-01-05 18:19:16 +00:00
|
|
|
|
if (buildPlayerOptions.target == BuildTarget.Android)
|
2022-01-25 21:18:15 +00:00
|
|
|
|
{
|
|
|
|
|
VersionApplicator.SetAndroidVersionCode(options["androidVersionCode"]);
|
2020-07-06 01:41:21 +00:00
|
|
|
|
AndroidSettings.Apply(options);
|
2022-01-25 21:18:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-02 09:11:56 +00:00
|
|
|
|
// 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
|
|
|
|
|
try
|
|
|
|
|
{
|
2021-05-20 15:51:54 +00:00
|
|
|
|
addressableAssetSettingsType.GetMethod("CleanPlayerContent", BindingFlags.Static | BindingFlags.Public)
|
|
|
|
|
.Invoke(null, new object[] {null});
|
|
|
|
|
addressableAssetSettingsType.GetMethod("BuildPlayerContent", new Type[0]).Invoke(null, new object[0]);
|
2021-04-02 09:11:56 +00:00
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
2024-10-10 14:02:39 +00:00
|
|
|
|
Debug.LogError("Failed to run default addressables build:\n" + e);
|
2021-04-02 09:11:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-03-19 17:50:39 +00:00
|
|
|
|
|
2019-12-07 22:43:37 +00:00
|
|
|
|
// Perform build
|
2021-01-05 18:19:16 +00:00
|
|
|
|
BuildReport buildReport = BuildPipeline.BuildPlayer(buildPlayerOptions);
|
2019-11-30 23:23:56 +00:00
|
|
|
|
|
2019-12-07 22:43:37 +00:00
|
|
|
|
// Summary
|
|
|
|
|
BuildSummary summary = buildReport.summary;
|
2020-04-21 22:08:08 +00:00
|
|
|
|
StdOutReporter.ReportSummary(summary);
|
2019-11-30 23:23:56 +00:00
|
|
|
|
|
2019-12-07 22:43:37 +00:00
|
|
|
|
// Result
|
|
|
|
|
BuildResult result = summary.result;
|
2020-04-21 22:08:08 +00:00
|
|
|
|
StdOutReporter.ExitWithResult(result);
|
2019-11-30 23:23:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|