Skip to content

Commit 951f18b

Browse files
committed
Merge branch 'master' into 2023.2-urp
# Conflicts: # Packages/manifest.json # Packages/packages-lock.json # ProjectSettings/MultiplayerManager.asset # ProjectSettings/ProjectVersion.txt
2 parents 75f8b13 + 6e2e243 commit 951f18b

21 files changed

+777
-177
lines changed

.github/workflows/release.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ on:
55
push:
66
tags:
77
- '*'
8+
branches:
9+
- master
810

911
jobs:
1012
variables:
@@ -28,7 +30,12 @@ jobs:
2830
2931
- name: Set tag
3032
id: set_tag
31-
run: echo "VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_OUTPUT
33+
run: |
34+
if [[ $GITHUB_REF == refs/tags/* ]]; then
35+
echo "VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_OUTPUT
36+
else
37+
echo "VERSION=${{ steps.set_unity_version.outputs.VERSION }}-webgl2-master" >> $GITHUB_OUTPUT
38+
fi
3239
3340
- name: Set target name
3441
id: set_build_name
@@ -62,8 +69,8 @@ jobs:
6269
6370
buildProject:
6471
name: Create Unity WebGL Build 🏗
65-
# only build with additional parameters, the tag alone should only create a release draft
66-
if: ${{ needs.variables.outputs.TAG != needs.variables.outputs.UNITY_VERSION }}
72+
# Build if it's a master push or if the tag is not just the unity version
73+
if: ${{ github.ref == 'refs/heads/master' || needs.variables.outputs.TAG != needs.variables.outputs.UNITY_VERSION }}
6774
needs: [ variables ]
6875
runs-on: ubuntu-latest
6976
strategy:
@@ -112,7 +119,7 @@ jobs:
112119
createRelease:
113120
name: Create Github release 🐙
114121
# only run for the pure tag without build parameters
115-
if: ${{ needs.variables.outputs.TAG == needs.variables.outputs.UNITY_VERSION }}
122+
if: ${{ github.ref_type == 'tag' && needs.variables.outputs.TAG == needs.variables.outputs.UNITY_VERSION }}
116123
needs: [ variables ]
117124
runs-on: ubuntu-latest
118125
steps:

.github/workflows/upgrade-unity.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ on:
3232

3333
jobs:
3434
upgrade-unity-version:
35-
name: Upgrade Unity version and packages
35+
name: Upgrade Unity version and packages to ${{ inputs.unityVersion }}
3636
runs-on: ubuntu-latest
3737
strategy:
3838
fail-fast: false
@@ -106,6 +106,13 @@ jobs:
106106
run: |
107107
LAST_UNITY_VERSION=$(sed -n 's/^\m_EditorVersion: //p'< ./ProjectSettings/ProjectVersion.txt)
108108
echo "VERSION=$LAST_UNITY_VERSION" >> $GITHUB_OUTPUT
109+
BRANCH_NAME=${GITHUB_REF#refs/heads/}
110+
if [[ "$BRANCH_NAME" == *"urp"* ]]
111+
then
112+
echo "NAME=$LAST_UNITY_VERSION-urp" >> $GITHUB_OUTPUT
113+
else
114+
echo "NAME=$LAST_UNITY_VERSION" >> $GITHUB_OUTPUT
115+
fi
109116
110117
- name: Set upgrade name
111118
id: upgrade_name
@@ -123,6 +130,7 @@ jobs:
123130
- name: Log variables
124131
run: |
125132
echo "last_unity_version -> ${{ steps.last_unity_version.outputs.VERSION }}"
133+
echo "last_unity_name -> ${{ steps.last_unity_version.outputs.NAME }}"
126134
echo "upgrade_name -> ${{ steps.upgrade_name.outputs.NAME }}"
127135
128136
- name: Build project
@@ -159,10 +167,10 @@ jobs:
159167
uses: peter-evans/create-pull-request@v4
160168
with:
161169
token: ${{ secrets.PR_GITHUB_TOKEN }}
162-
commit-message: "[Automated workflow] upgrade-unity from ${{steps.last_unity_version.outputs.VERSION}} to ${{ inputs.unityVersion }}"
163-
branch: "ci/upgrade-unity/from-${{steps.last_unity_version.outputs.VERSION}}-to-${{ steps.upgrade_name.outputs.NAME }}"
170+
commit-message: "[Automated workflow] upgrade-unity from ${{steps.last_unity_version.outputs.NAME}} to ${{ inputs.unityVersion }}"
171+
branch: "ci/upgrade-unity/from-${{steps.last_unity_version.outputs.NAME}}-to-${{ steps.upgrade_name.outputs.NAME }}"
164172
delete-branch: true
165-
title: "[Automated workflow] upgrade-unity from ${{steps.last_unity_version.outputs.VERSION}} to ${{ steps.upgrade_name.outputs.NAME }}"
173+
title: "[Automated workflow] upgrade-unity from ${{steps.last_unity_version.outputs.NAME}} to ${{ steps.upgrade_name.outputs.NAME }}"
166174
body: ${{ steps.template.outputs.result }}
167175

168176
- name: Add tags

Assets/Plugins/WebGL/WebBridge/CommonCommands.cs

Lines changed: 191 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
// --------------------------------------------------------------------------------------------------------------------
1010

1111
using System;
12+
using System.Collections;
1213
using System.Collections.Generic;
14+
using System.Linq;
15+
using System.Text;
1316
using Supyrb.Attributes;
1417
using UnityEngine;
1518
using UnityEngine.Rendering;
@@ -21,6 +24,11 @@ namespace Supyrb
2124
/// </summary>
2225
public class CommonCommands : WebCommands
2326
{
27+
/// <summary>
28+
/// List that stores allocated byte arrays to prevent them from being garbage collected
29+
/// </summary>
30+
private List<byte[]> byteArrayMemory = new List<byte[]>();
31+
2432
/// <summary>
2533
/// Disable capturing all keyboard input, e.g. for using native html input fields
2634
/// Browser Usage: <code>unityGame.SendMessage("WebGL","DisableCaptureAllKeyboardInput");</code>
@@ -58,6 +66,41 @@ public void LogMemory()
5866
WebToolPlugins.LogMemory();
5967
}
6068

69+
/// <summary>
70+
/// Allocate memory to test memory usage and limits
71+
/// The memory will be stored in a list to prevent it from being garbage collected
72+
/// </summary>
73+
/// <param name="mb">MB to allocate</param>
74+
[WebCommand(Description = "Allocate memory to test memory usage and limits")]
75+
public void AllocateByteArrayMemory(int mb)
76+
{
77+
byte[] memory = new byte[mb * 1024 * 1024];
78+
byteArrayMemory.Add(memory);
79+
Debug.Log($"Allocated {mb} MB of memory, total memory usage: {WebToolPlugins.GetTotalMemorySize():0.00}MB");
80+
}
81+
82+
/// <summary>
83+
/// Release all allocated byte array memory
84+
/// </summary>
85+
[WebCommand(Description = "Release all allocated byte array memory")]
86+
[ContextMenu(nameof(ReleaseByteArrayMemory))]
87+
public void ReleaseByteArrayMemory()
88+
{
89+
byteArrayMemory.Clear();
90+
Debug.Log("Released all allocated byte array memory, it can now be garbage collected");
91+
}
92+
93+
/// <summary>
94+
/// Trigger garbage collection
95+
/// </summary>
96+
[WebCommand(Description = "Trigger garbage collection")]
97+
[ContextMenu(nameof(TriggerGarbageCollection))]
98+
public void TriggerGarbageCollection()
99+
{
100+
GC.Collect();
101+
Debug.Log("Garbage collection triggered");
102+
}
103+
61104
/// <summary>
62105
/// Unloads all unused assets <see cref="Resources.UnloadUnusedAssets"/>
63106
/// Browser Usage: <code>unityGame.SendMessage("WebGL","UnloadUnusedAssets");</code>
@@ -67,6 +110,7 @@ public void LogMemory()
67110
public void UnloadUnusedAssets()
68111
{
69112
Resources.UnloadUnusedAssets();
113+
Debug.Log("Unloaded unused assets");
70114
}
71115

72116
/// <summary>
@@ -79,6 +123,7 @@ public void UnloadUnusedAssets()
79123
public void SetApplicationRunInBackground(int runInBackground)
80124
{
81125
Application.runInBackground = runInBackground == 1;
126+
Debug.Log($"Application.runInBackground: {Application.runInBackground}");
82127
}
83128

84129
/// <summary>
@@ -90,6 +135,7 @@ public void SetApplicationRunInBackground(int runInBackground)
90135
public void SetApplicationTargetFrameRate(int targetFrameRate)
91136
{
92137
Application.targetFrameRate = targetFrameRate;
138+
Debug.Log($"Application.targetFrameRate: {Application.targetFrameRate}");
93139
}
94140

95141
/// <summary>
@@ -101,6 +147,7 @@ public void SetApplicationTargetFrameRate(int targetFrameRate)
101147
public void SetTimeFixedDeltaTime(float fixedDeltaTime)
102148
{
103149
Time.fixedDeltaTime = fixedDeltaTime;
150+
Debug.Log($"Time.fixedDeltaTime: {Time.fixedDeltaTime}");
104151
}
105152

106153
/// <summary>
@@ -113,6 +160,69 @@ public void SetTimeFixedDeltaTime(float fixedDeltaTime)
113160
public void SetTimeTimeScale(float timeScale)
114161
{
115162
Time.timeScale = timeScale;
163+
Debug.Log($"Time.timeScale: {Time.timeScale}");
164+
}
165+
166+
/// <summary>
167+
/// Log information about when the WebBridge was initialized
168+
/// </summary>
169+
[WebCommand(Description = "Log initialization time information")]
170+
[ContextMenu(nameof(LogInitializationTime))]
171+
public void LogInitializationTime()
172+
{
173+
var currentUnityTime = Time.realtimeSinceStartupAsDouble;
174+
var currentUtcTime = DateTime.UtcNow;
175+
176+
var unityTimeSinceInit = currentUnityTime - WebBridge.InitializationUnityTime;
177+
var utcTimeSinceInit = currentUtcTime - WebBridge.InitializationUtcTime;
178+
179+
var timeComparison = unityTimeSinceInit > utcTimeSinceInit.TotalSeconds
180+
? "future"
181+
: "past";
182+
183+
Debug.Log($"Unity Time since init: {unityTimeSinceInit:F2}s\n" +
184+
$"UTC Time since init: {utcTimeSinceInit.TotalSeconds:F2}s\n" +
185+
$"Unity time lies {Math.Abs(unityTimeSinceInit - utcTimeSinceInit.TotalSeconds):F2}s in the {timeComparison} compared to UTC");
186+
}
187+
188+
/// <summary>
189+
/// Finds GameObject(s) by name and logs the found GameObject(s) and their components
190+
/// </summary>
191+
/// <param name="name">The name of the GameObject to find</param>
192+
[WebCommand(Description = "Find GameObject by name and log its components")]
193+
public void FindGameObjectByName(string name)
194+
{
195+
var gameObjects = GameObject.FindObjectsOfType<GameObject>().Where(go => go.name == name).ToArray();
196+
if (gameObjects.Length == 0)
197+
{
198+
Debug.Log($"No GameObject found with the name: {name}");
199+
}
200+
else
201+
{
202+
StringBuilder sb = new StringBuilder();
203+
foreach (var go in gameObjects)
204+
{
205+
int pathStartIndex = 0;
206+
var currentTransform = go.transform;
207+
sb.Insert(pathStartIndex, currentTransform.name);
208+
currentTransform = currentTransform.parent;
209+
while (currentTransform != null)
210+
{
211+
sb.Insert(pathStartIndex, currentTransform.name + "/");
212+
currentTransform = currentTransform.parent;
213+
}
214+
215+
sb.AppendLine($", Tag: {go.tag}, Layer: {go.layer}, ActiveSelf: {go.activeSelf}, ActiveInHierarchy: {go.activeInHierarchy}");
216+
sb.AppendLine("Attached Components:");
217+
var components = go.GetComponents<Component>();
218+
foreach (var component in components)
219+
{
220+
sb.AppendLine($"- {component.GetType().Name}");
221+
}
222+
Debug.Log(sb.ToString());
223+
sb.Clear();
224+
}
225+
}
116226
}
117227

118228
/// <summary>
@@ -214,6 +324,7 @@ public void LogTextureSupport()
214324
public void DeleteAllPlayerPrefs()
215325
{
216326
PlayerPrefs.DeleteAll();
327+
Debug.Log("Deleted all player prefs");
217328
}
218329

219330
/// <summary>
@@ -222,10 +333,89 @@ public void DeleteAllPlayerPrefs()
222333
/// </summary>
223334
/// <param name="runInBackground">1 if it should run in background</param>
224335
[WebCommand(Description = "GraphicsSettings.logWhenShaderIsCompiled")]
225-
[ContextMenu(nameof(LogShaderCompilation))]
226336
public void LogShaderCompilation(int enabled)
227337
{
228338
GraphicsSettings.logWhenShaderIsCompiled = enabled == 1;
339+
Debug.Log($"GraphicsSettings.logWhenShaderIsCompiled: {GraphicsSettings.logWhenShaderIsCompiled}");
340+
}
341+
342+
/// <summary>
343+
/// Copy text to clipboard using the browser's clipboard API
344+
/// </summary>
345+
/// <param name="text">Text to copy to clipboard</param>
346+
[WebCommand(Description = "Copy text to clipboard")]
347+
public void CopyToClipboard(string text)
348+
{
349+
WebToolPlugins.CopyToClipboard(text);
350+
}
351+
352+
/// <summary>
353+
/// Check if the browser has an internet connection
354+
/// </summary>
355+
[WebCommand(Description = "Check if browser is online")]
356+
public void CheckOnlineStatus()
357+
{
358+
bool isOnline = WebToolPlugins.IsOnline();
359+
Debug.Log($"<color=#4D65A4>Online Status:</color> {(isOnline ? "<color=#3bb508>Connected</color>" : "<color=#b50808>Disconnected</color>")}");
360+
}
361+
362+
/// <summary>
363+
/// Captures the current screen and saves it as a PNG file.
364+
/// </summary>
365+
[WebCommand(Description = "Save current screen as PNG")]
366+
public void SaveScreenshot()
367+
{
368+
SaveScreenshotSuperSize(1);
369+
}
370+
371+
/// <summary>
372+
/// Captures the current screen and saves it as a PNG file.
373+
/// </summary>
374+
/// <param name="superSize">1 for normal size, 2 for double size, 4 for quadruple size</param>
375+
[WebCommand(Description = "Save current screen as PNG with variable super size")]
376+
public void SaveScreenshotSuperSize(int superSize)
377+
{
378+
StartCoroutine(CaptureScreenshot(superSize));
379+
}
380+
381+
private IEnumerator CaptureScreenshot(int superSize)
382+
{
383+
// Wait for the end of frame to ensure everything is rendered
384+
yield return new WaitForEndOfFrame();
385+
386+
string filename = "screenshot.png";
387+
try
388+
{
389+
// Capture the screen
390+
Texture2D screenshot = ScreenCapture.CaptureScreenshotAsTexture(superSize);
391+
392+
try
393+
{
394+
// Convert to PNG
395+
byte[] pngData = screenshot.EncodeToPNG();
396+
397+
// Download through browser
398+
WebToolPlugins.DownloadBinaryFile(filename, pngData, "image/png");
399+
400+
Debug.Log($"Screenshot saved as {filename} ({screenshot.width}x{screenshot.height}) with size {pngData.Length} bytes");
401+
}
402+
finally
403+
{
404+
// Clean up the texture
405+
if (Application.isPlaying)
406+
{
407+
Destroy(screenshot);
408+
}
409+
else
410+
{
411+
DestroyImmediate(screenshot);
412+
}
413+
}
414+
}
415+
catch (System.Exception e)
416+
{
417+
Debug.LogError($"Failed to save screenshot: {e.Message}");
418+
}
229419
}
230420
}
231421
}

0 commit comments

Comments
 (0)