@@ -46,6 +46,10 @@ public static class WebToolPlugins
4646 private static extern void _DownloadBlob ( string filename , byte [ ] byteArray , int byteLength , string mimeType ) ;
4747 [ DllImport ( "__Internal" ) ]
4848 private static extern void _SetCursor ( string cursorName ) ;
49+ [ DllImport ( "__Internal" ) ]
50+ private static extern void _Vibrate ( int durationInMs ) ;
51+ [ DllImport ( "__Internal" ) ]
52+ private static extern void _VibratePattern ( int [ ] durationsInMs , int length ) ;
4953
5054#endif
5155
@@ -330,5 +334,47 @@ public static void SetCursor(string cursorName)
330334 Debug . Log ( $ "{ nameof ( WebToolPlugins ) } .{ nameof ( SetCursor ) } called with cursor: { cursorName } ") ;
331335 #endif
332336 }
337+
338+ /// <summary>
339+ /// Triggers a vibration on devices that support it using the Vibration API.
340+ /// <see href="https://developer.mozilla.org/en-US/docs/Web/API/Navigator/vibrate"/>
341+ /// </summary>
342+ /// <param name="durationInMs">Duration of the vibration in milliseconds</param>
343+ public static void Vibrate ( int durationInMs )
344+ {
345+ #if UNITY_WEBGL && ! UNITY_EDITOR
346+ _Vibrate ( durationInMs ) ;
347+ #elif UNITY_EDITOR && WEBTOOLS_LOG_CALLS
348+ Debug . Log ( $ "{ nameof ( WebToolPlugins ) } .{ nameof ( Vibrate ) } called with duration: { durationInMs } ms") ;
349+ #endif
350+ }
351+
352+ /// <summary>
353+ /// Triggers a vibration with 0ms on devices that support it using the Vibration API.
354+ /// <see href="https://developer.mozilla.org/en-US/docs/Web/API/Navigator/vibrate"/>
355+ /// </summary>
356+ public static void StopCurrentVibration ( )
357+ {
358+ #if UNITY_WEBGL && ! UNITY_EDITOR
359+ _Vibrate ( 0 ) ;
360+ #elif UNITY_EDITOR && WEBTOOLS_LOG_CALLS
361+ Debug . Log ( $ "{ nameof ( WebToolPlugins ) } .{ nameof ( StopCurrentVibration ) } called") ;
362+ #endif
363+ }
364+
365+ /// <summary>
366+ /// Triggers a vibration pattern on devices that support it using the Vibration API.
367+ /// Alternating values represent vibration and pause durations.
368+ /// <see href="https://developer.mozilla.org/en-US/docs/Web/API/Navigator/vibrate"/>
369+ /// </summary>
370+ /// <param name="durationsInMs">Alternating vibration/pause durations in milliseconds</param>
371+ public static void Vibrate ( int [ ] durationsInMs )
372+ {
373+ #if UNITY_WEBGL && ! UNITY_EDITOR
374+ _VibratePattern ( durationsInMs , durationsInMs . Length ) ;
375+ #elif UNITY_EDITOR && WEBTOOLS_LOG_CALLS
376+ Debug . Log ( $ "{ nameof ( WebToolPlugins ) } .{ nameof ( Vibrate ) } called with pattern: [{ string . Join ( ", " , durationsInMs ) } ]ms") ;
377+ #endif
378+ }
333379 }
334380}
0 commit comments