A collection of useful helper classes for Unity builds.
Add npmjs registry to Packages/manifest.json
in your Unity project.
{
"scopedRegistries": [
{
"name": "npmjs",
"url": "https://registry.npmjs.com",
"scopes": ["jp.masakura.unity"]
}
],
"dependencies": {
// ...
- Open Package Manager Window with Your Unity project.
- Click
+
, selectAdd package by name...
- entry
jp.masakura.unity.build.helper
- Click
Add
- Open Package Manager Window with your Unity project.
- Click
+
, selectAdd package from git URL...
- entry
https://gitlab.com/ignis-build/unity-build-helper.git?path=Packages/jp.masakura.unity.build.helper
- Click
Add
Temporarily modify Unity build-time settings.
using (var settings = new TemporarySettings())
{
// Property.
settings.SetValue(() => PlayerSettings.usePlayerLog, false);
// Getter method.
settings.SetValue(() => PlayerSettings.GetApplicationIdentifier(BuildTargetGroup.Android), "com.example.app1");
// Modify symbol.
settings.Symbol(() => PlayerSettings.GetScriptingDefineSymbolsForGroup(BuildTargetGroup.Android),
symbols.Add("DEBUG").Remove("LOGO"));
BuildPlayer.BuildPipeline(/* ... */);
}
// When the Dispose() method is called,
// the setting values are reverted to their original values.
You can temporarily set code signing for Android and iOS.
// temporary siging settings for Android.
settings.Android().Signing(AndroidSigning.Manual(
"path/to/app.keystore",
"keystore password",
"alias name",
"alias password"
));
// temporary unsigned settings for Android.
settings.Android().Signing(AndroidSigning.Unsigned());
c
// The Signing Settings in PlayerSettings will be used as they are.
settings.Android().Signing(AndroidSigning.UsePlayerSettings());
// temporary auto signing settings for iOS.
settings.iOS().Signing(iOSSigning.Auto("apple developer team id"));
// temporary manual signing settings for iOS.
settings.iOS().Signing(iOSSigning.Manual(
"apple developer team id",
ProvisioningProfileType.Distribution,
"provisioning profile uuid"
));
// The Signing Settings in PlayerSettings will be used as they are.
settings.iOS().Signing(iOSSigning.UsePlayerSettings());
It is also possible to handle the signing settings for both Android and iOS together.
var signing = new CodeSigning(
AndroidSigning.Unsigned(),
iOSSigning.Auto("apple developer team id")
);
// The signing settings for both Android and iOS will be changed.
settings.Signing(signing);
// The Signing Settings in PlayerSettings will be used as they are.
settings.Signing(CodeSigning.UsePlayerSettings());
After the process execution, the Editor will be closed if it's in batch mode.
[MenuItem("Batch/Task")]
public static RunTask()
{
// Normal method.
BatchScope.Run(() => { YourTask(); });
}
[MenuItem("Batch/Coroutine")]
public static RunCoroutine()
{
// Coroutine.
BatchScope.Run(YourCoroutine());
}
When running within -batchmode
, -quit
is not necessary.
$ /path/to/Unity -batchmode -executeMethod Batch.RunTask
It manages the scenes specified for BuildPipeline.BuildPlayer().
var scenes = UnityScenes.All()
.MoveToPrimary(By.Name("Debug")) // Set Debug scene as the primary scene.
.OnlyEnabled(); // Enabled scene only.
BuildPipeline.BuildPlayer(
scenes,
// ...
);
Run xcodebuild using coroutine.
var xcodeBuild = new XcodeBuild()
.WithWorkingDirectory("/path/to/directory");
EditorCoroutineUtility.StartCoroutineOwnerless(
xcodeBuild.Run(args => args.Add("-projectPath", "/path/to/project"))
);
It can also be used in combination with BatchScope
.
BatchScope.Run(
xcodeBuild.Run(args => args.Add("-projectPath", "/path/to/project"))
);
var project = new XcodeProject("/path/to/xcode/project");
EditorCoroutineUtility.StartCoroutineOwnerless(
project
.Archive("/path/to/project.xcarchive", args => args
.Configuration("Release")
.UnityScheme())
.Export("/path/to/export/directory", "/path/to/ExportOptions.plist")
);
Archive Xcode archive and Xcode export into zip.
var project = new XcodeProject("/path/to/xcode/project");
EditorCoroutineUtility.StartCoroutineOwnerless(
project
.Archive("/path/to/project.xcarchive", args => args /* ... */)
.Zip("/path/to/project.xcarchive.zip")
);