|
19 | 19 | using UnityEditor.Compilation; |
20 | 20 | using UnityEngine; |
21 | 21 | using UnityEngine.Rendering; |
| 22 | +#if UNITY_6000_1_OR_NEWER |
| 23 | +using Unity.Web.Stripping.Editor; |
| 24 | +#endif |
22 | 25 |
|
23 | 26 | namespace UnityBuilderAction |
24 | 27 | { |
@@ -118,112 +121,140 @@ public static void Build(string[] args) |
118 | 121 | if (options.TryGetValue("tag", out string tagVersion) && |
119 | 122 | !string.IsNullOrEmpty(tagVersion)) |
120 | 123 | { |
121 | | - string[] tagParameters = tagVersion.Split('-'); |
122 | | - if (tagParameters.Contains("minsize")) |
123 | | - { |
124 | | - PlayerSettings.WebGL.template = "PROJECT:Release"; |
125 | | - buildPlayerOptions.options |= BuildOptions.CompressWithLz4HC; |
126 | | - PlayerSettings.WebGL.exceptionSupport = WebGLExceptionSupport.None; |
127 | | - SetWebGlOptimization(CodeOptimizationSize); |
| 124 | + HandleTagParameters(tagVersion, namedBuildTarget); |
| 125 | + } |
| 126 | + |
| 127 | + break; |
| 128 | + } |
| 129 | + |
| 130 | + // Additional options for local builds |
| 131 | + if (!Application.isBatchMode) |
| 132 | + { |
| 133 | + if (options.TryGetValue("autorunplayer", out string _)) |
| 134 | + { |
| 135 | + buildPlayerOptions.options |= BuildOptions.AutoRunPlayer; |
| 136 | + } |
| 137 | + |
| 138 | + var projectPath = Application.dataPath.Substring(0, Application.dataPath.Length - "/Assets".Length); |
| 139 | + BackupLastBuild($"{projectPath}/{options["customBuildPath"]}"); |
| 140 | + } |
| 141 | + |
| 142 | + errorLogMessages = new List<string>(); |
| 143 | + Application.logMessageReceived += OnLogMessageReceived; |
| 144 | + |
| 145 | + // Custom build |
| 146 | + Build(buildTarget, options["customBuildPath"]); |
| 147 | + } |
| 148 | + |
| 149 | + private static void HandleTagParameters(string tagVersion, NamedBuildTarget namedBuildTarget) |
| 150 | + { |
| 151 | + string[] tagParameters = tagVersion.Split('-'); |
| 152 | + if (tagParameters.Contains("minsize")) |
| 153 | + { |
| 154 | + PlayerSettings.WebGL.template = "PROJECT:Release"; |
| 155 | + buildPlayerOptions.options |= BuildOptions.CompressWithLz4HC; |
| 156 | + PlayerSettings.WebGL.exceptionSupport = WebGLExceptionSupport.None; |
| 157 | + SetWebGlOptimization(CodeOptimizationSize); |
128 | 158 | #if UNITY_2022_1_OR_NEWER |
129 | | - PlayerSettings.SetIl2CppCodeGeneration(namedBuildTarget, Il2CppCodeGeneration.OptimizeSize); |
| 159 | + PlayerSettings.SetIl2CppCodeGeneration(namedBuildTarget, Il2CppCodeGeneration.OptimizeSize); |
130 | 160 | #endif |
131 | 161 | #if UNITY_2021_2_OR_NEWER |
132 | | - PlayerSettings.SetIl2CppCompilerConfiguration(namedBuildTarget, Il2CppCompilerConfiguration.Master); |
| 162 | + PlayerSettings.SetIl2CppCompilerConfiguration(namedBuildTarget, Il2CppCompilerConfiguration.Master); |
133 | 163 | #else |
134 | 164 | PlayerSettings.SetIl2CppCompilerConfiguration(BuildTargetGroup.WebGL, Il2CppCompilerConfiguration.Master); |
135 | 165 | #endif |
136 | | - } |
137 | | - else if (tagParameters.Contains("debug")) |
138 | | - { |
139 | | - PlayerSettings.WebGL.template = "PROJECT:Develop"; |
140 | | - PlayerSettings.WebGL.exceptionSupport = WebGLExceptionSupport.FullWithStacktrace; |
141 | | - // For debug builds this setting will always be build times no matter what is set, setting this more as a documentation of the behavior |
142 | | - SetWebGlOptimization(CodeOptimizationBuildTimes); |
| 166 | + } |
| 167 | + else if (tagParameters.Contains("debug")) |
| 168 | + { |
| 169 | + PlayerSettings.WebGL.template = "PROJECT:Develop"; |
| 170 | + PlayerSettings.WebGL.exceptionSupport = WebGLExceptionSupport.FullWithStacktrace; |
| 171 | + // For debug builds this setting will always be build times no matter what is set, setting this more as a documentation of the behavior |
| 172 | + SetWebGlOptimization(CodeOptimizationBuildTimes); |
143 | 173 | #if UNITY_2022_1_OR_NEWER |
144 | | - PlayerSettings.SetIl2CppCodeGeneration(namedBuildTarget, Il2CppCodeGeneration.OptimizeSize); |
| 174 | + PlayerSettings.SetIl2CppCodeGeneration(namedBuildTarget, Il2CppCodeGeneration.OptimizeSize); |
145 | 175 | #endif |
146 | 176 | #if UNITY_2021_2_OR_NEWER |
147 | | - PlayerSettings.SetIl2CppCompilerConfiguration(namedBuildTarget, Il2CppCompilerConfiguration.Debug); |
148 | | - PlayerSettings.WebGL.debugSymbolMode = WebGLDebugSymbolMode.Embedded; |
| 177 | + PlayerSettings.SetIl2CppCompilerConfiguration(namedBuildTarget, Il2CppCompilerConfiguration.Debug); |
| 178 | + PlayerSettings.WebGL.debugSymbolMode = WebGLDebugSymbolMode.Embedded; |
149 | 179 | #else |
150 | 180 | PlayerSettings.SetIl2CppCompilerConfiguration(BuildTargetGroup.WebGL, Il2CppCompilerConfiguration.Debug); |
151 | 181 | PlayerSettings.WebGL.debugSymbols = true; |
152 | 182 | #endif |
153 | 183 |
|
154 | 184 | #if UNITY_2022_2_OR_NEWER |
155 | | - PlayerSettings.WebGL.showDiagnostics = true; |
| 185 | + PlayerSettings.WebGL.showDiagnostics = true; |
156 | 186 | #endif |
157 | | - buildPlayerOptions.options |= BuildOptions.Development; |
158 | | - } |
159 | | - else |
160 | | - { |
161 | | - PlayerSettings.WebGL.template = "PROJECT:Develop"; |
162 | | - // By default use the speed setting |
163 | | - SetWebGlOptimization(CodeOptimizationSpeed); |
| 187 | + buildPlayerOptions.options |= BuildOptions.Development; |
| 188 | + } |
| 189 | + else |
| 190 | + { |
| 191 | + PlayerSettings.WebGL.template = "PROJECT:Develop"; |
| 192 | + // By default use the speed setting |
| 193 | + SetWebGlOptimization(CodeOptimizationSpeed); |
164 | 194 | #if UNITY_2022_1_OR_NEWER |
165 | | - PlayerSettings.SetIl2CppCodeGeneration(namedBuildTarget, Il2CppCodeGeneration.OptimizeSpeed); |
| 195 | + PlayerSettings.SetIl2CppCodeGeneration(namedBuildTarget, Il2CppCodeGeneration.OptimizeSpeed); |
166 | 196 | #endif |
167 | 197 | #if UNITY_2021_2_OR_NEWER |
168 | | - PlayerSettings.SetIl2CppCompilerConfiguration(namedBuildTarget, Il2CppCompilerConfiguration.Master); |
| 198 | + PlayerSettings.SetIl2CppCompilerConfiguration(namedBuildTarget, Il2CppCompilerConfiguration.Master); |
169 | 199 | #else |
170 | 200 | PlayerSettings.SetIl2CppCompilerConfiguration(BuildTargetGroup.WebGL, Il2CppCompilerConfiguration.Master); |
171 | 201 | #endif |
172 | | - } |
| 202 | + } |
| 203 | + |
| 204 | + HandleSubmoduleStrippingParameters(tagParameters); |
| 205 | + SetGraphicsApi(tagParameters); |
| 206 | + } |
| 207 | + |
| 208 | + private static void HandleSubmoduleStrippingParameters(string[] tagParameters) |
| 209 | + { |
| 210 | +#if UNITY_6000_1_OR_NEWER |
| 211 | + bool enableStripping = tagParameters.Contains("minsize") || tagParameters.Contains("stripping"); |
| 212 | + PlayerSettings.WebGL.enableSubmoduleStrippingCompatibility = enableStripping; |
| 213 | + |
| 214 | + if (enableStripping) |
| 215 | + { |
| 216 | + PlayerSettings.WebGL.debugSymbolMode = WebGLDebugSymbolMode.Embedded; |
| 217 | + } |
| 218 | + StrippingProjectSettings.StripAutomaticallyAfterBuild = enableStripping; |
| 219 | + Log("Web submodule stripping is set to " + enableStripping); |
| 220 | +#else |
| 221 | + Log("Skipping Web submodule stripping since is not supported in this Unity version"); |
| 222 | +#endif |
| 223 | + } |
173 | 224 |
|
174 | | - List<GraphicsDeviceType> graphicsAPIs = new List<GraphicsDeviceType>(); |
175 | | - if (tagParameters.Contains("webgl1")) |
176 | | - { |
| 225 | + private static void SetGraphicsApi(string[] tagParameters) |
| 226 | + { |
| 227 | + List<GraphicsDeviceType> graphicsAPIs = new List<GraphicsDeviceType>(); |
| 228 | + if (tagParameters.Contains("webgl1")) |
| 229 | + { |
177 | 230 | #if !UNITY_2023_1_OR_NEWER |
178 | 231 | graphicsAPIs.Add(GraphicsDeviceType.OpenGLES2); |
179 | 232 | #else |
180 | | - LogWarning("WebGL1 not supported anymore, choosing WebGL2 instead"); |
181 | | - graphicsAPIs.Add(GraphicsDeviceType.OpenGLES3); |
| 233 | + LogWarning("WebGL1 not supported anymore, choosing WebGL2 instead"); |
| 234 | + graphicsAPIs.Add(GraphicsDeviceType.OpenGLES3); |
182 | 235 | #endif |
183 | | - } |
184 | | - if(tagParameters.Contains("webgl2")) |
185 | | - { |
186 | | - graphicsAPIs.Add(GraphicsDeviceType.OpenGLES3); |
187 | | - } |
188 | | - if(tagParameters.Contains("webgpu")) |
189 | | - { |
| 236 | + } |
| 237 | + if(tagParameters.Contains("webgl2")) |
| 238 | + { |
| 239 | + graphicsAPIs.Add(GraphicsDeviceType.OpenGLES3); |
| 240 | + } |
| 241 | + if(tagParameters.Contains("webgpu")) |
| 242 | + { |
190 | 243 | #if UNITY_2023_2_OR_NEWER |
191 | | - graphicsAPIs.Add(GraphicsDeviceType.WebGPU); |
192 | | - #if UNITY_6000_0_OR_NEWER |
193 | | - // Enable wasm2023 for WebGPU, since if webGPU is supported everything from 2023 is supported as well |
194 | | - PlayerSettings.WebGL.wasm2023 = true; |
195 | | - #endif |
| 244 | + graphicsAPIs.Add(GraphicsDeviceType.WebGPU); |
| 245 | +#if UNITY_6000_0_OR_NEWER |
| 246 | + // Enable wasm2023 for WebGPU, since if webGPU is supported everything from 2023 is supported as well |
| 247 | + PlayerSettings.WebGL.wasm2023 = true; |
| 248 | +#endif |
196 | 249 | #else |
197 | 250 | LogError("WebGPU not supported yet"); |
198 | 251 | #endif |
199 | | - } |
200 | | - |
201 | | - PlayerSettings.SetGraphicsAPIs(BuildTarget.WebGL, graphicsAPIs.ToArray()); |
202 | | - } |
203 | | - |
204 | | - break; |
205 | 252 | } |
206 | 253 |
|
207 | | - // Additional options for local builds |
208 | | - if (!Application.isBatchMode) |
209 | | - { |
210 | | - if (options.TryGetValue("autorunplayer", out string _)) |
211 | | - { |
212 | | - buildPlayerOptions.options |= BuildOptions.AutoRunPlayer; |
213 | | - } |
214 | | - |
215 | | - var projectPath = Application.dataPath.Substring(0, Application.dataPath.Length - "/Assets".Length); |
216 | | - BackupLastBuild($"{projectPath}/{options["customBuildPath"]}"); |
217 | | - } |
218 | | - |
219 | | - errorLogMessages = new List<string>(); |
220 | | - Application.logMessageReceived += OnLogMessageReceived; |
221 | | - |
222 | | - // Custom build |
223 | | - Build(buildTarget, options["customBuildPath"]); |
| 254 | + PlayerSettings.SetGraphicsAPIs(BuildTarget.WebGL, graphicsAPIs.ToArray()); |
224 | 255 | } |
225 | 256 |
|
226 | | - private static void OnLogMessageReceived(string logString, string stackTrace, LogType type) |
| 257 | + private static void OnLogMessageReceived(string logString, string stackTrace, LogType type) |
227 | 258 | { |
228 | 259 | if(type == LogType.Error || type == LogType.Exception) |
229 | 260 | { |
|
0 commit comments