Skip to content

Commit 660846d

Browse files
committed
Merge branch 'master' into 6000.0
# Conflicts: # Packages/manifest.json # Packages/packages-lock.json # ProjectSettings/ProjectVersion.txt
2 parents 7565e4d + 6e2e243 commit 660846d

File tree

5 files changed

+60
-5
lines changed

5 files changed

+60
-5
lines changed

Assets/Plugins/WebGL/WebBridge/CommonCommands.cs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,33 @@ public void SetTimeTimeScale(float timeScale)
163163
Debug.Log($"Time.timeScale: {Time.timeScale}");
164164
}
165165

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+
166188
/// <summary>
167189
/// Finds GameObject(s) by name and logs the found GameObject(s) and their components
168190
/// </summary>
169191
/// <param name="name">The name of the GameObject to find</param>
170192
[WebCommand(Description = "Find GameObject by name and log its components")]
171-
[ContextMenu(nameof(FindGameObjectByName))]
172193
public void FindGameObjectByName(string name)
173194
{
174195
var gameObjects = GameObject.FindObjectsOfType<GameObject>().Where(go => go.name == name).ToArray();
@@ -312,7 +333,6 @@ public void DeleteAllPlayerPrefs()
312333
/// </summary>
313334
/// <param name="runInBackground">1 if it should run in background</param>
314335
[WebCommand(Description = "GraphicsSettings.logWhenShaderIsCompiled")]
315-
[ContextMenu(nameof(LogShaderCompilation))]
316336
public void LogShaderCompilation(int enabled)
317337
{
318338
GraphicsSettings.logWhenShaderIsCompiled = enabled == 1;

Assets/Plugins/WebGL/WebBridge/WebBridge.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,16 @@ namespace Supyrb
2626
public class WebBridge : WebCommands
2727
{
2828
private const string GameObjectName = "WebBridge";
29+
public static double InitializationUnityTime {get; private set;}
30+
public static DateTime InitializationUtcTime {get; private set;}
2931

3032
private static GameObject instance;
3133
#if UNITY_WEBGL
3234
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
3335
private static void OnBeforeSceneLoadRuntimeMethod()
3436
{
37+
InitializationUnityTime = Time.realtimeSinceStartupAsDouble;
38+
InitializationUtcTime = DateTime.UtcNow;
3539
SetGlobalVariables();
3640
instance = new GameObject(GameObjectName);
3741
DontDestroyOnLoad(instance);

Assets/Plugins/WebGL/WebTools/WebToolPlugins.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ public static void AddFpsTrackingEvent(float fps)
8181
#if UNITY_WEBGL && !UNITY_EDITOR
8282
_AddFpsTrackingEvent(fps);
8383
#elif UNITY_EDITOR && WEBTOOLS_LOG_CALLS
84-
Debug.Log($"{nameof(WebToolPlugins)}.{nameof(AddFpsTrackingEvent)} called with {fps:0.00}");
84+
// This is called often, so it can spam the console, uncomment if needed
85+
//Debug.Log($"{nameof(WebToolPlugins)}.{nameof(AddFpsTrackingEvent)} called with {fps:0.00}");
8586
#endif
8687
}
8788

Assets/Prefabs/Spawner.prefab

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,4 @@ MonoBehaviour:
4848
spawnCoolDownSeconds: 0.4
4949
spawnOffsetSeconds: 0
5050
maxInstances: 1000
51+
spawnSceneName: Cubes

Assets/Scripts/ObjectSpawner.cs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
// </author>
99
// --------------------------------------------------------------------------------------------------------------------
1010

11+
using System;
1112
using System.Collections.Generic;
1213
using UnityEngine;
14+
using UnityEngine.SceneManagement;
1315

1416
namespace Supyrb
1517
{
@@ -30,6 +32,10 @@ public class ObjectSpawner : MonoBehaviour
3032
[SerializeField]
3133
private int maxInstances = 200;
3234

35+
[SerializeField]
36+
[Tooltip("If set, the object will be spawned in the scene with the given name")]
37+
private string spawnSceneName = string.Empty;
38+
3339
public float SpawnCoolDownSeconds
3440
{
3541
get => spawnCoolDownSeconds;
@@ -102,12 +108,35 @@ private void SpawnObject()
102108
return;
103109
}
104110

105-
var newGo = Instantiate(prefab, transform.position, transform.rotation);
111+
var newGo = InstantiatePrefab();
106112
spawnedObjects.Enqueue(newGo);
107113
totalSpawnCount++;
108114
}
109115

110-
#if UNITY_EDITOR
116+
private GameObject InstantiatePrefab()
117+
{
118+
var lastActiveScene = SceneManager.GetActiveScene();
119+
if(!string.IsNullOrEmpty(spawnSceneName))
120+
{
121+
var spawnScene = SceneManager.GetSceneByName(spawnSceneName);
122+
if(!spawnScene.IsValid())
123+
{
124+
spawnScene = SceneManager.CreateScene(spawnSceneName);
125+
}
126+
SceneManager.SetActiveScene(spawnScene);
127+
}
128+
129+
var newGo = Instantiate(prefab, transform.position, transform.rotation);
130+
131+
if(!string.IsNullOrEmpty(spawnSceneName))
132+
{
133+
SceneManager.SetActiveScene(lastActiveScene);
134+
}
135+
136+
return newGo;
137+
}
138+
139+
#if UNITY_EDITOR
111140
private void OnDrawGizmos()
112141
{
113142
Gizmos.DrawWireSphere(transform.position, 0.5f);

0 commit comments

Comments
 (0)