Skip to content

Commit f79334d

Browse files
committed
Merge branch 'master' into 2023.2-urp
# Conflicts: # Packages/manifest.json # Packages/packages-lock.json # ProjectSettings/ProjectSettings.asset # ProjectSettings/ProjectVersion.txt
2 parents e9d4e2d + 0cf2bed commit f79334d

File tree

20 files changed

+427
-85
lines changed

20 files changed

+427
-85
lines changed

.github/scripts/add-tags.sh

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
# example usage
44
# sh add-tags.sh "6000.0.0f1" -> Creates tags for non-urp version
55
# sh add-tags.sh "6000.0.0f1" "true" -> Creates tags for urp version
6+
# sh add-tags.sh "6000.0.0f1" "true" "10" -> Creates tags for urp version with 10 second delay between pushes
67

78
# Input parameters
89
UNITY_VERSION=$1
910
IS_URP=${2:-"false"}
10-
echo "Running add_tags.sh with UNITY_VERSION: $UNITY_VERSION, IS_URP: $IS_URP"
11+
DELAY_TAGS=${3:-"0"}
12+
13+
echo "Running add_tags.sh with UNITY_VERSION: $UNITY_VERSION, IS_URP: $IS_URP, DELAY_TAGS: $DELAY_TAGS seconds"
1114

1215
# Extract the value before the first dot as an integer
1316
MAJOR_VERSION=$(echo $UNITY_VERSION | cut -d. -f1)
@@ -19,22 +22,42 @@ then
1922
TAG_PREFIX=$UNITY_VERSION-urp
2023
fi
2124

25+
# Build array of tags to create and push
26+
TAGS=()
27+
2228
if [[ "$MAJOR_VERSION" -lt "2023" ]]
2329
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"
30+
TAGS+=("$TAG_PREFIX-minsize-webgl1")
31+
TAGS+=("$TAG_PREFIX-webgl1")
2632
else
27-
git tag -a -f $TAG_PREFIX-minsize-webgl2 -m "[Automated workflow] Created by upgrade-unity"
33+
TAGS+=("$TAG_PREFIX-minsize-webgl2")
2834
fi
29-
# Push tags in between - pushing more than 3 tags won't trigger tag workflows
30-
git push origin -f --tags
3135

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"
36+
TAGS+=("$TAG_PREFIX-webgl2")
37+
TAGS+=("$TAG_PREFIX-webgl2-debug")
3438

3539
if [[ "$MAJOR_VERSION" -ge "6000" ]]
3640
then
37-
git tag -a -f $TAG_PREFIX-webgpu -m "[Automated workflow] Created by upgrade-unity"
41+
TAGS+=("$TAG_PREFIX-webgpu")
3842
fi
3943

