Skip to content

Commit 5b15216

Browse files
committed
Merge branch 'master' into 2023.2
# Conflicts: # Packages/manifest.json # Packages/packages-lock.json # ProjectSettings/ProjectSettings.asset # ProjectSettings/ProjectVersion.txt
2 parents 6016e95 + 595c22a commit 5b15216

File tree

20 files changed

+402
-74
lines changed

20 files changed

+402
-74
lines changed

.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: 41 additions & 2 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 before force pushing tags (in minutes)'
34+
required: false
35+
type: number
36+
default: 0
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 minutes"
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
@@ -173,6 +202,16 @@ jobs:
173202
title: "[Automated workflow] upgrade-unity from ${{steps.last_unity_version.outputs.NAME}} to ${{ steps.upgrade_name.outputs.NAME }}"
174203
body: ${{ steps.template.outputs.result }}
175204

205+
- name: Wait before pushing tags
206+
if: ${{ (inputs.createTags || inputs.tagsOnly) && inputs.delayTags > 0 }}
207+
run: |
208+
DELAY_SECONDS=$((DELAY_TAGS * 60))
209+
echo "Waiting for $DELAY_TAGS minutes ($DELAY_SECONDS seconds) before pushing tags..."
210+
sleep $DELAY_SECONDS
211+
echo "Wait complete. Proceeding with tag push."
212+
env:
213+
DELAY_TAGS: ${{ inputs.delayTags }}
214+
176215
- name: Add tags
177216
if: ${{ inputs.createTags || inputs.tagsOnly }}
178217
run: |

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
}

Assets/Plugins/WebGL/WebTools/WebToolPlugins.jslib

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ var WebGlPlugins =
9999
return -1;
100100
},
101101

102+
_GetDeviceMemorySize: function()
103+
{
104+
if(navigator.deviceMemory) {
105+
return navigator.deviceMemory;
106+
}
107+
return -1;
108+
},
109+
102110
_CopyToClipboard: function(text) {
103111
var str = UTF8ToString(text);
104112
navigator.clipboard.writeText(str)
@@ -146,6 +154,21 @@ var WebGlPlugins =
146154
element.click();
147155
document.body.removeChild(element);
148156
URL.revokeObjectURL(url);
157+
},
158+
159+
_SetCursor: function(cursorName) {
160+
var cursorStr = UTF8ToString(cursorName);
161+
// Check if canvas variable exists from the Unity template
162+
var canvasElement = (typeof canvas !== 'undefined') ? canvas : null;
163+
if (!canvasElement) {
164+
canvasElement = document.getElementById('unity-canvas');
165+
}
166+
if (!canvasElement) {
167+
canvasElement = document.querySelector('canvas');
168+
}
169+
if (canvasElement) {
170+
canvasElement.style.cursor = cursorStr;
171+
}
149172
}
150173
};
151174

Assets/Prefabs/RigidbodyCube.prefab

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ GameObject:
1313
- component: {fileID: 23875290202771946}
1414
- component: {fileID: 65366149667932608}
1515
- component: {fileID: 54003196623453922}
16+
- component: {fileID: 265791508532593724}
1617
m_Layer: 0
1718
m_Name: RigidbodyCube
1819
m_TagString: Untagged
@@ -136,3 +137,17 @@ Rigidbody:
136137
m_Interpolate: 0
137138
m_Constraints: 0
138139
m_CollisionDetection: 1
140+
--- !u!114 &265791508532593724
141+
MonoBehaviour:
142+
m_ObjectHideFlags: 0
143+
m_CorrespondingSourceObject: {fileID: 0}
144+
m_PrefabInstance: {fileID: 0}
145+
m_PrefabAsset: {fileID: 0}
146+
m_GameObject: {fileID: 1293945906612296}
147+
m_Enabled: 1
148+
m_EditorHideFlags: 0
149+
m_Script: {fileID: 11500000, guid: 7cd0ca8b7204d4214b198040d886c542, type: 3}
150+
m_Name:
151+
m_EditorClassIdentifier:
152+
CursorEnteredName: pointer
153+
CursorExitedName: default

0 commit comments

Comments
 (0)