Skip to content

Commit 03e269c

Browse files
committed
Add command to compare realtime since startup and utc now
1 parent 515a296 commit 03e269c

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
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);

0 commit comments

Comments
 (0)