Skip to content

Commit b044950

Browse files
committed
Merge branch 'master' of https://github.com/JohannesDeml/UnityWebGL-LoadingTest into 2021.3-urp
2 parents a564920 + 35acae7 commit b044950

File tree

2 files changed

+76
-53
lines changed

2 files changed

+76
-53
lines changed

Assets/Scripts/Editor/BuildScript.cs

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public static class BuildScript
5757
{ "androidKeystorePass", "androidKeyaliasName", "androidKeyaliasPass" };
5858

5959
private static BuildPlayerOptions buildPlayerOptions;
60+
private static List<string> errorLogMessages = new List<string>();
6061

6162
[UsedImplicitly]
6263
public static void BuildWithCommandlineArgs()
@@ -121,26 +122,32 @@ public static void Build(string[] args)
121122
if (tagParameters.Contains("minsize"))
122123
{
123124
PlayerSettings.WebGL.template = "PROJECT:Release";
124-
SetWebGlOptimization(CodeOptimizationSize);
125125
buildPlayerOptions.options |= BuildOptions.CompressWithLz4HC;
126126
PlayerSettings.WebGL.exceptionSupport = WebGLExceptionSupport.None;
127-
PlayerSettings.SetIl2CppCompilerConfiguration(BuildTargetGroup.WebGL, Il2CppCompilerConfiguration.Master);
127+
SetWebGlOptimization(CodeOptimizationSize);
128128
#if UNITY_2022_1_OR_NEWER
129129
PlayerSettings.SetIl2CppCodeGeneration(namedBuildTarget, Il2CppCodeGeneration.OptimizeSize);
130+
#endif
131+
#if UNITY_2021_2_OR_NEWER
132+
PlayerSettings.SetIl2CppCompilerConfiguration(namedBuildTarget, Il2CppCompilerConfiguration.Master);
133+
#else
134+
PlayerSettings.SetIl2CppCompilerConfiguration(BuildTargetGroup.WebGL, Il2CppCompilerConfiguration.Master);
130135
#endif
131136
}
132137
else if (tagParameters.Contains("debug"))
133138
{
134139
PlayerSettings.WebGL.template = "PROJECT:Develop";
135140
PlayerSettings.WebGL.exceptionSupport = WebGLExceptionSupport.FullWithStacktrace;
136-
PlayerSettings.SetIl2CppCompilerConfiguration(BuildTargetGroup.WebGL, Il2CppCompilerConfiguration.Debug);
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
137142
SetWebGlOptimization(CodeOptimizationBuildTimes);
138143
#if UNITY_2022_1_OR_NEWER
139144
PlayerSettings.SetIl2CppCodeGeneration(namedBuildTarget, Il2CppCodeGeneration.OptimizeSize);
140145
#endif
141146
#if UNITY_2021_2_OR_NEWER
147+
PlayerSettings.SetIl2CppCompilerConfiguration(namedBuildTarget, Il2CppCompilerConfiguration.Debug);
142148
PlayerSettings.WebGL.debugSymbolMode = WebGLDebugSymbolMode.Embedded;
143149
#else
150+
PlayerSettings.SetIl2CppCompilerConfiguration(BuildTargetGroup.WebGL, Il2CppCompilerConfiguration.Debug);
144151
PlayerSettings.WebGL.debugSymbols = true;
145152
#endif
146153

@@ -152,18 +159,27 @@ public static void Build(string[] args)
152159
else
153160
{
154161
PlayerSettings.WebGL.template = "PROJECT:Develop";
155-
PlayerSettings.SetIl2CppCompilerConfiguration(BuildTargetGroup.WebGL, Il2CppCompilerConfiguration.Master);
156162
// By default use the speed setting
157163
SetWebGlOptimization(CodeOptimizationSpeed);
158164
#if UNITY_2022_1_OR_NEWER
159165
PlayerSettings.SetIl2CppCodeGeneration(namedBuildTarget, Il2CppCodeGeneration.OptimizeSpeed);
166+
#endif
167+
#if UNITY_2021_2_OR_NEWER
168+
PlayerSettings.SetIl2CppCompilerConfiguration(namedBuildTarget, Il2CppCompilerConfiguration.Master);
169+
#else
170+
PlayerSettings.SetIl2CppCompilerConfiguration(BuildTargetGroup.WebGL, Il2CppCompilerConfiguration.Master);
160171
#endif
161172
}
162173

163174
List<GraphicsDeviceType> graphicsAPIs = new List<GraphicsDeviceType>();
164175
if (tagParameters.Contains("webgl1"))
165176
{
177+
#if !UNITY_2023_1_OR_NEWER
166178
graphicsAPIs.Add(GraphicsDeviceType.OpenGLES2);
179+
#else
180+
LogWarning("WebGL1 not supported anymore, choosing WebGL2 instead");
181+
graphicsAPIs.Add(GraphicsDeviceType.OpenGLES3);
182+
#endif
167183
}
168184
if(tagParameters.Contains("webgl2"))
169185
{
@@ -173,19 +189,14 @@ public static void Build(string[] args)
173189
{
174190
#if UNITY_2023_2_OR_NEWER
175191
graphicsAPIs.Add(GraphicsDeviceType.WebGPU);
192+
// Enable wasm2023 for WebGPU, since if webGPU is supported everything from 2023 is supported as well
193+
PlayerSettings.WebGL.wasm2023 = true;
176194
#else
177195
LogError("WebGPU not supported yet");
178196
#endif
179197
}
180198

181199
PlayerSettings.SetGraphicsAPIs(BuildTarget.WebGL, graphicsAPIs.ToArray());
182-
183-
#if UNITY_2023_1_OR_NEWER
184-
if (tagParameters.Contains("webgl1"))
185-
{
186-
Log("WebGL1 not supported anymore, choosing WebGL2 instead");
187-
}
188-
#endif
189200
}
190201

191202
break;
@@ -203,11 +214,22 @@ public static void Build(string[] args)
203214
BackupLastBuild($"{projectPath}/{options["customBuildPath"]}");
204215
}
205216

