@@ -20,7 +20,13 @@ namespace Supyrb
2020 public static class WebGlPlugins
2121 {
2222 [ DllImport ( "__Internal" ) ]
23- private static extern void _LogStartTime ( string startupTime , string unityVersion , string webGlVersion ) ;
23+ private static extern void _SetStringVariable ( string variableName , string variableValue ) ;
24+ [ DllImport ( "__Internal" ) ]
25+ private static extern void _AddTimeTrackingEvent ( string eventName ) ;
26+ [ DllImport ( "__Internal" ) ]
27+ private static extern void _ShowInfoPanel ( ) ;
28+ [ DllImport ( "__Internal" ) ]
29+ private static extern void _HideInfoPanel ( ) ;
2430
2531 [ DllImport ( "__Internal" ) ]
2632 private static extern void _LogMemoryInfo ( uint native , uint managed , uint total ) ;
@@ -34,35 +40,82 @@ public static class WebGlPlugins
3440 [ DllImport ( "__Internal" ) ]
3541 private static extern uint _GetDynamicMemorySize ( ) ;
3642
43+ private static bool _infoPanelVisible = false ;
44+
3745 /// <summary>
38- /// Logs the start time for Unity and the time since the webpage started loading
39- /// By default triggered by <see cref="WebGlLogger"/> in Awake with execution order -100
40- /// Needs the Develop WebGL Template to include the webpage time information
46+ /// Sets a global string variable in JavaScript.
47+ /// This variable can be accessed by the console and other javascript functions
4148 /// </summary>
42- public static void LogStartTime ( )
49+ /// <param name="variableName">Name of the variable</param>
50+ /// <param name="value">Value of the variable</param>
51+ public static void SetVariable ( string variableName , string value )
4352 {
4453 #if UNITY_WEBGL && ! UNITY_EDITOR
45- var graphicsDevice = SystemInfo . graphicsDeviceType ;
46- string webGl = string . Empty ;
47- switch ( graphicsDevice )
48- {
49- case GraphicsDeviceType . OpenGLES2 :
50- webGl = "WebGL 1" ;
51- break ;
52- case GraphicsDeviceType . OpenGLES3 :
53- webGl = "WebGL 2" ;
54- break ;
55- default :
56- webGl = graphicsDevice . ToString ( ) ;
57- break ;
58- }
59-
60- _LogStartTime ( Time . realtimeSinceStartup . ToString ( "0.00" ) , Application . unityVersion , webGl ) ;
54+ _SetStringVariable ( variableName , value ) ;
55+ #else
56+ Debug . Log ( $ "{ nameof ( WebGlPlugins ) } .{ nameof ( SetVariable ) } called with { variableName } : { value } ") ;
57+ #endif
58+ }
59+
60+ /// <summary>
61+ /// Adds a time marker at the call time to the javascript map "unityTimeTrackers"
62+ /// The mapped value is performance.now() at the time of the call
63+ /// </summary>
64+ /// <param name="eventName">Name of the tracking event, e.g. "Awake"</param>
65+ public static void AddTimeTrackingEvent ( string eventName )
66+ {
67+ #if UNITY_WEBGL && ! UNITY_EDITOR
68+ _AddTimeTrackingEvent ( eventName ) ;
69+ #else
70+ Debug . Log ( $ "{ nameof ( WebGlPlugins ) } .{ nameof ( AddTimeTrackingEvent ) } called with { eventName } ") ;
71+ #endif
72+ }
73+
74+ /// <summary>
75+ /// Show the info panel in the top right corner
76+ /// By default triggered by <see cref="WebGlTimeTracker"/> in Awake
77+ /// Needs the Develop WebGL Template to provide the logic
78+ /// </summary>
79+ public static void ShowInfoPanel ( )
80+ {
81+ _infoPanelVisible = true ;
82+ #if UNITY_WEBGL && ! UNITY_EDITOR
83+ _ShowInfoPanel ( ) ;
84+ #else
85+ Debug . Log ( $ "{ nameof ( WebGlPlugins ) } .{ nameof ( ShowInfoPanel ) } called") ;
86+ #endif
87+ }
88+
89+ /// <summary>
90+ /// Hide the info panel in the top right corner
91+ /// By default triggered by <see cref="WebGlTimeTracker"/> in Awake
92+ /// Needs the Develop WebGL Template to provide the logic
93+ /// </summary>
94+ public static void HideInfoPanel ( )
95+ {
96+ _infoPanelVisible = false ;
97+ #if UNITY_WEBGL && ! UNITY_EDITOR
98+ _HideInfoPanel ( ) ;
6199 #else
62- Debug . Log ( "Not supported on this platform ") ;
100+ Debug . Log ( $ " { nameof ( WebGlPlugins ) } . { nameof ( HideInfoPanel ) } called ") ;
63101 #endif
64102 }
65103
104+ /// <summary>
105+ /// Toggle the visibility of the info panel
106+ /// </summary>
107+ public static void ToggleInfoPanel ( )
108+ {
109+ if ( _infoPanelVisible )
110+ {
111+ HideInfoPanel ( ) ;
112+ }
113+ else
114+ {
115+ ShowInfoPanel ( ) ;
116+ }
117+ }
118+
66119 /// <summary>
67120 /// Log all current memory data in MB
68121 /// </summary>
@@ -74,7 +127,7 @@ public static void LogMemory()
74127 var total = GetTotalMemorySize ( ) ;
75128 Debug . Log ( $ "Memory stats:\n Managed: { managed : 0.00} MB\n Native: { native : 0.00} MB\n Total: { total : 0.00} MB") ;
76129 #else
77- Debug . Log ( "Not supported on this platform ") ;
130+ Debug . Log ( $ " { nameof ( WebGlPlugins ) } . { nameof ( LogMemory ) } called ") ;
78131 #endif
79132 }
80133
@@ -88,7 +141,7 @@ public static float GetTotalMemorySize()
88141 var bytes = _GetTotalMemorySize ( ) ;
89142 return GetMegaBytes ( bytes ) ;
90143 #else
91- Debug . Log ( "Not supported on this platform ") ;
144+ Debug . Log ( $ " { nameof ( WebGlPlugins ) } . { nameof ( GetTotalMemorySize ) } called ") ;
92145 return - 1f ;
93146 #endif
94147 }
@@ -103,7 +156,7 @@ public static float GetStaticMemorySize()
103156 var bytes = _GetStaticMemorySize ( ) ;
104157 return GetMegaBytes ( bytes ) ;
105158 #else
106- Debug . Log ( "Not supported on this platform ") ;
159+ Debug . Log ( $ " { nameof ( WebGlPlugins ) } . { nameof ( GetStaticMemorySize ) } called ") ;
107160 return - 1f ;
108161 #endif
109162 }
@@ -118,7 +171,7 @@ public static float GetDynamicMemorySize()
118171 var bytes = _GetStaticMemorySize ( ) ;
119172 return GetMegaBytes ( bytes ) ;
120173 #else
121- Debug . Log ( "Not supported on this platform ") ;
174+ Debug . Log ( $ " { nameof ( WebGlPlugins ) } . { nameof ( GetDynamicMemorySize ) } called ") ;
122175 return - 1f ;
123176 #endif
124177 }
@@ -132,7 +185,7 @@ public static float GetNativeMemorySize()
132185 #if UNITY_WEBGL && ! UNITY_EDITOR
133186 return GetDynamicMemorySize ( ) + GetStaticMemorySize ( ) ;
134187 #else
135- Debug . Log ( "Not supported on this platform ") ;
188+ Debug . Log ( $ " { nameof ( WebGlPlugins ) } . { nameof ( GetNativeMemorySize ) } called ") ;
136189 return - 1f ;
137190 #endif
138191 }
0 commit comments