Skip to content

Commit

Permalink
Cache android java class object
Browse files Browse the repository at this point in the history
  • Loading branch information
sanukin39 committed Oct 21, 2020
1 parent f995c8d commit dcac946
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions Assets/UniAndroidVibration/UniAndroidVibration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@
public class UniAndroidVibration
{
private const string PackageClassPath = "net.sanukin.vibration.UniVibration";

#if !UNITY_EDITOR && UNITY_ANDROID
private static AndroidJavaClass _javaClass;
#endif

public static void Vibrate(int milliseconds)
{
#if !UNITY_EDITOR && UNITY_ANDROID
var javaClass = new AndroidJavaClass(PackageClassPath);
javaClass.CallStatic("vibrate", milliseconds);
if (_javaClass == null)
{
_javaClass = new AndroidJavaClass(PackageClassPath);
}
_javaClass.CallStatic("vibrate", milliseconds);
#endif
}
}

0 comments on commit dcac946

Please sign in to comment.