public void OnVibrateWaveForm2() { if (!AGVibrator.HasVibrator()) { Debug.LogWarning("This device does not have vibrator"); } if (!AGVibrator.AreVibrationEffectsSupported) { Debug.LogWarning("This device does not support vibration effects API!"); return; } long[] mVibratePattern = { 0, 400, 1000, 600, 1000, 800, 1000, 1000 }; int[] mAmplitudes = { 0, 255, 0, 255, 0, 255, 0, 255 }; //Create a waveform vibration with different vibration amplitudes AGVibrator.Cancel(); AGVibrator.Vibrate(VibrationEffect.CreateWaveForm(mVibratePattern, mAmplitudes, 0)); }
public void OnVibrateWaveForm1() { if (!AGVibrator.HasVibrator()) { Debug.LogWarning("This device does not have vibrator"); } if (!AGVibrator.AreVibrationEffectsSupported) { Debug.LogWarning("This device does not support vibration effects API!"); return; } // Start without a delay // Each element then alternates between vibrate, sleep, vibrate, sleep... long[] mVibratePattern = { 0, 400, 1000, 600, 1000, 800, 1000, 1000 }; AGVibrator.Cancel(); //Create a waveform vibration. AGVibrator.Vibrate(VibrationEffect.CreateWaveForm(mVibratePattern, -1)); }
public static void HapticEvent(HEvent e) { #if UNITY_IOS bool available = IGHapticFeedback.IsHapticFeedbackSupported; #elif UNITY_ANDROID bool available = AGVibrator.HasVibrator(); #endif if (!available) { return; } switch (e) { case HEvent.Select: #if UNITY_IOS IGHapticFeedback.SelectionChanged(); #elif UNITY_ANDROID AGVibrator.Vibrate(VibrationEffect.CreateOneShot(400, 120)); #endif break; case HEvent.Delete: #if UNITY_IOS IGHapticFeedback.ImpactOccurred(IGHapticFeedback.ImpactType.Medium); #elif UNITY_ANDROID AGVibrator.Vibrate(VibrationEffect.CreateOneShot(600, 170)); #endif break; case HEvent.Deleted: #if UNITY_IOS IGHapticFeedback.ImpactOccurred(IGHapticFeedback.ImpactType.Heavy); #elif UNITY_ANDROID AGVibrator.Vibrate(VibrationEffect.CreateOneShot(600, 250)); #endif break; case HEvent.Click: #if UNITY_IOS IGHapticFeedback.ImpactOccurred(IGHapticFeedback.ImpactType.Light); #elif UNITY_ANDROID AGVibrator.Vibrate(VibrationEffect.CreateOneShot(300, 100)); #endif break; case HEvent.Error: #if UNITY_IOS IGHapticFeedback.NotificationOccurred(IGHapticFeedback.NotificationType.Error); #elif UNITY_ANDROID AGVibrator.Vibrate(VibrationEffect.CreateWaveForm(error_pattern, error_amplitude, -1)); #endif break; case HEvent.Warning: #if UNITY_IOS IGHapticFeedback.NotificationOccurred(IGHapticFeedback.NotificationType.Warning); #elif UNITY_ANDROID AGVibrator.Vibrate(VibrationEffect.CreateWaveForm(warning_pattern, warning_amplitude, -1)); #endif break; case HEvent.Success: #if UNITY_IOS IGHapticFeedback.NotificationOccurred(IGHapticFeedback.NotificationType.Success); #elif UNITY_ANDROID AGVibrator.Vibrate(VibrationEffect.CreateWaveForm(success_pattern, success_amplitude, -1)); #endif break; } }