Skip to content

Commit

Permalink
Merge branch 'master' into 2023.2-urp
Browse files Browse the repository at this point in the history
# Conflicts:
#	ProjectSettings/ProjectSettings.asset
  • Loading branch information
JohannesDeml committed Jul 8, 2024
2 parents e9ebcfa + 30e821b commit f52daa0
Show file tree
Hide file tree
Showing 12 changed files with 166 additions and 40 deletions.
40 changes: 40 additions & 0 deletions .github/scripts/add-tags.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash
# This script creates tags for the given unity version to trigger the release workflow
# example usage
# sh add-tags.sh "6000.0.0f1" -> Creates tags for non-urp version
# sh add-tags.sh "6000.0.0f1" "true" -> Creates tags for urp version

# Input parameters
UNITY_VERSION=$1
IS_URP=${2:-"false"}
echo "Running add_tags.sh with UNITY_VERSION: $UNITY_VERSION, IS_URP: $IS_URP"

# Extract the value before the first dot as an integer
MAJOR_VERSION=$(echo $UNITY_VERSION | cut -d. -f1)
BRANCH_NAME=${GITHUB_REF#refs/heads/}

TAG_PREFIX=$UNITY_VERSION
if [[ "$IS_URP" == "true" ]]
then
TAG_PREFIX=$UNITY_VERSION-urp
fi

if [[ "$MAJOR_VERSION" -lt "2023" ]]
then
git tag -a -f $TAG_PREFIX-minsize-webgl1 -m "[Automated workflow] Created by upgrade-unity"
git tag -a -f $TAG_PREFIX-webgl1 -m "[Automated workflow] Created by upgrade-unity"
else
git tag -a -f $TAG_PREFIX-minsize-webgl2 -m "[Automated workflow] Created by upgrade-unity"
fi
# Push tags in between - pushing more than 3 tags won't trigger tag workflows
git push origin -f --tags

git tag -a -f $TAG_PREFIX-webgl2 -m "[Automated workflow] Created by upgrade-unity"
git tag -a -f $TAG_PREFIX-webgl2-debug -m "[Automated workflow] Created by upgrade-unity"

if [[ "$MAJOR_VERSION" -ge "6000" ]]
then
git tag -a -f $TAG_PREFIX-webgpu -m "[Automated workflow] Created by upgrade-unity"
fi

git push origin -f --tags
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ jobs:
buildMethod: UnityBuilderAction.BuildScript.BuildWithCommandlineArgs
customParameters: -tag ${{ needs.variables.outputs.TAG }}
targetPlatform: WebGL
versioning: None
buildName: ${{ needs.variables.outputs.BUILD_NAME }}

- uses: actions/upload-artifact@v4
Expand Down
27 changes: 6 additions & 21 deletions .github/workflows/upgrade-unity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ jobs:
customParameters: ${{ inputs.customParameters }}
unityVersion: ${{ inputs.unityVersion }}
targetPlatform: WebGL
buildName: ${{ needs.variables.outputs.BUILD_NAME }}
buildName: ${{ steps.upgrade_name.outputs.NAME }}
allowDirtyBuild: true
manualExit: true

Expand Down Expand Up @@ -168,30 +168,15 @@ jobs:
- name: Add tags
if: ${{ inputs.createTags || inputs.tagsOnly }}
run: |
# Extract the first four characters of UNITY_VERSION
UNITY_YEAR=${UNITY_VERSION:0:4}
BRANCH_NAME=${GITHUB_REF#refs/heads/}
TAG_PREFIX=$UNITY_VERSION
if [[ "$BRANCH_NAME" == *"urp"* ]]
then
TAG_PREFIX=$UNITY_VERSION-urp
IS_URP=false
if [[ "$BRANCH_NAME" == *"urp"* ]]; then
IS_URP=true
fi
if [[ "$UNITY_YEAR" < "2023" ]]
then
git tag -a -f $TAG_PREFIX-minsize-webgl1 -m "[Automated workflow] Created by upgrade-unity"
git tag -a -f $TAG_PREFIX-webgl1 -m "[Automated workflow] Created by upgrade-unity"
else
git tag -a -f $TAG_PREFIX-minsize-webgl2 -m "[Automated workflow] Created by upgrade-unity"
fi
# Push tags in between - pushing more than 3 tags won't trigger tag workflows
git push origin -f --tags
git tag -a -f $TAG_PREFIX-webgl2 -m "[Automated workflow] Created by upgrade-unity"
git tag -a -f $TAG_PREFIX-webgl2-debug -m "[Automated workflow] Created by upgrade-unity"
git push origin -f --tags
# Run add tags script
./.github/scripts/add-tags.sh "$UNITY_VERSION" "$IS_URP"
env:
UNITY_VERSION: ${{ inputs.unityVersion }}

1 change: 1 addition & 0 deletions Assets/Plugins/WebGL/WebBridge/WebBridge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ private static void SetGlobalVariables()
}
WebToolPlugins.SetVariable("webGlVersion", webGraphics);
WebToolPlugins.SetVariable("unityVersion", Application.unityVersion);
WebToolPlugins.SetVariable("applicationVersion", Application.version);
#if !UNITY_EDITOR && UNITY_WEBGL
WebToolPlugins.SetVariable("unityCaptureAllKeyboardInputDefault", WebGLInput.captureAllKeyboardInput?"true":"false");
#endif
Expand Down
55 changes: 47 additions & 8 deletions Assets/Scripts/Editor/BuildScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
using System.Linq;
using JetBrains.Annotations;
using UnityEditor;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
using UnityEditor.Compilation;
using UnityEngine;
using UnityEngine.Rendering;

Expand All @@ -31,6 +33,25 @@ public static class BuildScript
private static readonly string Eol = Environment.NewLine;
private static bool LogVerboseBatchMode = true;
private static bool LogVerboseInEditor = false;
private static readonly string CodeOptimizationSpeed =
#if UNITY_2021_3_OR_NEWER
CodeOptimizationWebGL.RuntimeSpeedLTO.ToString();
#else
"speed";
#endif
private static readonly string CodeOptimizationSize =
#if UNITY_2021_3_OR_NEWER
CodeOptimizationWebGL.DiskSizeLTO.ToString();
#else
"size";
#endif

private static readonly string CodeOptimizationBuildTimes =
#if UNITY_2021_3_OR_NEWER
CodeOptimizationWebGL.BuildTimes.ToString();
#else
"size";
#endif

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

// Set version for this build
PlayerSettings.bundleVersion = options["buildVersion"];
PlayerSettings.macOS.buildNumber = options["buildVersion"];
PlayerSettings.Android.bundleVersionCode = int.Parse(options["androidVersionCode"]);
// Set version for this build if provided
if(options.TryGetValue("buildVersion", out string buildVersion) && buildVersion != "none")
{
PlayerSettings.bundleVersion = buildVersion;
PlayerSettings.macOS.buildNumber = buildVersion;
}
if(options.TryGetValue("androidVersionCode", out string versionCode) && versionCode != "0")
{
PlayerSettings.Android.bundleVersionCode = int.Parse(options["androidVersionCode"]);
}

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

if (options.TryGetValue("tag", out string tagVersion) &&
Expand All @@ -93,16 +121,23 @@ public static void Build(string[] args)
if (tagParameters.Contains("minsize"))
{
PlayerSettings.WebGL.template = "PROJECT:Release";
SetWebGlOptimization("size");
SetWebGlOptimization(CodeOptimizationSize);
buildPlayerOptions.options |= BuildOptions.CompressWithLz4HC;
PlayerSettings.WebGL.exceptionSupport = WebGLExceptionSupport.None;
PlayerSettings.SetIl2CppCompilerConfiguration(BuildTargetGroup.WebGL, Il2CppCompilerConfiguration.Master);
#if UNITY_2022_1_OR_NEWER
PlayerSettings.SetIl2CppCodeGeneration(namedBuildTarget, Il2CppCodeGeneration.OptimizeSize);
#endif
}
else if (tagParameters.Contains("debug"))
{
PlayerSettings.WebGL.template = "PROJECT:Develop";
SetWebGlOptimization("size");
PlayerSettings.WebGL.exceptionSupport = WebGLExceptionSupport.FullWithStacktrace;
PlayerSettings.SetIl2CppCompilerConfiguration(BuildTargetGroup.WebGL, Il2CppCompilerConfiguration.Debug);
SetWebGlOptimization(CodeOptimizationBuildTimes);
#if UNITY_2022_1_OR_NEWER
PlayerSettings.SetIl2CppCodeGeneration(namedBuildTarget, Il2CppCodeGeneration.OptimizeSize);
#endif
#if UNITY_2021_2_OR_NEWER
PlayerSettings.WebGL.debugSymbolMode = WebGLDebugSymbolMode.Embedded;
#else
Expand All @@ -117,8 +152,12 @@ public static void Build(string[] args)
else
{
PlayerSettings.WebGL.template = "PROJECT:Develop";
PlayerSettings.SetIl2CppCompilerConfiguration(BuildTargetGroup.WebGL, Il2CppCompilerConfiguration.Master);
// By default use the speed setting
SetWebGlOptimization("speed");
SetWebGlOptimization(CodeOptimizationSpeed);
#if UNITY_2022_1_OR_NEWER
PlayerSettings.SetIl2CppCodeGeneration(namedBuildTarget, Il2CppCodeGeneration.OptimizeSpeed);
#endif
}

List<GraphicsDeviceType> graphicsAPIs = new List<GraphicsDeviceType>();
Expand Down Expand Up @@ -155,7 +194,7 @@ public static void Build(string[] args)
// Additional options for local builds
if (!Application.isBatchMode)
{
if (options.TryGetValue("autorunplayer", out string autorunplayer))
if (options.TryGetValue("autorunplayer", out string _))
{
buildPlayerOptions.options |= BuildOptions.AutoRunPlayer;
}
Expand Down
25 changes: 25 additions & 0 deletions Assets/Scripts/Editor/CodeOptimizationWebGL.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="BuildScript.cs">
// Copyright (c) 2023 Johannes Deml. All rights reserved.
// </copyright>
// <author>
// Johannes Deml
// [email protected]
// </author>
// --------------------------------------------------------------------------------------------------------------------

namespace UnityBuilderAction
{
/// <summary>
/// Code optimization settings for the build
/// See also <see href="https://forum.unity.com/threads/webgl-build-code-optimization-option.1058441/#post-9818385" />
/// </summary>
enum CodeOptimizationWebGL
{
BuildTimes,
RuntimeSpeed,
RuntimeSpeedLTO,
DiskSize,
DiskSizeLTO,
}
}
11 changes: 11 additions & 0 deletions Assets/Scripts/Editor/CodeOptimizationWebGL.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Assets/WebGLTemplates/Develop/debug-console.js
Original file line number Diff line number Diff line change
Expand Up @@ -553,9 +553,9 @@ function getInfoPanel() {
infoPanel.id = 'infoPanel';
document.body.appendChild(infoPanel);
var infoHeader = document.createElement('h3');
if (typeof unityVersion != `undefined` && typeof webGlVersion != `undefined`) {
if (typeof unityVersion != `undefined` && typeof applicationVersion != `undefined` && typeof webGlVersion != `undefined`) {
// Set by WebGlBridge in Unity
infoHeader.textContent = `Unity ${unityVersion} (${webGlVersion})`;
infoHeader.textContent = `Unity ${unityVersion}@${applicationVersion} (${webGlVersion})`;
} else {
infoHeader.textContent = `Unity InfoPanel`;
}
Expand Down
6 changes: 5 additions & 1 deletion Assets/WebGLTemplates/Develop/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="debug-console.css">
<!-- Start loading assets right away, to have them (partly) loaded already when they are requested -->
<link rel="preload" href="Build//{{{ DATA_FILENAME }}}" as="fetch" type="application/octet-stream" crossorigin>
<link rel="preload" href="Build/{{{ FRAMEWORK_FILENAME }}}" as="script">
<link rel="preload" href="Build/{{{ CODE_FILENAME }}}" as="fetch" type="application/wasm" crossorigin>
<title>{{{ PRODUCT_NAME }}}</title>
<style>
* {
Expand Down Expand Up @@ -113,7 +118,6 @@
transition: 400ms linear;
}
</style>
<link rel="stylesheet" href="debug-console.css">
</head>

<body>
Expand Down
4 changes: 4 additions & 0 deletions Assets/WebGLTemplates/Release/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Start loading assets right away, to have them (partly) loaded already when they are requested -->
<link rel="preload" href="Build//{{{ DATA_FILENAME }}}" as="fetch" type="application/octet-stream" crossorigin>
<link rel="preload" href="Build/{{{ FRAMEWORK_FILENAME }}}" as="script">
<link rel="preload" href="Build/{{{ CODE_FILENAME }}}" as="fetch" type="application/wasm" crossorigin>
<title>{{{ PRODUCT_NAME }}}</title>
<style>
* {
Expand Down
Loading

0 comments on commit f52daa0

Please sign in to comment.