Skip to content

Commit 7c6a33d

Browse files
committed
Merge branch 'master' into 2021.3
2 parents 774afec + f796151 commit 7c6a33d

File tree

11 files changed

+203
-46
lines changed

11 files changed

+203
-46
lines changed

Assets/Plugins/WebGL/WebBridge/CommonCommands.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,17 @@ public void CheckOnlineStatus()
382382
Debug.Log($"<color=#4D65A4>Online Status:</color> {(isOnline ? "<color=#3bb508>Connected</color>" : "<color=#b50808>Disconnected</color>")}");
383383
}
384384

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+
385396
/// <summary>
386397
/// Captures the current screen and saves it as a PNG file.
387398
/// </summary>

Assets/Plugins/WebGL/WebTools/WebToolPlugins.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ public static class WebToolPlugins
4444
private static extern void _DownloadFile(string filename, string content);
4545
[DllImport("__Internal")]
4646
private static extern void _DownloadBlob(string filename, byte[] byteArray, int byteLength, string mimeType);
47+
[DllImport("__Internal")]
48+
private static extern void _SetCursor(string cursorName);
4749

4850
#endif
4951

@@ -305,5 +307,27 @@ public static void DownloadBinaryFile(string filename, byte[] data, string mimeT
305307
Debug.Log($"{nameof(WebToolPlugins)}.{nameof(DownloadBinaryFile)} called with filename: {filename}");
306308
#endif
307309
}
310+
311+
/// <summary>
312+
/// Sets the CSS cursor style for the Unity canvas element.
313+
/// </summary>
314+
/// <param name="cursorName">The CSS cursor value (e.g., "pointer", "grab", "crosshair", "text", "default")</param>
315+
/// <example>
316+
/// <code>
317+
/// // Example: Change cursor to pointer on hover
318+
/// WebToolPlugins.SetCursor("pointer");
319+
///
320+
/// // Example: Reset to default cursor
321+
/// WebToolPlugins.SetCursor("default");
322+
/// </code>
323+
/// </example>
324+
public static void SetCursor(string cursorName)
325+
{
326+
#if UNITY_WEBGL && !UNITY_EDITOR
327+
_SetCursor(cursorName);
328+
#elif UNITY_EDITOR && WEBTOOLS_LOG_CALLS
329+
Debug.Log($"{nameof(WebToolPlugins)}.{nameof(SetCursor)} called with cursor: {cursorName}");
330+
#endif
331+
}
308332
}
309333
}

Assets/Plugins/WebGL/WebTools/WebToolPlugins.jslib

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,21 @@ var WebGlPlugins =
154154
element.click();
155155
document.body.removeChild(element);
156156
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+
}
157172
}
158173
};
159174

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
@@ -114,3 +115,17 @@ Rigidbody:
114115
m_Interpolate: 0
115116
m_Constraints: 0
116117
m_CollisionDetection: 1
118+
--- !u!114 &265791508532593724
119+
MonoBehaviour:
120+
m_ObjectHideFlags: 0
121+
m_CorrespondingSourceObject: {fileID: 0}
122+
m_PrefabInstance: {fileID: 0}
123+
m_PrefabAsset: {fileID: 0}
124+
m_GameObject: {fileID: 1293945906612296}
125+
m_Enabled: 1
126+
m_EditorHideFlags: 0
127+
m_Script: {fileID: 11500000, guid: 7cd0ca8b7204d4214b198040d886c542, type: 3}
128+
m_Name:
129+
m_EditorClassIdentifier:
130+
CursorEnteredName: pointer
131+
CursorExitedName: default

