|
2 | 2 |
|
3 | 3 | using UnityEngine;
|
4 | 4 | using UnityEditor;
|
| 5 | +using UnityEditor.SceneManagement; |
5 | 6 | using AltTester.AltTesterUnitySDK.Editor;
|
6 | 7 | using AltTester.AltTesterUnitySDK;
|
7 | 8 | using System;
|
8 | 9 |
|
9 |
| -public class BuildScript |
| 10 | +public class MacBuilder |
10 | 11 | {
|
| 12 | + private const string DefaultBuildPath = "Builds/MacOS/SampleApp.app"; |
| 13 | + |
| 14 | + static void Build() |
| 15 | + { |
| 16 | + BuildPlayer(DefaultBuildPath, BuildOptions.None); |
| 17 | + } |
| 18 | + |
11 | 19 | static void BuildForAltTester()
|
| 20 | + { |
| 21 | + BuildPlayer(DefaultBuildPath, BuildOptions.Development | BuildOptions.IncludeTestAssemblies | BuildOptions.AutoRunPlayer, true); |
| 22 | + } |
| 23 | + |
| 24 | + private static void BuildPlayer(string defaultBuildPath, BuildOptions buildOptions, bool setupForAltTester = false) |
12 | 25 | {
|
13 | 26 | try
|
14 | 27 | {
|
15 |
| - BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions(); |
16 |
| - buildPlayerOptions.scenes = new string[] { |
| 28 | + string buildPath = GetBuildPathFromArgs(defaultBuildPath); |
| 29 | + BuildPlayerOptions buildPlayerOptions = CreateBuildPlayerOptions(buildPath, buildOptions); |
| 30 | + |
| 31 | + if (setupForAltTester) |
| 32 | + { |
| 33 | + SetupAltTester(buildPlayerOptions); |
| 34 | + } |
| 35 | + |
| 36 | + var results = BuildPipeline.BuildPlayer(buildPlayerOptions); |
| 37 | + |
| 38 | + if (setupForAltTester) |
| 39 | + { |
| 40 | + // Clean up AltTester settings after build |
| 41 | + AltBuilder.RemoveAltTesterFromScriptingDefineSymbols(BuildTargetGroup.Standalone); |
| 42 | + RemoveAltFromScene(buildPlayerOptions.scenes[0]); |
| 43 | + } |
| 44 | + } |
| 45 | + catch (Exception exception) |
| 46 | + { |
| 47 | + Debug.LogException(exception); |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + private static string GetBuildPathFromArgs(string defaultBuildPath) |
| 52 | + { |
| 53 | + string[] args = Environment.GetCommandLineArgs(); |
| 54 | + for (int i = 0; i < args.Length; i++) |
| 55 | + { |
| 56 | + if (args[i] == "--buildPath" && i + 1 < args.Length) |
| 57 | + { |
| 58 | + return args[i + 1]; |
| 59 | + } |
| 60 | + } |
| 61 | + return defaultBuildPath; |
| 62 | + } |
| 63 | + |
| 64 | + private static BuildPlayerOptions CreateBuildPlayerOptions(string buildPath, BuildOptions buildOptions) |
| 65 | + { |
| 66 | + return new BuildPlayerOptions |
| 67 | + { |
| 68 | + scenes = new[] |
| 69 | + { |
17 | 70 | "Assets/Scenes/SelectAuthMethod.unity",
|
18 | 71 | "Assets/Scenes/UnauthenticatedScene.unity",
|
19 | 72 | "Assets/Scenes/AuthenticatedScene.unity",
|
20 | 73 | "Assets/Scenes/ZkEvmGetBalance.unity",
|
21 | 74 | "Assets/Scenes/ZkEvmGetTransactionReceipt.unity",
|
22 | 75 | "Assets/Scenes/ZkEvmSendTransaction.unity",
|
23 | 76 | "Assets/Scenes/ImxNftTransfer.unity"
|
24 |
| - }; |
| 77 | + }, |
| 78 | + locationPathName = buildPath, |
| 79 | + target = BuildTarget.StandaloneOSX, |
| 80 | + options = buildOptions |
| 81 | + }; |
| 82 | + } |
25 | 83 |
|
26 |
| - buildPlayerOptions.locationPathName = "Builds/MacOS/SampleApp.app"; |
27 |
| - buildPlayerOptions.target = BuildTarget.StandaloneOSX; |
28 |
| - buildPlayerOptions.options = BuildOptions.Development | BuildOptions.IncludeTestAssemblies | BuildOptions.AutoRunPlayer; |
| 84 | + private static void SetupAltTester(BuildPlayerOptions buildPlayerOptions) |
| 85 | + { |
| 86 | + AltBuilder.AddAltTesterInScriptingDefineSymbolsGroup(BuildTargetGroup.Standalone); |
| 87 | + AltBuilder.CreateJsonFileForInputMappingOfAxis(); |
29 | 88 |
|
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); |
| 89 | + var instrumentationSettings = new AltInstrumentationSettings(); |
| 90 | + AltBuilder.InsertAltInScene(buildPlayerOptions.scenes[0], instrumentationSettings); |
| 91 | + } |
37 | 92 |
|
38 |
| - var results = BuildPipeline.BuildPlayer(buildPlayerOptions); |
39 |
| - AltBuilder.RemoveAltTesterFromScriptingDefineSymbols(BuildTargetGroup.Standalone); |
| 93 | + public static void RemoveAltFromScene(string scene) |
| 94 | + { |
| 95 | + Debug.Log("Removing AltTesterPrefab from the [" + scene + "] scene."); |
| 96 | + |
| 97 | + var sceneToModify = EditorSceneManager.OpenScene(scene); |
| 98 | + |
| 99 | + // Find the AltTesterPrefab instance in the scene |
| 100 | + var altRunner = GameObject.FindObjectOfType<AltRunner>(); |
| 101 | + |
| 102 | + if (altRunner != null) |
| 103 | + { |
| 104 | + // Destroy the AltTesterPrefab instance |
| 105 | + GameObject.DestroyImmediate(altRunner.gameObject); |
40 | 106 |
|
| 107 | + // Mark the scene as dirty and save it |
| 108 | + EditorSceneManager.MarkSceneDirty(sceneToModify); |
| 109 | + EditorSceneManager.SaveOpenScenes(); |
| 110 | + |
| 111 | + Debug.Log("AltTesterPrefab successfully removed from the [" + scene + "] scene."); |
41 | 112 | }
|
42 |
| - catch (Exception exception) |
| 113 | + else |
43 | 114 | {
|
44 |
| - Debug.LogException(exception); |
| 115 | + Debug.LogWarning("AltTesterPrefab was not found in the [" + scene + "] scene."); |
45 | 116 | }
|
46 | 117 | }
|
| 118 | + |
47 | 119 | }
|
48 | 120 |
|
49 | 121 | #endif
|
0 commit comments