40-
git push origin -f --tags
44+
# Loop through tags, create and push each one with delay
45+
for i in "${!TAGS[@]}"; do
46+
TAG="${TAGS[$i]}"
47+
echo "Creating and pushing tag: $TAG"
48+
49+
# Create the tag
50+
git tag -a -f "$TAG" -m "[Automated workflow] Created by upgrade-unity"
51+
52+
# Push the tag
53+
git push origin -f "$TAG"
54+
55+
# Wait between pushes if not the last tag and delay is specified
56+
if [[ $i -lt $((${#TAGS[@]} - 1)) ]] && [[ "$DELAY_TAGS" -gt "0" ]]
57+
then
58+
echo "Waiting $DELAY_TAGS seconds before next tag push..."
59+
sleep $DELAY_TAGS
60+
fi
61+
done
62+
63+
echo "All tags created and pushed successfully."

.github/templates/upgrade-unity-pr-body.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
### Built version demos
66

77
* https://deml.io/experiments/unity-webgl/{{ .unityversion }}-webgl2
8-
* https://deml.io/experiments/unity-webgl/{{ .unityversion }}-webgl1
8+
* https://deml.io/experiments/unity-webgl/{{ .unityversion }}-webgl2-debug
9+
* https://deml.io/experiments/unity-webgl/{{ .unityversion }}-minsize-webgl2
910

1011
### Other links
1112

.github/workflows/release.yml

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,24 @@ jobs:
7373
if: ${{ github.ref == 'refs/heads/master' || needs.variables.outputs.TAG != needs.variables.outputs.UNITY_VERSION }}
7474
needs: [ variables ]
7575
runs-on: ubuntu-latest
76-
strategy:
77-
fail-fast: false
7876
steps:
7977
- uses: actions/checkout@v4
8078
with:
8179
fetch-depth: 0
8280
lfs: true
8381

82+
# Avoid running into space issues for github runners - Docker images can take up quite some space
83+
- name: Free Disk Space
84+
run: |
85+
echo "Disk space before cleanup:"
86+
df -h
87+
sudo rm -rf /usr/share/dotnet
88+
sudo rm -rf /opt/ghc
89+
sudo rm -rf /usr/local/share/boost
90+
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
91+
echo "Disk space after cleanup:"
92+
df -h
93+
8494
# Unity 2020 cache is not compatible with older versions
8595
- name: Unity Library Cache 2020 or higher
8696
if: ${{ !startsWith(needs.variables.outputs.UNITY_VERSION, '201') }}
@@ -111,6 +121,17 @@ jobs:
111121
versioning: None
112122
buildName: ${{ needs.variables.outputs.BUILD_NAME }}
113123

124+
- name: Check Disk Space After Build
125+
run: |
126+
echo "Disk space after build:"
127+
df -h
128+
AVAILABLE=$(df / | tail -1 | awk '{print $4}')
129+
AVAILABLE_GB=$(echo $AVAILABLE | sed 's/G//')
130+
echo "Available space: ${AVAILABLE_GB}GB"
131+
if (( $(echo "$AVAILABLE_GB < 1" | bc -l) )); then
132+
echo "::warning::Low disk space! Less than 1GB remaining."
133+
fi
134+
114135
- uses: actions/upload-artifact@v4
115136
with:
116137
name: ${{ needs.variables.outputs.BUILD_NAME }}

.github/workflows/upgrade-unity.yml

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,16 @@ on:
2929
required: false
3030
type: string
3131
default: '-accept-apiupdate'
32+
delayTags:
33+
description: 'Delay between tag pushes (in seconds, minimum 1)'
34+
required: false
35+
type: number
36+
default: 1
3237

3338
jobs:
3439
upgrade-unity-version:
3540
name: Upgrade Unity version and packages to ${{ inputs.unityVersion }}
3641
runs-on: ubuntu-latest
37-
strategy:
38-
fail-fast: false
3942
steps:
4043
- name: Log input parameter
4144
run: |
@@ -47,6 +50,7 @@ jobs:
4750
echo "Only create tags: $TAGS_ONLY"
4851
echo "Merge master into branch: $MERGE_MASTER"
4952
echo "Custom cli arguments: $CUSTOM_PARAMETERS"
53+
echo "Delay tags: $DELAY_TAGS seconds"
5054
if [[ "$BRANCH_NAME" == *"urp"* ]]
5155
then
5256
echo "urp: true"
@@ -59,6 +63,7 @@ jobs:
5963
TAGS_ONLY: ${{ inputs.tagsOnly }}
6064
MERGE_MASTER: ${{ inputs.mergeMaster }}
6165
CUSTOM_PARAMETERS: ${{ inputs.customParameters }}
66+
DELAY_TAGS: ${{ inputs.delayTags }}
6267

6368
- uses: actions/checkout@v4
6469
with:
@@ -75,6 +80,18 @@ jobs:
7580
env:
7681
GIT_USER: ${{ github.actor }}
7782

83+
# Avoid running into space issues for github runners - Docker images can take up quite some space
84+
- name: Free Disk Space
85+
run: |
86+
echo "Disk space before cleanup:"
87+
df -h
88+
sudo rm -rf /usr/share/dotnet
89+
sudo rm -rf /opt/ghc
90+
sudo rm -rf /usr/local/share/boost
91+
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
92+
echo "Disk space after cleanup:"
93+
df -h
94+
7895
# Make sure the branch has the latest master changes in
7996
- name: Merge master into current branch
8097
if: ${{ inputs.mergeMaster }}
@@ -149,6 +166,18 @@ jobs:
149166
allowDirtyBuild: true
150167
manualExit: true
151168

169+
- name: Check Disk Space After Build
170+
if: ${{ !inputs.tagsOnly }}
171+
run: |
172+
echo "Disk space after build:"
173+
df -h
174+
AVAILABLE=$(df / | tail -1 | awk '{print $4}')
175+
AVAILABLE_GB=$(echo $AVAILABLE | sed 's/G//')
176+
echo "Available space: ${AVAILABLE_GB}GB"
177+
if (( $(echo "$AVAILABLE_GB < 1" | bc -l) )); then
178+
echo "::warning::Low disk space! Less than 1GB remaining."
179+
fi
180+
152181
- name: Delete build folder with elevated rights
153182
if: ${{ !inputs.tagsOnly }}
154183
run: sudo rm -rf ./build
@@ -183,8 +212,9 @@ jobs:
183212
IS_URP=true
184213
fi
185214
186-
# Run add tags script
187-
./.github/scripts/add-tags.sh "$UNITY_VERSION" "$IS_URP"
215+
# Run add tags script with delay parameter
216+
./.github/scripts/add-tags.sh "$UNITY_VERSION" "$IS_URP" "$DELAY_TAGS"
188217
env:
189218
UNITY_VERSION: ${{ inputs.unityVersion }}
219+
DELAY_TAGS: ${{ inputs.delayTags }}
190220

Assets/Plugins/WebGL/WebBridge/CommonCommands.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,25 @@ public void LogMemory()
6666
WebToolPlugins.LogMemory();
6767
}
6868

69+
/// <summary>
70+
/// Logs the rough device memory capped between 0.25 and 8 GB
71+
/// Browser Usage: <code>unityGame.SendMessage("WebGL","LogDeviceMemory");</code>
72+
/// </summary>
73+
[WebCommand(Description = "Logs the device memory")]
74+
[ContextMenu(nameof(LogDeviceMemory))]
75+
public void LogDeviceMemory()
76+
{
77+
float deviceMemoryInMb = WebToolPlugins.GetDeviceMemory();
78+
if (deviceMemoryInMb > 0)
79+
{
80+
Debug.Log($"Device Memory: {deviceMemoryInMb} GB");
81+
}
82+
else
83+
{
84+
Debug.Log("Device Memory information is not available on this device or browser.");
85+
}
86+
}
87+
6988
/// <summary>
7089
/// Allocate memory to test memory usage and limits
7190
/// The memory will be stored in a list to prevent it from being garbage collected
@@ -192,7 +211,11 @@ public void LogInitializationTime()
192211
[WebCommand(Description = "Find GameObject by name and log its components")]
193212
public void FindGameObjectByName(string name)
194213
{
214+
#if UNITY_6000_0_OR_NEWER
215+
var gameObjects = GameObject.FindObjectsByType<GameObject>(FindObjectsSortMode.None).Where(go => go.name == name).ToArray();
216+
#else
195217
var gameObjects = GameObject.FindObjectsOfType<GameObject>().Where(go => go.name == name).ToArray();
218+
#endif
196219
if (gameObjects.Length == 0)
197220
{
198221
Debug.Log($"No GameObject found with the name: {name}");
@@ -359,6 +382,17 @@ public void CheckOnlineStatus()
359382
Debug.Log($"<color=#4D65A4>Online Status:</color> {(isOnline ? "<color=#3bb508>Connected</color>" : "<color=#b50808>Disconnected</color>")}");
360383
}
361384

385+
/// <summary>
386+
/// Sets the CSS cursor style for the Unity canvas element.
387+
/// Browser Usage: <code>unityGame.SendMessage("WebGL", "SetCursor", "pointer");</code>
388+
/// </summary>
389+
/// <param name="cursorName">CSS cursor value (e.g., "default", "pointer", "grab", "crosshair", "text")</param>
390+
[WebCommand(Description = "Set the CSS cursor style")]
391+
public void SetCursor(string cursorName)
392+
{
393+
WebToolPlugins.SetCursor(cursorName);
394+
}
395+
362396
/// <summary>
363397
/// Captures the current screen and saves it as a PNG file.
364398
/// </summary>

Assets/Plugins/WebGL/WebBridge/WebBridge.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,14 @@ private static void AddAllWebCommands()
7070
private static void SetGlobalVariables()
7171
{
7272
var graphicsDevice = SystemInfo.graphicsDeviceType;
73-
string webGraphics = string.Empty;
73+
string webGraphics;
7474
switch (graphicsDevice)
7575
{
76+
#if !UNITY_2023_1_OR_NEWER
7677
case GraphicsDeviceType.OpenGLES2:
7778
webGraphics = "WebGL 1";
7879
break;
80+
#endif
7981
case GraphicsDeviceType.OpenGLES3:
8082
webGraphics = "WebGL 2";
8183
break;

Assets/Plugins/WebGL/WebTools/EventListeners/WebEventListeners.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
using System;
1212
using System.Collections.Generic;
13+
using System.Diagnostics;
1314
using System.Runtime.InteropServices;
1415
using UnityEngine;
1516

@@ -36,6 +37,7 @@ private static void OnBeforeSceneLoadRuntimeMethod()
3637
}
3738
#endif
3839

40+
[Conditional("UNITY_WEBGL")]
3941
public static void AddEventListener(string eventName, Action callback)
4042
{
4143
instance.AddEventListenerInternal(eventName, callback);
@@ -59,7 +61,7 @@ private void AddEventListenerInternal(string eventName, Action callback)
5961
// Add event listener on javascript side
6062
_AddJsEventListener(eventName);
6163
#elif UNITY_EDITOR && WEBTOOLS_LOG_CALLS
62-
Debug.Log($"<color=#00CCCC>{nameof(WebEventListeners)}.{nameof(AddEventListenerInternal)} add callback for {eventName}</color>");
64+
UnityEngine.Debug.Log($"<color=#00CCCC>{nameof(WebEventListeners)}.{nameof(AddEventListenerInternal)} add callback for {eventName}</color>");
6365
#endif
6466
}
6567
}

Assets/Plugins/WebGL/WebTools/WebToolPlugins.cs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,17 @@ public static class WebToolPlugins
3535
[DllImport("__Internal")]
3636
private static extern uint _GetTotalMemorySize();
3737
[DllImport("__Internal")]
38+
private static extern uint _GetDeviceMemorySize();
39+
[DllImport("__Internal")]
3840
private static extern bool _CopyToClipboard(string text);
3941
[DllImport("__Internal")]
4042
private static extern int _IsOnline();
4143
[DllImport("__Internal")]
4244
private static extern void _DownloadFile(string filename, string content);
4345
[DllImport("__Internal")]
4446
private static extern void _DownloadBlob(string filename, byte[] byteArray, int byteLength, string mimeType);
47+
[DllImport("__Internal")]
48+
private static extern void _SetCursor(string cursorName);
4549

4650
#endif
4751

@@ -191,6 +195,29 @@ public static float GetTotalMemorySize()
191195
#endif
192196
}
193197

198+
/// <summary>
199+
/// Get the device memory size in MB if supported by the browser
200+
/// Uses navigator.deviceMemory which is supported by chromium based browsers
201+
/// <see href="https://developer.mozilla.org/en-US/docs/Web/API/Navigator/deviceMemory"/>
202+
/// </summary>
203+
/// <returns>Size in MB or -1 if not supported</returns>
204+
public static float GetDeviceMemory()
205+
{
206+
#if UNITY_WEBGL && !UNITY_EDITOR
207+
var gb = _GetDeviceMemorySize();
208+
if (gb > 0)
209+
{
210+
return gb * 1024f; // convert to MB
211+
}
212+
return -1f;
213+
#elif UNITY_EDITOR && WEBTOOLS_LOG_CALLS
214+
Debug.Log($"{nameof(WebToolPlugins)}.{nameof(GetDeviceMemory)} called");
215+
return -1f;
216+
#else
217+
return -1f;
218+
#endif
219+
}
220+
194221
/// <summary>
195222
/// Get the managed memory size used by the application in MB
196223
/// </summary>
@@ -280,5 +307,28 @@ public static void DownloadBinaryFile(string filename, byte[] data, string mimeT
280307
Debug.Log($"{nameof(WebToolPlugins)}.{nameof(DownloadBinaryFile)} called with filename: {filename}");
281308
#endif
282309
}
310+
311+
/// <summary>
312+
/// Sets the CSS cursor style for the Unity canvas element.
313+
/// <see href="https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/cursor"/>
314+
/// </summary>
315+
/// <param name="cursorName">The CSS cursor value (e.g., "pointer", "grab", "crosshair", "text", "default")</param>
316+
/// <example>
317+
/// <code>
318+
/// // Example: Change cursor to pointer on hover
319+
/// WebToolPlugins.SetCursor("pointer");
320+
///
321+
/// // Example: Reset to default cursor
322+
/// WebToolPlugins.SetCursor("default");
323+
/// </code>
324+
/// </example>
325+
public static void SetCursor(string cursorName)
326+
{
327+
#if UNITY_WEBGL && !UNITY_EDITOR
328+
_SetCursor(cursorName);
329+
#elif UNITY_EDITOR && WEBTOOLS_LOG_CALLS
330+
Debug.Log($"{nameof(WebToolPlugins)}.{nameof(SetCursor)} called with cursor: {cursorName}");
331+
#endif
332+
}
283333
}
284334
}

0 commit comments

Comments
 (0)