From 2cafae9dbbf0fb29736dbdec751f1d7f0f94d928 Mon Sep 17 00:00:00 2001 From: Natalie Bunduwongse Date: Tue, 13 Aug 2024 18:01:18 +1200 Subject: [PATCH] chore: mac build script to build without alttester --- sample/Assets/Editor/MacBuilder.cs | 87 ++++++++++++++++++++++-------- 1 file changed, 66 insertions(+), 21 deletions(-) diff --git a/sample/Assets/Editor/MacBuilder.cs b/sample/Assets/Editor/MacBuilder.cs index 1261631a..adae77da 100644 --- a/sample/Assets/Editor/MacBuilder.cs +++ b/sample/Assets/Editor/MacBuilder.cs @@ -6,14 +6,59 @@ 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[] { + string buildPath = GetBuildPathFromArgs(defaultBuildPath); + BuildPlayerOptions buildPlayerOptions = CreateBuildPlayerOptions(buildPath, buildOptions); + + if (setupForAltTester) + { + SetupAltTester(buildPlayerOptions); + } + + var results = BuildPipeline.BuildPlayer(buildPlayerOptions); + } + 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", @@ -21,28 +66,28 @@ static void BuildForAltTester() "Assets/Scenes/ZkEvmGetTransactionReceipt.unity", "Assets/Scenes/ZkEvmSendTransaction.unity", "Assets/Scenes/ImxNftTransfer.unity" - }; - - 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); + }, + locationPathName = buildPath, + target = BuildTarget.StandaloneOSX, + options = buildOptions + }; + } - var results = BuildPipeline.BuildPlayer(buildPlayerOptions); - AltBuilder.RemoveAltTesterFromScriptingDefineSymbols(BuildTargetGroup.Standalone); + private static void SetupAltTester(BuildPlayerOptions buildPlayerOptions) + { + var buildTargetGroup = BuildTargetGroup.Standalone; + AltBuilder.AddAltTesterInScriptingDefineSymbolsGroup(buildTargetGroup); - } - catch (Exception exception) + if (buildTargetGroup == BuildTargetGroup.Standalone) { - Debug.LogException(exception); + AltBuilder.CreateJsonFileForInputMappingOfAxis(); } + + var instrumentationSettings = new AltInstrumentationSettings(); + AltBuilder.InsertAltInScene(buildPlayerOptions.scenes[0], instrumentationSettings); + + // Clean up AltTester settings after build + AltBuilder.RemoveAltTesterFromScriptingDefineSymbols(buildTargetGroup); } }