Skip to content

Commit

Permalink
Fork default builds script
Browse files Browse the repository at this point in the history
  • Loading branch information
skibitsky committed Aug 13, 2024
1 parent a73445b commit ed923d0
Show file tree
Hide file tree
Showing 31 changed files with 668 additions and 238 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
projectPath: ${{ matrix.projectPath }}
targetPlatform: ${{ matrix.targetPlatform }}
customParameters: -Development -test ${{ secrets.TEST_SECRET }}
buildMethod: UnityBuilderAction.BuildScript.Build
buildMethod: UnityBuilderAction.Builder.Build
- uses: actions/upload-artifact@v3
with:
name: Build-${{ matrix.targetPlatform }}
Expand Down
233 changes: 0 additions & 233 deletions Samples/AppKit Sample/Assets/Editor/UnityBuilderAction/BuildScript.cs

This file was deleted.

This file was deleted.

93 changes: 93 additions & 0 deletions Samples/AppKit Sample/Assets/Editor/UnityBuilderAction/Builder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using System;
using System.Linq;
using System.Reflection;
using UnityBuilderAction.Input;
using UnityBuilderAction.Reporting;
using UnityBuilderAction.Versioning;
using UnityEditor;
using UnityEditor.Build.Reporting;
using UnityEngine;

namespace UnityBuilderAction
{
static class Builder
{
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;
}
}

#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

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

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

// Apply Android settings
if (buildPlayerOptions.target == BuildTarget.Android)
{
VersionApplicator.SetAndroidVersionCode(options["androidVersionCode"]);
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
try
{
addressableAssetSettingsType.GetMethod("CleanPlayerContent", BindingFlags.Static | BindingFlags.Public)
.Invoke(null, new object[] {null});
addressableAssetSettingsType.GetMethod("BuildPlayerContent", new Type[0]).Invoke(null, new object[0]);
}
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);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ed923d0

Please sign in to comment.