Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions docs/03-github/04-builder.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,24 @@ _**required:** `false`_ _**default:** `""`_
#### projectPath

Specify the path to your Unity project to be built. The path should be relative to the root of your
project.
repository.

_**required:** `false`_ _**default:** `<your project root>`_
_**required:** `false`_ _**default:** `<your repository root>`_

#### buildProfile

Provide a path to a build profile. The path should be relative to the root of your Unity project
(i.e. relative to `projectPath`). See the
[Unity documentation](https://docs.unity3d.com/Manual/build-profiles.html) for more information on
using build profiles.

```yaml
- uses: game-ci/unity-builder@v4
with:
buildProfile: 'Assets/Settings/Build Profiles/WindowsDemo.asset'
```

_**required:** `false`_ _**default:** Unity will do a platform build for the `targetPlatform`._

#### buildName

Expand Down
35 changes: 35 additions & 0 deletions example/BuildScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
using System.Linq;
using UnityEditor;
using UnityEditor.Build.Reporting;
#if UNITY_6000_0_OR_NEWER
using UnityEditor.Build.Profile;
#endif

namespace UnityBuilderAction
{
Expand Down Expand Up @@ -89,6 +92,38 @@ public static void Build()
Build(buildTarget, buildSubtarget, options["customBuildPath"]);
}

#if UNITY_6000_0_OR_NEWER
public static void BuildWithProfile()
{
// Gather values from args
Dictionary<string, string> options = GetValidatedOptions();

// Load build profile from Assets folder
BuildProfile buildProfile = AssetDatabase.LoadAssetAtPath<BuildProfile>(options["customBuildProfile"]);

// Set it as active
BuildProfile.SetActiveBuildProfile(buildProfile);
// 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 BuildPlayerWithProfileOptions
var buildPlayerWithProfileOptions = new BuildPlayerWithProfileOptions {
buildProfile = buildProfile,
locationPathName = options["customBuildPath"],
options = buildOptions,
};

BuildSummary buildSummary = BuildPipeline.BuildPlayer(buildPlayerWithProfileOptions).summary;
ReportSummary(buildSummary);
ExitWithResult(buildSummary.result);
}
#endif

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Update GetValidatedOptions for build profile support.

The GetValidatedOptions method should be updated to validate the customBuildProfile option when using Unity 6.0.0 or newer.

Apply this diff to update the method:

         private static Dictionary<string, string> GetValidatedOptions()
         {
             ParseCommandLineArguments(out Dictionary<string, string> validatedOptions);
 
+#if UNITY_6000_0_OR_NEWER
+            // Validate customBuildProfile when using BuildWithProfile
+            if (validatedOptions.TryGetValue("buildWithProfile", out string useProfile) && 
+                useProfile.ToLower() == "true" && 
+                !validatedOptions.TryGetValue("customBuildProfile", out string _))
+            {
+                Console.WriteLine("Missing argument -customBuildProfile when buildWithProfile is true");
+                EditorApplication.Exit(140);
+            }
+#endif

Committable suggestion skipped: line range outside the PR's diff.

private static Dictionary<string, string> GetValidatedOptions()
{
ParseCommandLineArguments(out Dictionary<string, string> validatedOptions);
Expand Down