Skip to content

Commit a055cc8

Browse files
committed
Cleanup code any make sure log is not spammed by default
You can add the script define WEBTOOLS_LOG_CALLS to see the logs in the editor
1 parent 04633e2 commit a055cc8

File tree

2 files changed

+36
-32
lines changed

2 files changed

+36
-32
lines changed

Assets/Plugins/WebGL/WebBridge/WebBridge.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ private static void SetGlobalVariables()
9292

9393
private void Start()
9494
{
95+
#if (!UNITY_EDITOR && UNITY_WEBGL) || UNITY_EDITOR && WEBTOOLS_LOG_CALLS
9596
Debug.Log($"Unity WebGL Bridge ready -> Run 'runUnityCommand(\"Help\")' in the browser console to see usage");
97+
#endif
9698
}
9799

98100
[WebCommand(Description = "Log all available commands")]

Assets/Plugins/WebGL/WebTools/WebToolPlugins.cs

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,12 @@ public static class WebToolPlugins
5050
/// <param name="value">Value of the variable</param>
5151
public static void SetVariable(string variableName, string value)
5252
{
53-
#if UNITY_WEBGL && !UNITY_EDITOR
53+
#if UNITY_WEBGL && !UNITY_EDITOR
5454
_SetStringVariable(variableName, value);
55-
#endif
55+
_AddTimeTrackingEvent(eventName);
56+
#elif UNITY_EDITOR && WEBTOOLS_LOG_CALLS
5657
Debug.Log($"<color=#00CCCC>{nameof(WebToolPlugins)}.{nameof(SetVariable)} set {variableName}: {value}</color>");
58+
#endif
5759
}
5860

5961
/// <summary>
@@ -63,20 +65,20 @@ public static void SetVariable(string variableName, string value)
6365
/// <param name="eventName">Name of the tracking event, e.g. "Awake"</param>
6466
public static void AddTimeTrackingEvent(string eventName)
6567
{
66-
#if UNITY_WEBGL && !UNITY_EDITOR
68+
#if UNITY_WEBGL && !UNITY_EDITOR
6769
_AddTimeTrackingEvent(eventName);
68-
#else
70+
#elif UNITY_EDITOR && WEBTOOLS_LOG_CALLS
6971
Debug.Log($"{nameof(WebToolPlugins)}.{nameof(AddTimeTrackingEvent)} called with {eventName}");
70-
#endif
72+
#endif
7173
}
7274

7375
public static void AddFpsTrackingEvent(float fps)
7476
{
75-
#if UNITY_WEBGL && !UNITY_EDITOR
77+
#if UNITY_WEBGL && !UNITY_EDITOR
7678
_AddFpsTrackingEvent(fps);
77-
#else
79+
#elif UNITY_EDITOR && WEBTOOLS_LOG_CALLS
7880
Debug.Log($"{nameof(WebToolPlugins)}.{nameof(AddFpsTrackingEvent)} called with {fps:0.00}");
79-
#endif
81+
#endif
8082
}
8183

8284
/// <summary>
@@ -87,11 +89,11 @@ public static void AddFpsTrackingEvent(float fps)
8789
public static void ShowInfoPanel()
8890
{
8991
_infoPanelVisible = true;
90-
#if UNITY_WEBGL && !UNITY_EDITOR
92+
#if UNITY_WEBGL && !UNITY_EDITOR
9193
_ShowInfoPanel();
92-
#else
94+
#elif UNITY_EDITOR && WEBTOOLS_LOG_CALLS
9395
Debug.Log($"{nameof(WebToolPlugins)}.{nameof(ShowInfoPanel)} called");
94-
#endif
96+
#endif
9597
}
9698

9799
/// <summary>
@@ -102,11 +104,11 @@ public static void ShowInfoPanel()
102104
public static void HideInfoPanel()
103105
{
104106
_infoPanelVisible = false;
105-
#if UNITY_WEBGL && !UNITY_EDITOR
107+
#if UNITY_WEBGL && !UNITY_EDITOR
106108
_HideInfoPanel();
107-
#else
109+
#elif UNITY_EDITOR && WEBTOOLS_LOG_CALLS
108110
Debug.Log($"{nameof(WebToolPlugins)}.{nameof(HideInfoPanel)} called");
109-
#endif
111+
#endif
110112
}
111113

112114
/// <summary>
@@ -130,12 +132,12 @@ public static void ToggleInfoPanel()
130132
/// <returns>navigator.userAgent</returns>
131133
public static string GetUserAgent()
132134
{
133-
#if UNITY_WEBGL && !UNITY_EDITOR
135+
#if UNITY_WEBGL && !UNITY_EDITOR
134136
return _GetUserAgent();
135-
#else
137+
#elif UNITY_EDITOR && WEBTOOLS_LOG_CALLS
136138
Debug.Log($"{nameof(WebToolPlugins)}.{nameof(GetUserAgent)} called");
139+
#endif
137140
return "undefined";
138-
#endif
139141
}
140142

