From c397f1af317c8ed8386166e8ea41a6e9982e30fd Mon Sep 17 00:00:00 2001 From: Natalie Bunduwongse Date: Wed, 14 Aug 2024 08:36:01 +1200 Subject: [PATCH] chore: mac build script to build without alttester --- sample/Assets/Editor/MacBuilder.cs | 89 ++++++++++++++++++++++-------- 1 file changed, 66 insertions(+), 23 deletions(-) diff --git a/sample/Assets/Editor/MacBuilder.cs b/sample/Assets/Editor/MacBuilder.cs index 1261631a..20983299 100644 --- a/sample/Assets/Editor/MacBuilder.cs +++ b/sample/Assets/Editor/MacBuilder.cs @@ -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