217+
errorLogMessages = new List<string>();
218+
Application.logMessageReceived += OnLogMessageReceived;
219+
206220
// Custom build
207221
Build(buildTarget, options["customBuildPath"]);
208222
}
209223

210-
private static void BackupLastBuild(string buildPath)
224+
private static void OnLogMessageReceived(string logString, string stackTrace, LogType type)
225+
{
226+
if(type == LogType.Error || type == LogType.Exception)
227+
{
228+
errorLogMessages.Add($"{logString}{Eol}{stackTrace}");
229+
}
230+
}
231+
232+
private static void BackupLastBuild(string buildPath)
211233
{
212234
if (Directory.Exists(buildPath))
213235
{
@@ -342,6 +364,12 @@ private static void ReportSummary(BuildSummary summary)
342364
$"Size: {summary.totalSize.ToString()} bytes{Eol}" +
343365
$"{Eol}";
344366

367+
if(errorLogMessages.Count > 0)
368+
{
369+
summaryText += $"### Error log messages: ###{Eol}";
370+
summaryText += string.Join(Eol, errorLogMessages);
371+
}
372+
345373
if (summary.totalErrors == 0)
346374
{
347375
Log(summaryText);
@@ -421,6 +449,18 @@ private static void Log(string message)
421449
}
422450
}
423451

452+
private static void LogWarning(string message)
453+
{
454+
if(Application.isBatchMode)
455+
{
456+
Console.WriteLine(message);
457+
}
458+
else
459+
{
460+
Debug.LogWarning(message);
461+
}
462+
}
463+
424464
private static void LogError(string message)
425465
{
426466
if(Application.isBatchMode)

README.md

Lines changed: 24 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
[![](https://img.shields.io/github/release-date/JohannesDeml/UnityWebGL-LoadingTest.svg)](https://github.com/JohannesDeml/UnityWebGL-LoadingTest/releases) [![Tested up to Unity 6](https://img.shields.io/badge/tested%20up%20to%20unity-6000.0-green.svg?logo=unity&cacheSeconds=2592000)](https://unity3d.com/get-unity/download/archive)
66

7-
*Testing Unity's WebGL size and loading time for different versions (2018.4 - 6000.0) and platforms*
7+
*Testing Unity's WebGL size and loading time for different versions (2018.4 - 6000.0) and settings*
88

99
* [Unity Forum Thread](https://forum.unity.com/threads/webgl-builds-for-mobile.545877/)
1010
* [Overview page of all builds](https://deml.io/experiments/unity-webgl/)
@@ -30,79 +30,62 @@
3030

3131
## Live Demos
3232

33-
3433
### Built-in Renderpipeline WebGL2
3534
Version | Size | Link
3635
--- | --- | ---
37-
2023.2.10f1 | 3.19 MB | https://deml.io/experiments/unity-webgl/2023.2.10f1-webgl2
38-
2023.1.20f1 | 3.10 MB | https://deml.io/experiments/unity-webgl/2023.1.20f1-webgl2
39-
2022.3.20f1 | 3.08 MB | https://deml.io/experiments/unity-webgl/2022.3.20f1-webgl2
40-
2022.2.18f1 | 3.06 MB | https://deml.io/experiments/unity-webgl/2022.2.18f1-webgl2
41-
2022.1.24f1 | 2.82 MB | https://deml.io/experiments/unity-webgl/2022.1.24f1-webgl2
42-
2021.3.35f1 | 2.77 MB | https://deml.io/experiments/unity-webgl/2021.3.35f1-webgl2
36+
6000.0.9f1 | 3.26 MB | https://deml.io/experiments/unity-webgl/6000.0.9f1-webgl2
37+
2023.2.20f1 | 3.23 MB | https://deml.io/experiments/unity-webgl/2023.2.20f1-webgl2
38+
2023.1.20f1 | 3.14 MB | https://deml.io/experiments/unity-webgl/2023.1.20f1-webgl2
39+
2022.3.36f1 | 3.12 MB | https://deml.io/experiments/unity-webgl/2022.3.36f1-webgl2
40+
2021.3.35f1 | 2.78 MB | https://deml.io/experiments/unity-webgl/2021.3.35f1-webgl2
4341
2020.3.48f1 | 2.96 MB | https://deml.io/experiments/unity-webgl/2020.3.48f1-webgl2
44-
2019.4.40f1 | 3.05 MB | https://deml.io/experiments/unity-webgl/2019.4.40f1-webgl2
45-
2018.4.36f1 | 2.84 MB | https://deml.io/experiments/unity-webgl/2018.4.36f1-webgl2
4642

4743
### Built-in Renderpipeline WebGL1
4844
Version | Size | Link
4945
--- | --- | ---
50-
2022.3.20f1 | 3.06 MB | https://deml.io/experiments/unity-webgl/2022.3.20f1-webgl1
51-
2022.2.18f1 | 3.04 MB | https://deml.io/experiments/unity-webgl/2022.2.18f1-webgl1
52-
2022.1.24f1 | 2.80 MB | https://deml.io/experiments/unity-webgl/2022.1.24f1-webgl1
46+
2022.3.36f1 | 3.10 MB | https://deml.io/experiments/unity-webgl/2022.3.36f1-webgl1
5347
2021.3.35f1 | 2.76 MB | https://deml.io/experiments/unity-webgl/2021.3.35f1-webgl1
5448
2020.3.48f1 | 2.94 MB | https://deml.io/experiments/unity-webgl/2020.3.48f1-webgl1
55-
2019.4.40f1 | 3.01 MB | https://deml.io/experiments/unity-webgl/2019.4.40f1-webgl1
56-
2018.4.36f1 | 2.82 MB | https://deml.io/experiments/unity-webgl/2018.4.36f1-webgl1
5749

5850
### Built-in Renderpipeline Minimum size
5951
Version | Size | Link
6052
--- | --- | ---
61-
2023.2.10f1 | 3.02 MB | https://deml.io/experiments/unity-webgl/2023.2.10f1-minsize-webgl2
62-
2023.1.20f1 | 2.86 MB | https://deml.io/experiments/unity-webgl/2023.1.20f1-minsize-webgl2
63-
2022.3.20f1 | 2.84 MB | https://deml.io/experiments/unity-webgl/2022.3.20f1-minsize-webgl1
64-
2022.2.18f1 | 2.69 MB | https://deml.io/experiments/unity-webgl/2022.2.18f1-minsize-webgl1
65-
2022.1.24f1 | 2.64 MB | https://deml.io/experiments/unity-webgl/2022.1.24f1-minsize-webgl1
66-
2021.3.35f1 | 2.60 MB | https://deml.io/experiments/unity-webgl/2021.3.35f1-minsize-webgl1
53+
6000.0.9f1 | 3.16 MB | https://deml.io/experiments/unity-webgl/6000.0.9f1-minsize-webgl2
54+
2023.2.20f1 | 2.85 MB | https://deml.io/experiments/unity-webgl/2023.2.20f1-minsize-webgl2
55+
2023.1.20f1 | 2.72 MB | https://deml.io/experiments/unity-webgl/2023.1.20f1-minsize-webgl2
56+
2022.3.36f1 | 2.69 MB | https://deml.io/experiments/unity-webgl/2022.3.36f1-minsize-webgl1
57+
2021.3.35f1 | 2.73 MB | https://deml.io/experiments/unity-webgl/2021.3.35f1-minsize-webgl1
6758
2020.3.48f1 | 2.48 MB | https://deml.io/experiments/unity-webgl/2020.3.48f1-minsize-webgl1
68-
2019.4.40f1 | 2.96 MB | https://deml.io/experiments/unity-webgl/2019.4.40f1-minsize-webgl1
69-
2018.4.36f1 | 2.77 MB | https://deml.io/experiments/unity-webgl/2018.4.36f1-minsize-webgl1
7059

7160
### URP WebGL2
7261
Version | Size | Link
7362
--- | --- | ---
74-
2023.2.10f1 | 6.66 MB | https://deml.io/experiments/unity-webgl/2023.2.10f1-urp-webgl2
75-
2023.1.20f1 | 6.06 MB | https://deml.io/experiments/unity-webgl/2023.1.20f1-urp-webgl2
76-
2022.3.20f1 | 5.76 MB | https://deml.io/experiments/unity-webgl/2022.3.20f1-urp-webgl2
77-
2022.2.18f1 | 7.22 MB | https://deml.io/experiments/unity-webgl/2022.2.18f1-urp-webgl2
78-
2022.1.24f1 | 6.47 MB | https://deml.io/experiments/unity-webgl/2022.1.24f1-urp-webgl2
79-
2021.3.35f1 | 6.30 MB | https://deml.io/experiments/unity-webgl/2021.3.35f1-urp-webgl2
63+
6000.0.9f1 | 7.27 MB | https://deml.io/experiments/unity-webgl/6000.0.9f1-urp-webgl2
64+
2023.2.20f1 | 6.87 MB | https://deml.io/experiments/unity-webgl/2023.2.20f1-urp-webgl2
65+
2023.1.20f1 | 6.25 MB | https://deml.io/experiments/unity-webgl/2023.1.20f1-urp-webgl2
66+
2022.3.36f1 | 5.92 MB | https://deml.io/experiments/unity-webgl/2022.3.36f1-urp-webgl2
67+
2021.3.35f1 | 6.31 MB | https://deml.io/experiments/unity-webgl/2021.3.35f1-urp-webgl2
8068
2020.3.48f1 | 5.60 MB | https://deml.io/experiments/unity-webgl/2020.3.48f1-urp-webgl2
81-
2019.4.40f1 | 5.56 MB | https://deml.io/experiments/unity-webgl/2019.4.40f1-urp-webgl2
82-
2018.4.36f1 | 2.81 MB | https://deml.io/experiments/unity-webgl/2018.4.36f1-urp-webgl2
8369

8470
### URP WebGL1
8571
Version | Size | Link
8672
--- | --- | ---
87-
2022.3.20f1 | 5.73 MB | https://deml.io/experiments/unity-webgl/2022.3.20f1-urp-webgl1
88-
2022.2.18f1 | 7.08 MB | https://deml.io/experiments/unity-webgl/2022.2.18f1-urp-webgl1
89-
2022.1.24f1 | 6.33 MB | https://deml.io/experiments/unity-webgl/2022.1.24f1-urp-webgl1
90-
2021.3.35f1 | 6.12 MB | https://deml.io/experiments/unity-webgl/2021.3.35f1-urp-webgl1
73+
2022.3.36f1 | 5.89 MB | https://deml.io/experiments/unity-webgl/2022.3.36f1-urp-webgl1
74+
2021.3.35f1 | 6.13 MB | https://deml.io/experiments/unity-webgl/2021.3.35f1-urp-webgl1
9175
2020.3.48f1 | 5.44 MB | https://deml.io/experiments/unity-webgl/2020.3.48f1-urp-webgl1
92-
2019.4.40f1 | 5.51 MB | https://deml.io/experiments/unity-webgl/2019.4.40f1-urp-webgl1
93-
2018.4.36f1 | 2.80 MB | https://deml.io/experiments/unity-webgl/2018.4.36f1-urp-webgl1
9476

9577
### URP Minimum Size
9678
Version | Size | Link
9779
--- | --- | ---
98-
2023.2.10f1 | 6.38 MB | https://deml.io/experiments/unity-webgl/2023.2.10f1-urp-minsize-webgl2
80+
6000.0.9f1 | 6.51 MB | https://deml.io/experiments/unity-webgl/6000.0.9f1-urp-minsize-webgl2
81+
2023.2.20f1 | 5.30 MB | https://deml.io/experiments/unity-webgl/2023.2.20f1-urp-minsize-webgl2
9982
2023.1.20f1 | 5.71 MB | https://deml.io/experiments/unity-webgl/2023.1.20f1-urp-minsize-webgl2
100-
2022.3.20f1 | 5.38 MB | https://deml.io/experiments/unity-webgl/2022.3.20f1-urp-minsize-webgl1
101-
2022.1.24f1 | 6.06 MB | https://deml.io/experiments/unity-webgl/2022.1.24f1-urp-minsize-webgl1
102-
2021.3.35f1 | 5.87 MB | https://deml.io/experiments/unity-webgl/2021.3.35f1-urp-minsize-webgl1
83+
2022.3.36f1 | 4.64 MB | https://deml.io/experiments/unity-webgl/2022.3.36f1-urp-minsize-webgl1
84+
2021.3.35f1 | 6.11 MB | https://deml.io/experiments/unity-webgl/2021.3.35f1-urp-minsize-webgl1
10385
2020.3.48f1 | 4.86 MB | https://deml.io/experiments/unity-webgl/2020.3.48f1-urp-minsize-webgl1
10486

10587

88+
10689
## Platform Compatibility
10790

10891
| Platform | Chrome | Firefox | Edge | Safari | Internet Explorer |

0 commit comments

Comments
 (0)