-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
668 additions
and
238 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
233 changes: 0 additions & 233 deletions
233
Samples/AppKit Sample/Assets/Editor/UnityBuilderAction/BuildScript.cs
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
Samples/AppKit Sample/Assets/Editor/UnityBuilderAction/BuildScript.cs.meta
This file was deleted.
Oops, something went wrong.
93 changes: 93 additions & 0 deletions
93
Samples/AppKit Sample/Assets/Editor/UnityBuilderAction/Builder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Samples/AppKit Sample/Assets/Editor/UnityBuilderAction/Builder.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
Samples/AppKit Sample/Assets/Editor/UnityBuilderAction/Input.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.