|
6 | 6 | using AltTester.AltTesterUnitySDK;
|
7 | 7 | using System;
|
8 | 8 |
|
9 |
| -public class BuildScript |
| 9 | +public class MacBuilder |
10 | 10 | {
|
| 11 | + private const string DefaultBuildPath = "Builds/MacOS/SampleApp.app"; |
| 12 | + |
| 13 | + static void Build() |
| 14 | + { |
| 15 | + BuildPlayer(DefaultBuildPath, BuildOptions.None); |
| 16 | + } |
| 17 | + |
11 | 18 | static void BuildForAltTester()
|
| 19 | + { |
| 20 | + BuildPlayer(DefaultBuildPath, BuildOptions.Development | BuildOptions.IncludeTestAssemblies | BuildOptions.AutoRunPlayer, true); |
| 21 | + } |
| 22 | + |
| 23 | + private static void BuildPlayer(string defaultBuildPath, BuildOptions buildOptions, bool setupForAltTester = false) |
12 | 24 | {
|
13 | 25 | try
|
14 | 26 | {
|
15 |
| - BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions(); |
16 |
| - buildPlayerOptions.scenes = new string[] { |
17 |
| - "Assets/Scenes/SelectAuthMethod.unity", |
18 |
| - "Assets/Scenes/UnauthenticatedScene.unity", |
19 |
| - "Assets/Scenes/AuthenticatedScene.unity", |
20 |
| - "Assets/Scenes/ZkEvmGetBalance.unity", |
21 |
| - "Assets/Scenes/ZkEvmGetTransactionReceipt.unity", |
22 |
| - "Assets/Scenes/ZkEvmSendTransaction.unity", |
23 |
| - "Assets/Scenes/ImxNftTransfer.unity" |
24 |
| - }; |
| 27 | + string buildPath = GetBuildPathFromArgs(defaultBuildPath); |
| 28 | + BuildPlayerOptions buildPlayerOptions = CreateBuildPlayerOptions(buildPath, buildOptions); |
25 | 29 |
|
26 |
| - buildPlayerOptions.locationPathName = "Builds/MacOS/SampleApp.app"; |
27 |
| - buildPlayerOptions.target = BuildTarget.StandaloneOSX; |
28 |
| - buildPlayerOptions.options = BuildOptions.Development | BuildOptions.IncludeTestAssemblies | BuildOptions.AutoRunPlayer; |
29 |
| - |
30 |
| - // Setup for AltTester |
31 |
| - var buildTargetGroup = BuildTargetGroup.Standalone; |
32 |
| - AltBuilder.AddAltTesterInScriptingDefineSymbolsGroup(buildTargetGroup); |
33 |
| - if (buildTargetGroup == UnityEditor.BuildTargetGroup.Standalone) |
34 |
| - AltBuilder.CreateJsonFileForInputMappingOfAxis(); |
35 |
| - var instrumentationSettings = new AltInstrumentationSettings(); |
36 |
| - AltBuilder.InsertAltInScene(buildPlayerOptions.scenes[0], instrumentationSettings); |
| 30 | + if (setupForAltTester) |
| 31 | + { |
| 32 | + SetupAltTester(buildPlayerOptions); |
| 33 | + } |
37 | 34 |
|
38 | 35 | var results = BuildPipeline.BuildPlayer(buildPlayerOptions);
|
39 |
| - AltBuilder.RemoveAltTesterFromScriptingDefineSymbols(BuildTargetGroup.Standalone); |
40 | 36 |
|
| 37 | + if (setupForAltTester) |
| 38 | + { |
| 39 | + // Clean up AltTester settings after build |
| 40 | + AltBuilder.RemoveAltTesterFromScriptingDefineSymbols(BuildTargetGroup.Standalone); |
| 41 | + } |
41 | 42 | }
|
42 | 43 | catch (Exception exception)
|
43 | 44 | {
|
44 | 45 | Debug.LogException(exception);
|
45 | 46 | }
|
46 | 47 | }
|
| 48 | + |
| 49 | + private static string GetBuildPathFromArgs(string defaultBuildPath) |
| 50 | + { |
| 51 | + string[] args = Environment.GetCommandLineArgs(); |
| 52 | + for (int i = 0; i < args.Length; i++) |
| 53 | + { |
| 54 | + if (args[i] == "--buildPath" && i + 1 < args.Length) |
| 55 | + { |
| 56 | + return args[i + 1]; |
| 57 | + } |
| 58 | + } |
| 59 | + return defaultBuildPath; |
| 60 | + } |
| 61 | + |
| 62 | + private static BuildPlayerOptions CreateBuildPlayerOptions(string buildPath, BuildOptions buildOptions) |
| 63 | + { |
| 64 | + return new BuildPlayerOptions |
| 65 | + { |
| 66 | + scenes = new[] |
| 67 | + { |
| 68 | + "Assets/Scenes/SelectAuthMethod.unity", |
| 69 | + "Assets/Scenes/UnauthenticatedScene.unity", |
| 70 | + "Assets/Scenes/AuthenticatedScene.unity", |
| 71 | + "Assets/Scenes/ZkEvmGetBalance.unity", |
| 72 | + "Assets/Scenes/ZkEvmGetTransactionReceipt.unity", |
| 73 | + "Assets/Scenes/ZkEvmSendTransaction.unity", |
| 74 | + "Assets/Scenes/ImxNftTransfer.unity" |
| 75 | + }, |
| 76 | + locationPathName = buildPath, |
| 77 | + target = BuildTarget.StandaloneOSX, |
| 78 | + options = buildOptions |
| 79 | + }; |
| 80 | + } |
| 81 | + |
| 82 | + private static void SetupAltTester(BuildPlayerOptions buildPlayerOptions) |
| 83 | + { |
| 84 | + AltBuilder.AddAltTesterInScriptingDefineSymbolsGroup(BuildTargetGroup.Standalone); |
| 85 | + AltBuilder.CreateJsonFileForInputMappingOfAxis(); |
| 86 | + |
| 87 | + var instrumentationSettings = new AltInstrumentationSettings(); |
| 88 | + AltBuilder.InsertAltInScene(buildPlayerOptions.scenes[0], instrumentationSettings); |
| 89 | + } |
47 | 90 | }
|
48 | 91 |
|
49 | 92 | #endif
|
0 commit comments