Assets/Scenes/Main.unity

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ OcclusionCullingSettings:
1313
--- !u!104 &2
1414
RenderSettings:
1515
m_ObjectHideFlags: 0
16-
serializedVersion: 9
16+
serializedVersion: 10
1717
m_Fog: 0
1818
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
1919
m_FogMode: 3
@@ -38,13 +38,12 @@ RenderSettings:
3838
m_ReflectionIntensity: 1
3939
m_CustomReflection: {fileID: 0}
4040
m_Sun: {fileID: 0}
41-
m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1}
4241
m_UseRadianceAmbientProbe: 0
4342
--- !u!157 &3
4443
LightmapSettings:
4544
m_ObjectHideFlags: 0
46-
serializedVersion: 12
47-
m_GIWorkflowMode: 0
45+
serializedVersion: 13
46+
m_BakeOnSceneLoad: 0
4847
m_GISettings:
4948
serializedVersion: 2
5049
m_BounceScale: 1
@@ -67,9 +66,6 @@ LightmapSettings:
6766
m_LightmapParameters: {fileID: 0}
6867
m_LightmapsBakeMode: 1
6968
m_TextureCompression: 1
70-
m_FinalGather: 0
71-
m_FinalGatherFiltering: 1
72-
m_FinalGatherRayCount: 256
7369
m_ReflectionCompression: 2
7470
m_MixedBakeMode: 2
7571
m_BakeBackend: 1
@@ -197,9 +193,8 @@ Light:
197193
m_PrefabAsset: {fileID: 0}
198194
m_GameObject: {fileID: 170076733}
199195
m_Enabled: 1
200-
serializedVersion: 10
196+
serializedVersion: 11
201197
m_Type: 1
202-
m_Shape: 0
203198
m_Color: {r: 0.99215686, g: 0.96962065, b: 0.85490197, a: 1}
204199
m_Intensity: 0.7
205200
m_Range: 10
@@ -249,8 +244,12 @@ Light:
249244
m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0}
250245
m_UseBoundingSphereOverride: 0
251246
m_UseViewFrustumForShadowCasterCull: 1
247+
m_ForceVisible: 0
252248
m_ShadowRadius: 0
253249
m_ShadowAngle: 0
250+
m_LightUnit: 1
251+
m_LuxAtDistance: 1
252+
m_EnableSpotReflector: 1
254253
--- !u!4 &170076735
255254
Transform:
256255
m_ObjectHideFlags: 0
@@ -397,6 +396,9 @@ MeshRenderer:
397396
m_ReflectionProbeUsage: 1
398397
m_RayTracingMode: 2
399398
m_RayTraceProcedural: 0
399+
m_RayTracingAccelStructBuildFlagsOverride: 0
400+
m_RayTracingAccelStructBuildFlags: 1
401+
m_SmallMeshCulling: 1
400402
m_RenderingLayerMask: 4294967295
401403
m_RendererPriority: 0
402404
m_Materials:
@@ -811,6 +813,7 @@ GameObject:
811813
- component: {fileID: 2066011077}
812814
- component: {fileID: 2066011076}
813815
- component: {fileID: 2066011080}
816+
- component: {fileID: 2066011081}
814817
m_Layer: 0
815818
m_Name: RotatingCube
816819
m_TagString: Untagged
@@ -847,6 +850,9 @@ MeshRenderer:
847850
m_ReflectionProbeUsage: 1
848851
m_RayTracingMode: 2
849852
m_RayTraceProcedural: 0
853+
m_RayTracingAccelStructBuildFlagsOverride: 0
854+
m_RayTracingAccelStructBuildFlags: 1
855+
m_SmallMeshCulling: 1
850856
m_RenderingLayerMask: 4294967295
851857
m_RendererPriority: 0
852858
m_Materials:
@@ -910,6 +916,20 @@ MonoBehaviour:
910916
rotationAxis: {x: 0, y: 1, z: 0}
911917
degreePerSecond: 90
912918
updateType: 0
919+
--- !u!114 &2066011081
920+
MonoBehaviour:
921+
m_ObjectHideFlags: 0
922+
m_CorrespondingSourceObject: {fileID: 0}
923+
m_PrefabInstance: {fileID: 0}
924+
m_PrefabAsset: {fileID: 0}
925+
m_GameObject: {fileID: 2066011075}
926+
m_Enabled: 1
927+
m_EditorHideFlags: 0
928+
m_Script: {fileID: 11500000, guid: 7cd0ca8b7204d4214b198040d886c542, type: 3}
929+
m_Name:
930+
m_EditorClassIdentifier:
931+
CursorEnteredName: pointer
932+
CursorExitedName: default
913933
--- !u!1660057539 &9223372036854775807
914934
SceneRoots:
915935
m_ObjectHideFlags: 0
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// --------------------------------------------------------------------------------------------------------------------
2+
// <copyright file="ChangeCursorExample.cs">
3+
// Copyright (c) 2025 Johannes Deml. All rights reserved.
4+
// </copyright>
5+
// <author>
6+
// Johannes Deml
7+
// public@deml.io
8+
// </author>
9+
// --------------------------------------------------------------------------------------------------------------------
10+
11+
using UnityEngine;
12+
13+
namespace Supyrb
14+
{
15+
public class ChangeCursorExample : MonoBehaviour
16+
{
17+
public string CursorEnteredName = "pointer";
18+
public string CursorExitedName = "default";
19+
20+
private void OnMouseEnter()
21+
{
22+
WebToolPlugins.SetCursor(CursorEnteredName);
23+
}
24+
25+
private void OnMouseExit()
26+
{
27+
WebToolPlugins.SetCursor(CursorExitedName);
28+
}
29+
30+
private void OnMouseDown()
31+
{
32+
Destroy(gameObject);
33+
}
34+
}
35+
}

Assets/Scripts/ChangeCursorExample.cs.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Scripts/ObjectSpawner.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,23 @@ private void SpawnObject()
102102
if (spawnedObjects.Count >= maxInstances)
103103
{
104104
var recycleGo = spawnedObjects.Dequeue();
105-
recycleGo.transform.localPosition = transform.position;
106-
recycleGo.transform.localRotation = transform.localRotation;
107-
spawnedObjects.Enqueue(recycleGo);
108-
return;
105+
if(recycleGo == null)
106+
{
107+
// If the spawned object was destroyed, we create a new one
108+
// Decrement spawn count since it will be incremented when created below
109+
totalSpawnCount--;
110+
}
111+
else
112+
{
113+
#if UNITY_2021_3_OR_NEWER
114+
recycleGo.transform.SetLocalPositionAndRotation(transform.position, transform.localRotation);
115+
#else
116+
recycleGo.transform.localPosition = transform.position;
117+
recycleGo.transform.localRotation = transform.localRotation;
118+
#endif
119+
spawnedObjects.Enqueue(recycleGo);
120+
return;
121+
}
109122
}
110123

111124
var newGo = InstantiatePrefab();
198 KB
Loading

Documentation/urp-build-sizes.png

198 KB
Loading

0 commit comments

Comments
 (0)