Skip to content

Commit

Permalink
chore: mac build script to build without alttester
Browse files Browse the repository at this point in the history
  • Loading branch information
nattb8 committed Aug 13, 2024
1 parent 52f8664 commit c397f1a
Showing 1 changed file with 66 additions and 23 deletions.
89 changes: 66 additions & 23 deletions sample/Assets/Editor/MacBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,87 @@
using AltTester.AltTesterUnitySDK;
using System;

public class BuildScript
public class MacBuilder
{
private const string DefaultBuildPath = "Builds/MacOS/SampleApp.app";

static void Build()
{
BuildPlayer(DefaultBuildPath, BuildOptions.None);
}

static void BuildForAltTester()
{
BuildPlayer(DefaultBuildPath, BuildOptions.Development | BuildOptions.IncludeTestAssemblies | BuildOptions.AutoRunPlayer, true);
}

private static void BuildPlayer(string defaultBuildPath, BuildOptions buildOptions, bool setupForAltTester = false)
{
try
{
BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions();
buildPlayerOptions.scenes = new string[] {
"Assets/Scenes/SelectAuthMethod.unity",
"Assets/Scenes/UnauthenticatedScene.unity",
"Assets/Scenes/AuthenticatedScene.unity",
"Assets/Scenes/ZkEvmGetBalance.unity",
"Assets/Scenes/ZkEvmGetTransactionReceipt.unity",
"Assets/Scenes/ZkEvmSendTransaction.unity",
"Assets/Scenes/ImxNftTransfer.unity"
};
string buildPath = GetBuildPathFromArgs(defaultBuildPath);
BuildPlayerOptions buildPlayerOptions = CreateBuildPlayerOptions(buildPath, buildOptions);

buildPlayerOptions.locationPathName = "Builds/MacOS/SampleApp.app";
buildPlayerOptions.target = BuildTarget.StandaloneOSX;
buildPlayerOptions.options = BuildOptions.Development | BuildOptions.IncludeTestAssemblies | BuildOptions.AutoRunPlayer;

// Setup for AltTester
var buildTargetGroup = BuildTargetGroup.Standalone;
AltBuilder.AddAltTesterInScriptingDefineSymbolsGroup(buildTargetGroup);
if (buildTargetGroup == UnityEditor.BuildTargetGroup.Standalone)
AltBuilder.CreateJsonFileForInputMappingOfAxis();
var instrumentationSettings = new AltInstrumentationSettings();
AltBuilder.InsertAltInScene(buildPlayerOptions.scenes[0], instrumentationSettings);
if (setupForAltTester)
{
SetupAltTester(buildPlayerOptions);
}

var results = BuildPipeline.BuildPlayer(buildPlayerOptions);
AltBuilder.RemoveAltTesterFromScriptingDefineSymbols(BuildTargetGroup.Standalone);

if (setupForAltTester)
{
// Clean up AltTester settings after build
AltBuilder.RemoveAltTesterFromScriptingDefineSymbols(BuildTargetGroup.Standalone);
}
}
catch (Exception exception)
{
Debug.LogException(exception);
}
}

private static string GetBuildPathFromArgs(string defaultBuildPath)
{
string[] args = Environment.GetCommandLineArgs();
for (int i = 0; i < args.Length; i++)
{
if (args[i] == "--buildPath" && i + 1 < args.Length)
{
return args[i + 1];
}
}
return defaultBuildPath;
}

private static BuildPlayerOptions CreateBuildPlayerOptions(string buildPath, BuildOptions buildOptions)
{
return new BuildPlayerOptions
{
scenes = new[]
{
"Assets/Scenes/SelectAuthMethod.unity",
"Assets/Scenes/UnauthenticatedScene.unity",
"Assets/Scenes/AuthenticatedScene.unity",
"Assets/Scenes/ZkEvmGetBalance.unity",
"Assets/Scenes/ZkEvmGetTransactionReceipt.unity",
"Assets/Scenes/ZkEvmSendTransaction.unity",
"Assets/Scenes/ImxNftTransfer.unity"
},
locationPathName = buildPath,
target = BuildTarget.StandaloneOSX,
options = buildOptions
};
}

private static void SetupAltTester(BuildPlayerOptions buildPlayerOptions)
{
AltBuilder.AddAltTesterInScriptingDefineSymbolsGroup(BuildTargetGroup.Standalone);
AltBuilder.CreateJsonFileForInputMappingOfAxis();

var instrumentationSettings = new AltInstrumentationSettings();
AltBuilder.InsertAltInScene(buildPlayerOptions.scenes[0], instrumentationSettings);
}
}

#endif

0 comments on commit c397f1a

Please sign in to comment.