Skip to content

Commit 76f7700

Browse files
committed
Merge branch 'master' into 2021.3
# Conflicts: # Assets/Scenes/Main.unity
2 parents 7a12c9e + fc80d3d commit 76f7700

19 files changed

+717
-146
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: 170 additions & 0 deletions
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,48 @@ 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+
/// Finds GameObject(s) by name and logs the found GameObject(s) and their components
168+
/// </summary>
169+
/// <param name="name">The name of the GameObject to find</param>
170+
[WebCommand(Description = "Find GameObject by name and log its components")]
171+
[ContextMenu(nameof(FindGameObjectByName))]
172+
public void FindGameObjectByName(string name)
173+
{
174+
var gameObjects = GameObject.FindObjectsOfType<GameObject>().Where(go => go.name == name).ToArray();
175+
if (gameObjects.Length == 0)
176+
{
177+
Debug.Log($"No GameObject found with the name: {name}");
178+
}
179+
else
180+
{
181+
StringBuilder sb = new StringBuilder();
182+
foreach (var go in gameObjects)
183+
{
184+
int pathStartIndex = 0;
185+
var currentTransform = go.transform;
186+
sb.Insert(pathStartIndex, currentTransform.name);
187+
currentTransform = currentTransform.parent;
188+
while (currentTransform != null)
189+
{
190+
sb.Insert(pathStartIndex, currentTransform.name + "/");
191+
currentTransform = currentTransform.parent;
192+
}
193+
194+
sb.AppendLine($", Tag: {go.tag}, Layer: {go.layer}, ActiveSelf: {go.activeSelf}, ActiveInHierarchy: {go.activeInHierarchy}");
195+
sb.AppendLine("Attached Components:");
196+
var components = go.GetComponents<Component>();
197+
foreach (var component in components)
198+
{
199+
sb.AppendLine($"- {component.GetType().Name}");
200+
}
201+
Debug.Log(sb.ToString());
202+
sb.Clear();
203+
}
204+
}
116205
}
117206

118207
/// <summary>
@@ -214,6 +303,7 @@ public void LogTextureSupport()
214303
public void DeleteAllPlayerPrefs()
215304
{
216305
PlayerPrefs.DeleteAll();
306+
Debug.Log("Deleted all player prefs");
217307
}
218308

219309
/// <summary>
@@ -226,6 +316,86 @@ public void DeleteAllPlayerPrefs()
226316
public void LogShaderCompilation(int enabled)
227317
{
228318
GraphicsSettings.logWhenShaderIsCompiled = enabled == 1;
319+
Debug.Log($"GraphicsSettings.logWhenShaderIsCompiled: {GraphicsSettings.logWhenShaderIsCompiled}");
320+
}
321+
322+
/// <summary>
323+
/// Copy text to clipboard using the browser's clipboard API
324+
/// </summary>
325+
/// <param name="text">Text to copy to clipboard</param>
326+
[WebCommand(Description = "Copy text to clipboard")]
327+
public void CopyToClipboard(string text)
328+
{
329+
WebToolPlugins.CopyToClipboard(text);
330+
}
331+
332+
/// <summary>
333+
/// Check if the browser has an internet connection
334+
/// </summary>
335+
[WebCommand(Description = "Check if browser is online")]
336+
public void CheckOnlineStatus()
337+
{
338+
bool isOnline = WebToolPlugins.IsOnline();
339+
Debug.Log($"<color=#4D65A4>Online Status:</color> {(isOnline ? "<color=#3bb508>Connected</color>" : "<color=#b50808>Disconnected</color>")}");
340+
}
341+
342+
/// <summary>
343+
/// Captures the current screen and saves it as a PNG file.
344+
/// </summary>
345+
[WebCommand(Description = "Save current screen as PNG")]
346+
public void SaveScreenshot()
347+
{
348+
SaveScreenshotSuperSize(1);
349+
}
350+
351+
/// <summary>
352+
/// Captures the current screen and saves it as a PNG file.
353+
/// </summary>
354+
/// <param name="superSize">1 for normal size, 2 for double size, 4 for quadruple size</param>
355+
[WebCommand(Description = "Save current screen as PNG with variable super size")]
356+
public void SaveScreenshotSuperSize(int superSize)
357+
{
358+
StartCoroutine(CaptureScreenshot(superSize));
359+
}
360+
361+
private IEnumerator CaptureScreenshot(int superSize)
362+
{
363+
// Wait for the end of frame to ensure everything is rendered
364+
yield return new WaitForEndOfFrame();
365+
366+
string filename = "screenshot.png";
367+
try
368+
{
369+
// Capture the screen
370+
Texture2D screenshot = ScreenCapture.CaptureScreenshotAsTexture(superSize);
371+
372+
try
373+
{
374+
// Convert to PNG
375+
byte[] pngData = screenshot.EncodeToPNG();
376+
377+
// Download through browser
378+
WebToolPlugins.DownloadBinaryFile(filename, pngData, "image/png");
379+
380+
Debug.Log($"Screenshot saved as {filename} ({screenshot.width}x{screenshot.height}) with size {pngData.Length} bytes");
381+
}
382+
finally
383+
{
384+
// Clean up the texture
385+
if (Application.isPlaying)
386+
{
387+
Destroy(screenshot);
388+
}
389+
else
390+
{
391+
DestroyImmediate(screenshot);
392+
}
393+
}
394+
}
395+
catch (System.Exception e)
396+
{
397+
Debug.LogError($"Failed to save screenshot: {e.Message}");
398+
}
229399
}
230400
}
231401
}

0 commit comments

Comments
 (0)