// Requests a vibration on Android for the specified pattern and optional repeat // Straight out of the Android documentation : // Pass in an array of ints that are the durations for which to turn on or off the vibrator in milliseconds. // The first value indicates the number of milliseconds to wait before turning the vibrator on. // The next value indicates the number of milliseconds for which to keep the vibrator on before turning it off. // Subsequent values alternate between durations in milliseconds to turn the vibrator off or to turn the vibrator on. // repeat: the index into pattern at which to repeat, or -1 if you don't want to repeat. public static void AndroidVibrate(long[] pattern, int repeat) { if (!MMNVPlatform.Android()) { return; } if (pattern == null) { return; } if ((AndroidSDKVersion() < 26)) { AndroidVibrator.Call("vibrate", pattern, repeat); } else { AndroidVibrationEffectClassInitialization(); try { VibrationEffect = VibrationEffectClass.CallStatic <AndroidJavaObject>("createWaveform", new object[] { pattern, repeat }); AndroidVibrator.Call("vibrate", VibrationEffect); } catch (Exception e) { Debug.LogException(e); } } }
/// <summary> /// Returns true if the device running the game has vibrations /// </summary> /// <returns></returns> public static bool AndroidHasVibrator() { if (!MMNVPlatform.Android()) { return(false); } return(AndroidVibrator.Call <bool>("hasVibrator")); }
/// <summary> /// Stops all Android vibrations that may be active /// </summary> public static void AndroidCancelVibrations() { if (!MMNVPlatform.Android()) { return; } AndroidVibrator.Call("cancel"); }
/// <summary> /// Requests a default vibration on Android, for the specified duration, in milliseconds /// </summary> /// <param name="milliseconds">Milliseconds.</param> public static void AndroidVibrate(long milliseconds) { if (!MMNVPlatform.Android()) { return; } AndroidVibrateMethodRawClassParameters[0].j = milliseconds; AndroidJNI.CallVoidMethod(AndroidVibrator.GetRawObject(), AndroidVibrateMethodRawClass, AndroidVibrateMethodRawClassParameters); }
/// <summary> /// Returns true if the device running the game has amplitude control /// </summary> /// <returns></returns> public static bool AndroidHasAmplitudeControl() { if ((AndroidSDKVersion() < 26)) { return(false); } if (!MMNVPlatform.Android()) { return(false); } return(AndroidVibrator.Call <bool>("hasAmplitudeControl")); }
/// <summary> /// Requests a vibration on Android for the specified pattern, amplitude and optional repeat /// </summary> /// <param name="pattern">Pattern.</param> /// <param name="amplitudes">Amplitudes.</param> /// <param name="repeat">Repeat : -1 : no repeat, 0 : infinite, 1 : repeat once, 2 : repeat twice, etc</param> public static void AndroidVibrate(long[] pattern, int[] amplitudes, int repeat) { if (!MMNVPlatform.Android()) { return; } if ((AndroidSDKVersion() < 26)) { AndroidVibrator.Call("vibrate", pattern, repeat); } else { AndroidVibrationEffectClassInitialization(); VibrationEffect = VibrationEffectClass.CallStatic <AndroidJavaObject>("createWaveform", new object[] { pattern, amplitudes, repeat }); AndroidVibrator.Call("vibrate", VibrationEffect); } }
/// <summary> /// Requests a vibration of the specified amplitude and duration. If amplitude is not supported by the device's SDK, a default vibration will be requested /// </summary> /// <param name="milliseconds">Milliseconds.</param> /// <param name="amplitude">Amplitude.</param> public static void AndroidVibrate(long milliseconds, int amplitude) { if (!MMNVPlatform.Android()) { return; } // amplitude is only supported after API26 if ((AndroidSDKVersion() < 26)) { AndroidVibrate(milliseconds); } else { AndroidVibrationEffectClassInitialization(); VibrationEffect = VibrationEffectClass.CallStatic <AndroidJavaObject>("createOneShot", new object[] { milliseconds, amplitude }); AndroidVibrator.Call("vibrate", VibrationEffect); } }
/// <summary> /// Requests a vibration on Android for the specified pattern, amplitude and optional repeat /// </summary> /// <param name="pattern">Pattern.</param> /// <param name="amplitudes">Amplitudes.</param> /// <param name="repeat">Repeat : -1 : no repeat, 0 : infinite, 1 : repeat once, 2 : repeat twice, etc</param> public static void AndroidVibrate(long[] pattern, int[] amplitudes, int repeat, bool threaded = false) { if (!MMNVPlatform.Android()) { return; } if ((pattern == null) || (amplitudes == null)) { return; } if ((pattern.Length == 0) || (amplitudes.Length == 0)) { return; } if ((AndroidSDKVersion() < 26)) { AndroidVibrator.Call("vibrate", pattern, repeat); } else { if (threaded) { if (_androidVibrateThread == null) { _androidVibrateThread = new MMNVAltThread <MMNVAndroidVibrateThreadData>(); _androidVibrateThreadData = new MMNVAndroidVibrateThreadData(); } _androidVibrateThreadData.Pattern = pattern; _androidVibrateThreadData.Amplitudes = amplitudes; _androidVibrateThreadData.Repeat = repeat; _androidVibrateThread.Run(AndroidVibrateThread, _androidVibrateThreadData); } else { AndroidVibrateNoThread(pattern, amplitudes, repeat); } } }
/// <summary> /// Returns true if the current platform is Android, false otherwise. /// </summary> public static bool Android() { return(MMNVPlatform.Android()); }