141143
/// <summary>
@@ -157,13 +159,13 @@ public static bool IsMobileDevice()
157159
/// <returns>Size in MB</returns>
158160
public static float GetTotalMemorySize()
159161
{
160-
#if UNITY_WEBGL && !UNITY_EDITOR
162+
#if UNITY_WEBGL && !UNITY_EDITOR
161163
var bytes = _GetTotalMemorySize();
162164
return GetMegaBytes(bytes);
163-
#else
165+
#elif UNITY_EDITOR && WEBTOOLS_LOG_CALLS
164166
Debug.Log($"{nameof(WebToolPlugins)}.{nameof(GetTotalMemorySize)} called");
167+
#endif
165168
return -1f;
166-
#endif
167169
}
168170

169171
/// <summary>
@@ -176,7 +178,7 @@ public static void LogMemory()
176178
var native = GetNativeMemorySize();
177179
var total = GetTotalMemorySize();
178180
Debug.Log($"Memory stats:\nManaged: {managed:0.00}MB\nNative: {native:0.00}MB\nTotal: {total:0.00}MB");
179-
#else
181+
#elif UNITY_EDITOR && WEBTOOLS_LOG_CALLS
180182
Debug.Log($"{nameof(WebToolPlugins)}.{nameof(LogMemory)} called");
181183
#endif
182184
}
@@ -187,13 +189,13 @@ public static void LogMemory()
187189
/// <returns>Size in MB</returns>
188190
public static float GetStaticMemorySize()
189191
{
190-
#if UNITY_WEBGL && !UNITY_EDITOR
192+
#if UNITY_WEBGL && !UNITY_EDITOR
191193
var bytes = _GetStaticMemorySize();
192194
return GetMegaBytes(bytes);
193-
#else
195+
#elif UNITY_EDITOR && WEBTOOLS_LOG_CALLS
194196
Debug.Log($"{nameof(WebToolPlugins)}.{nameof(GetStaticMemorySize)} called");
197+
#endif
195198
return -1f;
196-
#endif
197199
}
198200

199201
/// <summary>
@@ -202,13 +204,13 @@ public static float GetStaticMemorySize()
202204
/// <returns>Size in MB</returns>
203205
public static float GetDynamicMemorySize()
204206
{
205-
#if UNITY_WEBGL && !UNITY_EDITOR
207+
#if UNITY_WEBGL && !UNITY_EDITOR
206208
var bytes = _GetStaticMemorySize();
207209
return GetMegaBytes(bytes);
208-
#else
210+
#elif UNITY_EDITOR && WEBTOOLS_LOG_CALLS
209211
Debug.Log($"{nameof(WebToolPlugins)}.{nameof(GetDynamicMemorySize)} called");
212+
#endif
210213
return -1f;
211-
#endif
212214
}
213215

214216
/// <summary>
@@ -217,12 +219,12 @@ public static float GetDynamicMemorySize()
217219
/// <returns>Size in MB</returns>
218220
public static float GetNativeMemorySize()
219221
{
220-
#if UNITY_WEBGL && !UNITY_EDITOR
222+
#if UNITY_WEBGL && !UNITY_EDITOR
221223
return GetDynamicMemorySize() + GetStaticMemorySize();
222-
#else
224+
#elif UNITY_EDITOR && WEBTOOLS_LOG_CALLS
223225
Debug.Log($"{nameof(WebToolPlugins)}.{nameof(GetNativeMemorySize)} called");
226+
#endif
224227
return -1f;
225-
#endif
226228
}
227229

228230
/// <summary>
@@ -231,7 +233,7 @@ public static float GetNativeMemorySize()
231233
/// <returns>Size in MB</returns>
232234
public static float GetManagedMemorySize()
233235
{
234-
var bytes = (uint) GC.GetTotalMemory(false);
236+
var bytes = (uint)GC.GetTotalMemory(false);
235237
return GetMegaBytes(bytes);
236238
}
237239

@@ -242,7 +244,7 @@ public static float GetManagedMemorySize()
242244
/// <returns>bytes / (1024 * 1024)</returns>
243245
private static float GetMegaBytes(uint bytes)
244246
{
245-
return (float) bytes / (1024 * 1024);
247+
return (float)bytes / (1024 * 1024);
246248
}
247249
}
248250
}

0 commit comments

Comments
 (0)