Skip to content

Commit 289655d

Browse files
committed
Merge branch 'master' into 2021.3-urp
2 parents 0e16361 + 30e821b commit 289655d

File tree

13 files changed

+268
-120
lines changed

13 files changed

+268
-120
lines changed

.github/scripts/add-tags.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
# This script creates tags for the given unity version to trigger the release workflow
3+
# example usage
4+
# sh add-tags.sh "6000.0.0f1" -> Creates tags for non-urp version
5+
# sh add-tags.sh "6000.0.0f1" "true" -> Creates tags for urp version
6+
7+
# Input parameters
8+
UNITY_VERSION=$1
9+
IS_URP=${2:-"false"}
10+
echo "Running add_tags.sh with UNITY_VERSION: $UNITY_VERSION, IS_URP: $IS_URP"
11+
12+
# Extract the value before the first dot as an integer
13+
MAJOR_VERSION=$(echo $UNITY_VERSION | cut -d. -f1)
14+
BRANCH_NAME=${GITHUB_REF#refs/heads/}
15+
16+
TAG_PREFIX=$UNITY_VERSION
17+
if [[ "$IS_URP" == "true" ]]
18+
then
19+
TAG_PREFIX=$UNITY_VERSION-urp
20+
fi
21+
22+
if [[ "$MAJOR_VERSION" -lt "2023" ]]
23+
then
24+
git tag -a -f $TAG_PREFIX-minsize-webgl1 -m "[Automated workflow] Created by upgrade-unity"
25+
git tag -a -f $TAG_PREFIX-webgl1 -m "[Automated workflow] Created by upgrade-unity"
26+
else
27+
git tag -a -f $TAG_PREFIX-minsize-webgl2 -m "[Automated workflow] Created by upgrade-unity"
28+
fi
29+
# Push tags in between - pushing more than 3 tags won't trigger tag workflows
30+
git push origin -f --tags
31+
32+
git tag -a -f $TAG_PREFIX-webgl2 -m "[Automated workflow] Created by upgrade-unity"
33+
git tag -a -f $TAG_PREFIX-webgl2-debug -m "[Automated workflow] Created by upgrade-unity"
34+
35+
if [[ "$MAJOR_VERSION" -ge "6000" ]]
36+
then
37+
git tag -a -f $TAG_PREFIX-webgpu -m "[Automated workflow] Created by upgrade-unity"
38+
fi
39+
40+
git push origin -f --tags

.github/workflows/activation.yml

Lines changed: 0 additions & 19 deletions
This file was deleted.

.github/workflows/release.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,15 @@ jobs:
7777
# Unity 2020 cache is not compatible with older versions
7878
- name: Unity Library Cache 2020 or higher
7979
if: ${{ !startsWith(needs.variables.outputs.UNITY_VERSION, '201') }}
80-
uses: actions/cache@v3
80+
uses: actions/cache@v4
8181
with:
8282
path: Library
8383
key: Library-202x-WebGL
8484
restore-keys: Library-202x-
8585

8686
- name: Unity Library Cache 2019 or lower
8787
if: ${{ startsWith(needs.variables.outputs.UNITY_VERSION, '201') }}
88-
uses: actions/cache@v3
88+
uses: actions/cache@v4
8989
with:
9090
path: Library
9191
key: Library-201x-WebGL
@@ -101,9 +101,10 @@ jobs:
101101
buildMethod: UnityBuilderAction.BuildScript.BuildWithCommandlineArgs
102102
customParameters: -tag ${{ needs.variables.outputs.TAG }}
103103
targetPlatform: WebGL
104+
versioning: None
104105
buildName: ${{ needs.variables.outputs.BUILD_NAME }}
105106

106-
- uses: actions/upload-artifact@v3
107+
- uses: actions/upload-artifact@v4
107108
with:
108109
name: ${{ needs.variables.outputs.BUILD_NAME }}
109110
path: build/WebGL
@@ -116,7 +117,7 @@ jobs:
116117
runs-on: ubuntu-latest
117118
steps:
118119
- name: Create Release
119-
uses: softprops/action-gh-release@v1
120+
uses: softprops/action-gh-release@v2
120121
with:
121122
body: |
122123
## Changes
@@ -140,7 +141,7 @@ jobs:
140141
- name: Checkout code
141142
uses: actions/checkout@v4
142143

143-
- uses: actions/download-artifact@v3
144+
- uses: actions/download-artifact@v4
144145
with:
145146
name: ${{ needs.variables.outputs.BUILD_NAME }}
146147
path: build
@@ -150,7 +151,7 @@ jobs:
150151
working-directory: build/${{ needs.variables.outputs.BUILD_NAME }}
151152

152153
- name: Deploy ⤴
153-
uses: SamKirkland/FTP-Deploy-Action@4.3.3
154+
uses: SamKirkland/FTP-Deploy-Action@v4.3.5
154155
with:
155156
server: ${{ secrets.FTP_SERVER }}
156157
username: ${{ secrets.FTP_USER }}

.github/workflows/upgrade-unity.yml

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,15 @@ jobs:
8787
# Unity 2020 cache is not compatible with older versions
8888
- name: Unity Library Cache 2020 or higher
8989
if: ${{ !startsWith(inputs.unityVersion, '201') }}
90-
uses: actions/cache@v3
90+
uses: actions/cache@v4
9191
with:
9292
path: Library
9393
key: Library-202x-WebGL
9494
restore-keys: Library-202x-
9595

9696
- name: Unity Library Cache 2019 or lower
9797
if: ${{ startsWith(inputs.unityVersion, '201') }}
98-
uses: actions/cache@v3
98+
uses: actions/cache@v4
9999
with:
100100
path: Library
101101
key: Library-201x-WebGL
@@ -137,7 +137,7 @@ jobs:
137137
customParameters: ${{ inputs.customParameters }}
138138
unityVersion: ${{ inputs.unityVersion }}
139139
targetPlatform: WebGL
140-
buildName: ${{ needs.variables.outputs.BUILD_NAME }}
140+
buildName: ${{ steps.upgrade_name.outputs.NAME }}
141141
allowDirtyBuild: true
142142
manualExit: true
143143

@@ -148,7 +148,7 @@ jobs:
148148
- name: Render template
149149
if: ${{ !inputs.tagsOnly }}
150150
id: template
151-
uses: chuhlomin/render-template@v1.4
151+
uses: chuhlomin/render-template@v1.9
152152
with:
153153
template: .github/templates/upgrade-unity-pr-body.md
154154
vars: |
@@ -168,30 +168,15 @@ jobs:
168168
- name: Add tags
169169
if: ${{ inputs.createTags || inputs.tagsOnly }}
170170
run: |
171-
# Extract the first four characters of UNITY_VERSION
172-
UNITY_YEAR=${UNITY_VERSION:0:4}
173171
BRANCH_NAME=${GITHUB_REF#refs/heads/}
174172
175-
TAG_PREFIX=$UNITY_VERSION
176-
if [[ "$BRANCH_NAME" == *"urp"* ]]
177-
then
178-
TAG_PREFIX=$UNITY_VERSION-urp
173+
IS_URP=false
174+
if [[ "$BRANCH_NAME" == *"urp"* ]]; then
175+
IS_URP=true
179176
fi
180177
181-
if [[ "$UNITY_YEAR" < "2023" ]]
182-
then
183-
git tag -a -f $TAG_PREFIX-minsize-webgl1 -m "[Automated workflow] Created by upgrade-unity"
184-
git tag -a -f $TAG_PREFIX-webgl1 -m "[Automated workflow] Created by upgrade-unity"
185-
else
186-
git tag -a -f $TAG_PREFIX-minsize-webgl2 -m "[Automated workflow] Created by upgrade-unity"
187-
fi
188-
# Push tags in between - pushing more than 3 tags won't trigger tag workflows
189-
git push origin -f --tags
190-
191-
git tag -a -f $TAG_PREFIX-webgl2 -m "[Automated workflow] Created by upgrade-unity"
192-
git tag -a -f $TAG_PREFIX-webgl2-debug -m "[Automated workflow] Created by upgrade-unity"
193-
194-
git push origin -f --tags
178+
# Run add tags script
179+
./.github/scripts/add-tags.sh "$UNITY_VERSION" "$IS_URP"
195180
env:
196181
UNITY_VERSION: ${{ inputs.unityVersion }}
197182

Assets/Plugins/WebGL/WebBridge/WebBridge.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ private static void SetGlobalVariables()
8585
}
8686
WebToolPlugins.SetVariable("webGlVersion", webGraphics);
8787
WebToolPlugins.SetVariable("unityVersion", Application.unityVersion);
88+
WebToolPlugins.SetVariable("applicationVersion", Application.version);
8889
#if !UNITY_EDITOR && UNITY_WEBGL
8990
WebToolPlugins.SetVariable("unityCaptureAllKeyboardInputDefault", WebGLInput.captureAllKeyboardInput?"true":"false");
9091
#endif

Assets/Scripts/Editor/BuildScript.cs

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
using System.Linq;
1515
using JetBrains.Annotations;
1616
using UnityEditor;
17+
using UnityEditor.Build;
1718
using UnityEditor.Build.Reporting;
19+
using UnityEditor.Compilation;
1820
using UnityEngine;
1921
using UnityEngine.Rendering;
2022

@@ -31,6 +33,25 @@ public static class BuildScript
3133
private static readonly string Eol = Environment.NewLine;
3234
private static bool LogVerboseBatchMode = true;
3335
private static bool LogVerboseInEditor = false;
36+
private static readonly string CodeOptimizationSpeed =
37+
#if UNITY_2021_3_OR_NEWER
38+
CodeOptimizationWebGL.RuntimeSpeedLTO.ToString();
39+
#else
40+
"speed";
41+
#endif
42+
private static readonly string CodeOptimizationSize =
43+
#if UNITY_2021_3_OR_NEWER
44+
CodeOptimizationWebGL.DiskSizeLTO.ToString();
45+
#else
46+
"size";
47+
#endif
48+
49+
private static readonly string CodeOptimizationBuildTimes =
50+
#if UNITY_2021_3_OR_NEWER
51+
CodeOptimizationWebGL.BuildTimes.ToString();
52+
#else
53+
"size";
54+
#endif
3455

3556
private static readonly string[] Secrets =
3657
{ "androidKeystorePass", "androidKeyaliasName", "androidKeyaliasPass" };
@@ -51,10 +72,16 @@ public static void Build(string[] args)
5172
// Gather values from args
5273
Dictionary<string, string> options = GetValidatedOptions(args);
5374

54-
// Set version for this build
55-
PlayerSettings.bundleVersion = options["buildVersion"];
56-
PlayerSettings.macOS.buildNumber = options["buildVersion"];
57-
PlayerSettings.Android.bundleVersionCode = int.Parse(options["androidVersionCode"]);
75+
// Set version for this build if provided
76+
if(options.TryGetValue("buildVersion", out string buildVersion) && buildVersion != "none")
77+
{
78+
PlayerSettings.bundleVersion = buildVersion;
79+
PlayerSettings.macOS.buildNumber = buildVersion;
80+
}
81+
if(options.TryGetValue("androidVersionCode", out string versionCode) && versionCode != "0")
82+
{
83+
PlayerSettings.Android.bundleVersionCode = int.Parse(options["androidVersionCode"]);
84+
}
5885

5986
// Apply build target
6087
var buildTarget = (BuildTarget)Enum.Parse(typeof(BuildTarget), options["buildTarget"]);
@@ -84,6 +111,7 @@ public static void Build(string[] args)
84111
#if UNITY_2021_2_OR_NEWER
85112
// Use ASTC texture compression, since we are also targeting mobile versions - Don't use this for desktop only targets
86113
buildPlayerOptions.subtarget = (int)WebGLTextureSubtarget.ASTC;
114+
var namedBuildTarget = NamedBuildTarget.WebGL;
87115
#endif
88116

89117
if (options.TryGetValue("tag", out string tagVersion) &&
@@ -93,16 +121,23 @@ public static void Build(string[] args)
93121
if (tagParameters.Contains("minsize"))
94122
{
95123
PlayerSettings.WebGL.template = "PROJECT:Release";
96-
SetWebGlOptimization("size");
124+
SetWebGlOptimization(CodeOptimizationSize);
125+
buildPlayerOptions.options |= BuildOptions.CompressWithLz4HC;
97126
PlayerSettings.WebGL.exceptionSupport = WebGLExceptionSupport.None;
98127
PlayerSettings.SetIl2CppCompilerConfiguration(BuildTargetGroup.WebGL, Il2CppCompilerConfiguration.Master);
128+
#if UNITY_2022_1_OR_NEWER
129+
PlayerSettings.SetIl2CppCodeGeneration(namedBuildTarget, Il2CppCodeGeneration.OptimizeSize);
130+
#endif
99131
}
100132
else if (tagParameters.Contains("debug"))
101133
{
102134
PlayerSettings.WebGL.template = "PROJECT:Develop";
103-
SetWebGlOptimization("size");
104135
PlayerSettings.WebGL.exceptionSupport = WebGLExceptionSupport.FullWithStacktrace;
105136
PlayerSettings.SetIl2CppCompilerConfiguration(BuildTargetGroup.WebGL, Il2CppCompilerConfiguration.Debug);
137+
SetWebGlOptimization(CodeOptimizationBuildTimes);
138+
#if UNITY_2022_1_OR_NEWER
139+
PlayerSettings.SetIl2CppCodeGeneration(namedBuildTarget, Il2CppCodeGeneration.OptimizeSize);
140+
#endif
106141
#if UNITY_2021_2_OR_NEWER
107142
PlayerSettings.WebGL.debugSymbolMode = WebGLDebugSymbolMode.Embedded;
108143
#else
@@ -117,8 +152,12 @@ public static void Build(string[] args)
117152
else
118153
{
119154
PlayerSettings.WebGL.template = "PROJECT:Develop";
155+
PlayerSettings.SetIl2CppCompilerConfiguration(BuildTargetGroup.WebGL, Il2CppCompilerConfiguration.Master);
120156
// By default use the speed setting
121-
SetWebGlOptimization("speed");
157+
SetWebGlOptimization(CodeOptimizationSpeed);
158+
#if UNITY_2022_1_OR_NEWER
159+
PlayerSettings.SetIl2CppCodeGeneration(namedBuildTarget, Il2CppCodeGeneration.OptimizeSpeed);
160+
#endif
122161
}
123162

124163
List<GraphicsDeviceType> graphicsAPIs = new List<GraphicsDeviceType>();
@@ -155,7 +194,7 @@ public static void Build(string[] args)
155194
// Additional options for local builds
156195
if (!Application.isBatchMode)
157196
{
158-
if (options.TryGetValue("autorunplayer", out string autorunplayer))
197+
if (options.TryGetValue("autorunplayer", out string _))
159198
{
160199
buildPlayerOptions.options |= BuildOptions.AutoRunPlayer;
161200
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// --------------------------------------------------------------------------------------------------------------------
2+
// <copyright file="BuildScript.cs">
3+
// Copyright (c) 2023 Johannes Deml. All rights reserved.
4+
// </copyright>
5+
// <author>
6+
// Johannes Deml
7+
// public@deml.io
8+
// </author>
9+
// --------------------------------------------------------------------------------------------------------------------
10+
11+
namespace UnityBuilderAction
12+
{
13+
/// <summary>
14+
/// Code optimization settings for the build
15+
/// See also <see href="https://forum.unity.com/threads/webgl-build-code-optimization-option.1058441/#post-9818385" />
16+
/// </summary>
17+
enum CodeOptimizationWebGL
18+
{
19+
BuildTimes,
20+
RuntimeSpeed,
21+
RuntimeSpeedLTO,
22+
DiskSize,
23+
DiskSizeLTO,
24+
}
25+
}

Assets/Scripts/Editor/CodeOptimizationWebGL.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/WebGLTemplates/Develop/debug-console.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -553,9 +553,9 @@ function getInfoPanel() {
553553
infoPanel.id = 'infoPanel';
554554
document.body.appendChild(infoPanel);
555555
var infoHeader = document.createElement('h3');
556-
if (typeof unityVersion != `undefined` && typeof webGlVersion != `undefined`) {
556+
if (typeof unityVersion != `undefined` && typeof applicationVersion != `undefined` && typeof webGlVersion != `undefined`) {
557557
// Set by WebGlBridge in Unity
558-
infoHeader.textContent = `Unity ${unityVersion} (${webGlVersion})`;
558+
infoHeader.textContent = `Unity ${unityVersion}@${applicationVersion} (${webGlVersion})`;
559559
} else {
560560
infoHeader.textContent = `Unity InfoPanel`;
561561
}

Assets/WebGLTemplates/Develop/index.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
<head>
55
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<link rel="stylesheet" href="debug-console.css">
8+
<!-- Start loading assets right away, to have them (partly) loaded already when they are requested -->
9+
<link rel="preload" href="Build//{{{ DATA_FILENAME }}}" as="fetch" type="application/octet-stream" crossorigin>
10+
<link rel="preload" href="Build/{{{ FRAMEWORK_FILENAME }}}" as="script">
11+
<link rel="preload" href="Build/{{{ CODE_FILENAME }}}" as="fetch" type="application/wasm" crossorigin>
712
<title>{{{ PRODUCT_NAME }}}</title>
813
<style>
914
* {
@@ -113,7 +118,6 @@
113118
transition: 400ms linear;
114119
}
115120
</style>
116-
<link rel="stylesheet" href="debug-console.css">
117121
</head>
118122

119123
<body>

0 commit comments

Comments
 (0)