@@ -29,6 +29,8 @@ public static class WebGlPlugins
2929 [ DllImport ( "__Internal" ) ]
3030 private static extern void _HideInfoPanel ( ) ;
3131 [ DllImport ( "__Internal" ) ]
32+ private static extern string _GetUserAgent ( ) ;
33+ [ DllImport ( "__Internal" ) ]
3234 private static extern uint _GetTotalMemorySize ( ) ;
3335 [ DllImport ( "__Internal" ) ]
3436 private static extern uint _GetStaticMemorySize ( ) ;
@@ -51,7 +53,7 @@ public static void SetVariable(string variableName, string value)
5153 #endif
5254 Debug . Log ( $ "<color=#00CCCC>{ nameof ( WebGlPlugins ) } .{ nameof ( SetVariable ) } set { variableName } : { value } </color>") ;
5355 }
54-
56+
5557 /// <summary>
5658 /// Adds a time marker at the call time to the javascript map "unityTimeTrackers"
5759 /// The mapped value is performance.now() at the time of the call
@@ -65,7 +67,7 @@ public static void AddTimeTrackingEvent(string eventName)
6567 Debug . Log ( $ "{ nameof ( WebGlPlugins ) } .{ nameof ( AddTimeTrackingEvent ) } called with { eventName } ") ;
6668 #endif
6769 }
68-
70+
6971 /// <summary>
7072 /// Show the info panel in the top right corner
7173 /// By default triggered by <see cref="WebGlTimeTracker"/> in Awake
@@ -80,7 +82,7 @@ public static void ShowInfoPanel()
8082 Debug . Log ( $ "{ nameof ( WebGlPlugins ) } .{ nameof ( ShowInfoPanel ) } called") ;
8183 #endif
8284 }
83-
85+
8486 /// <summary>
8587 /// Hide the info panel in the top right corner
8688 /// By default triggered by <see cref="WebGlTimeTracker"/> in Awake
@@ -111,6 +113,33 @@ public static void ToggleInfoPanel()
111113 }
112114 }
113115
116+ /// <summary>
117+ /// Get navigator.userAgent from the browser
118+ /// </summary>
119+ /// <returns>navigator.userAgent</returns>
120+ public static string GetUserAgent ( )
121+ {
122+ #if UNITY_WEBGL && ! UNITY_EDITOR
123+ return _GetUserAgent ( ) ;
124+ #else
125+ Debug . Log ( $ "{ nameof ( WebGlPlugins ) } .{ nameof ( GetUserAgent ) } called") ;
126+ return "undefined" ;
127+ #endif
128+ }
129+
130+ /// <summary>
131+ /// Check user agent to determine if the game runs on a mobile device
132+ /// </summary>
133+ /// <returns>true if on phone or tablet</returns>
134+ public static bool IsMobileDevice ( )
135+ {
136+ string userAgent = GetUserAgent ( ) ;
137+ return userAgent . Contains ( "iPhone" ) ||
138+ userAgent . Contains ( "iPad" ) ||
139+ userAgent . Contains ( "iPod" ) ||
140+ userAgent . Contains ( "Android" ) ;
141+ }
142+
114143 /// <summary>
115144 /// Get the total memory size used by the application in MB
116145 /// </summary>
@@ -194,7 +223,7 @@ public static float GetManagedMemorySize()
194223 var bytes = ( uint ) GC . GetTotalMemory ( false ) ;
195224 return GetMegaBytes ( bytes ) ;
196225 }
197-
226+
198227 /// <summary>
199228 /// Converts bytes (B) to mega bytes (MB)
200229 /// </summary>
0 commit comments