diff --git a/.github/scripts/add-tags.sh b/.github/scripts/add-tags.sh new file mode 100755 index 00000000..62490e6b --- /dev/null +++ b/.github/scripts/add-tags.sh @@ -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 \ No newline at end of file diff --git a/.github/workflows/activation.yml b/.github/workflows/activation.yml deleted file mode 100644 index a8fe6c2a..00000000 --- a/.github/workflows/activation.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: Get Unity license activation file ๐Ÿ”‘ - -on: - workflow_dispatch: {} -jobs: - activation: - name: Request manual activation file ๐Ÿ”‘ - runs-on: ubuntu-latest - steps: - # Request manual activation file - - name: Request manual activation file - id: getManualLicenseFile - uses: game-ci/unity-request-activation-file@v2 - # Upload artifact (Unity_v20XX.X.XXXX.alf) - - name: Expose as artifact - uses: actions/upload-artifact@v2 - with: - name: ${{ steps.getManualLicenseFile.outputs.filePath }} - path: ${{ steps.getManualLicenseFile.outputs.filePath }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ef1f5dba..9139e86a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -77,7 +77,7 @@ jobs: # Unity 2020 cache is not compatible with older versions - name: Unity Library Cache 2020 or higher if: ${{ !startsWith(needs.variables.outputs.UNITY_VERSION, '201') }} - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: Library key: Library-202x-WebGL @@ -85,7 +85,7 @@ jobs: - name: Unity Library Cache 2019 or lower if: ${{ startsWith(needs.variables.outputs.UNITY_VERSION, '201') }} - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: Library key: Library-201x-WebGL @@ -101,9 +101,10 @@ 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@v3 + - uses: actions/upload-artifact@v4 with: name: ${{ needs.variables.outputs.BUILD_NAME }} path: build/WebGL @@ -116,7 +117,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Create Release - uses: softprops/action-gh-release@v1 + uses: softprops/action-gh-release@v2 with: body: | ## Changes @@ -140,7 +141,7 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: name: ${{ needs.variables.outputs.BUILD_NAME }} path: build @@ -150,7 +151,7 @@ jobs: working-directory: build/${{ needs.variables.outputs.BUILD_NAME }} - name: Deploy โคด - uses: SamKirkland/FTP-Deploy-Action@4.3.3 + uses: SamKirkland/FTP-Deploy-Action@v4.3.5 with: server: ${{ secrets.FTP_SERVER }} username: ${{ secrets.FTP_USER }} diff --git a/.github/workflows/upgrade-unity.yml b/.github/workflows/upgrade-unity.yml index 4df3764e..79bbf034 100644 --- a/.github/workflows/upgrade-unity.yml +++ b/.github/workflows/upgrade-unity.yml @@ -87,7 +87,7 @@ jobs: # Unity 2020 cache is not compatible with older versions - name: Unity Library Cache 2020 or higher if: ${{ !startsWith(inputs.unityVersion, '201') }} - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: Library key: Library-202x-WebGL @@ -95,7 +95,7 @@ jobs: - name: Unity Library Cache 2019 or lower if: ${{ startsWith(inputs.unityVersion, '201') }} - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: Library key: Library-201x-WebGL @@ -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 @@ -148,7 +148,7 @@ jobs: - name: Render template if: ${{ !inputs.tagsOnly }} id: template - uses: chuhlomin/render-template@v1.4 + uses: chuhlomin/render-template@v1.9 with: template: .github/templates/upgrade-unity-pr-body.md vars: | @@ -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 }} diff --git a/Assets/Plugins/WebGL/WebBridge/WebBridge.cs b/Assets/Plugins/WebGL/WebBridge/WebBridge.cs index b41ff0fc..0bca0b6a 100644 --- a/Assets/Plugins/WebGL/WebBridge/WebBridge.cs +++ b/Assets/Plugins/WebGL/WebBridge/WebBridge.cs @@ -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 diff --git a/Assets/Scripts/Editor/BuildScript.cs b/Assets/Scripts/Editor/BuildScript.cs index 97abfb4e..8de8cbd1 100644 --- a/Assets/Scripts/Editor/BuildScript.cs +++ b/Assets/Scripts/Editor/BuildScript.cs @@ -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; @@ -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" }; @@ -51,10 +72,16 @@ public static void Build(string[] args) // Gather values from args Dictionary 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"]); @@ -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) && @@ -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 @@ -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 graphicsAPIs = new List(); @@ -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; } diff --git a/Assets/Scripts/Editor/CodeOptimizationWebGL.cs b/Assets/Scripts/Editor/CodeOptimizationWebGL.cs new file mode 100644 index 00000000..2e1e1134 --- /dev/null +++ b/Assets/Scripts/Editor/CodeOptimizationWebGL.cs @@ -0,0 +1,25 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2023 Johannes Deml. All rights reserved. +// +// +// Johannes Deml +// public@deml.io +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace UnityBuilderAction +{ + /// + /// Code optimization settings for the build + /// See also + /// + enum CodeOptimizationWebGL + { + BuildTimes, + RuntimeSpeed, + RuntimeSpeedLTO, + DiskSize, + DiskSizeLTO, + } +} \ No newline at end of file diff --git a/Assets/Scripts/Editor/CodeOptimizationWebGL.cs.meta b/Assets/Scripts/Editor/CodeOptimizationWebGL.cs.meta new file mode 100644 index 00000000..3d55b414 --- /dev/null +++ b/Assets/Scripts/Editor/CodeOptimizationWebGL.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 608e5ffaef00e024e85cf171fa639a91 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/WebGLTemplates/Develop/debug-console.js b/Assets/WebGLTemplates/Develop/debug-console.js index 06549bf2..00294efc 100644 --- a/Assets/WebGLTemplates/Develop/debug-console.js +++ b/Assets/WebGLTemplates/Develop/debug-console.js @@ -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`; } diff --git a/Assets/WebGLTemplates/Develop/index.html b/Assets/WebGLTemplates/Develop/index.html index e28a13b1..d0583e2f 100644 --- a/Assets/WebGLTemplates/Develop/index.html +++ b/Assets/WebGLTemplates/Develop/index.html @@ -4,6 +4,11 @@ + + + + + {{{ PRODUCT_NAME }}} - diff --git a/Assets/WebGLTemplates/Release/index.html b/Assets/WebGLTemplates/Release/index.html index 38ef3e38..cdd784ae 100644 --- a/Assets/WebGLTemplates/Release/index.html +++ b/Assets/WebGLTemplates/Release/index.html @@ -4,6 +4,10 @@ + + + + {{{ PRODUCT_NAME }}}