public static HapticSequence ClickStorm() { HapticSequence seq = new HapticSequence(); HapticEffect eff = new HapticEffect(Effect.Double_Click, .0f); seq.AddEffect(0, eff); eff = new HapticEffect(Effect.Click, .0f); seq.AddEffect(0.1, eff); eff = new HapticEffect(Effect.Click, .0f); seq.AddEffect(0.2, eff); eff = new HapticEffect(Effect.Double_Click, .0f); seq.AddEffect(0.3, eff); eff = new HapticEffect(Effect.Triple_Click, .0f); seq.AddEffect(0.4, eff); eff = new HapticEffect(Effect.Double_Click, .0f); seq.AddEffect(0.5, eff); eff = new HapticEffect(Effect.Click, .0f); seq.AddEffect(0.6, eff); eff = new HapticEffect(Effect.Triple_Click, .0f); seq.AddEffect(0.7, eff); return(seq); }
/// <summary> /// Creating a randomized code sequence is totally doable. /// This is a less than ideal approach (because static method) /// In your code you shouldn't use a static method like this (Do as I say, not as I do) /// </summary> /// <param name="randSeed">Hand in a random seed (or better yet, don't use random in static functions</param> /// <returns>A HapticSequence reference for use in Impulses</returns> public static HapticSequence RandomPulses(int randSeed) { //Debug.Log(randSeed + "\n"); System.Random rand = new System.Random(randSeed); HapticSequence seq = new HapticSequence(); float dur = ((float)rand.Next(0, 15)) / 10; float delay = ((float)rand.Next(0, 10)) / 20; HapticEffect eff = new HapticEffect(Effect.Pulse, dur); seq.AddEffect(0.0, ((float)rand.Next(0, 10)) / 10, eff); float offset = dur; dur = ((float)rand.Next(0, 15)) / 20; delay = ((float)rand.Next(0, 8)) / 20; //Debug.Log(dur + "\n"); eff = new HapticEffect(Effect.Pulse, dur); seq.AddEffect(offset + delay, ((float)rand.Next(0, 10)) / 10, eff); offset = dur; dur = ((float)rand.Next(0, 15)) / 20; delay = ((float)rand.Next(0, 8)) / 20; //Debug.Log(dur + "\n"); eff = new HapticEffect(Effect.Pulse, dur); seq.AddEffect(offset + delay, ((float)rand.Next(0, 10)) / 10, eff); return(seq); }
/// <summary> /// A VERY random effect. More just for showing haptic varion /// </summary> /// <param name="randSeed"></param> /// <returns></returns> public static HapticSequence VeryRandomEffect(int randSeed) { //Debug.Log(randSeed + "\n"); System.Random rand = new System.Random(randSeed); HapticSequence seq = new HapticSequence(); int effIndex = rand.Next(0, SuitImpulseDemo.effectOptions.Length); float dur = ((float)rand.Next(0, 6)) / 3; float delay = 0; float offset = 0; HapticEffect eff = null; int HowManyEffects = rand.Next(2, 11); //Debug.Log("How many effects: " + HowManyEffects + "\n"); for (int i = 0; i < HowManyEffects; i++) { effIndex = rand.Next(0, SuitImpulseDemo.effectOptions.Length); dur = ((float)rand.Next(0, 6)) / 3; delay = ((float)rand.Next(0, 8)) / 20; eff = new HapticEffect(SuitImpulseDemo.effectOptions[effIndex], dur); seq.AddEffect(offset + delay, ((float)rand.Next(0, 10)) / 10, eff); offset = dur; } return(seq); }
public void Vibrate(HapticEffect effect) { if (finalMode == true) { if (effect == HapticEffect.ESCAPE_DEATH) { finalMode = false; } else if (effect != HapticEffect.APPROACH_DEATH && effect != HapticEffect.APPROACH_DEATH_CLOSE) { return; } } if (effect == HapticEffect.APPROACH_DEATH || effect == HapticEffect.APPROACH_DEATH_CLOSE) { finalMode = true; } HapticEffectSettings retreivedSettings = GetEffectSettings(effect); if (!retreivedSettings.isEnabled) { return; } if (currentRoutine != null) { StopCoroutine(currentRoutine); V(0); } currentRoutine = StartCoroutine(VibrateTime(retreivedSettings.delay, retreivedSettings.length, retreivedSettings.strength)); }
/// <summary> /// Feedback the specified effect and mode. /// </summary> /// <param name="effect">Effect.</param> /// <param name="mode">Mode.</param> public static void Feedback(HapticEffect effect, KeyClicks mode = KeyClicks.Default) { if (mode == KeyClicks.Off) { return; } Service?.Feedback(effect, mode); }
public static HapticSequence ClickHum() { HapticSequence seq = new HapticSequence(); HapticEffect eff = new HapticEffect(Effect.Click, 0.0f); seq.AddEffect(0, eff); eff = new HapticEffect(Effect.Hum, .2f); seq.AddEffect(.15, 0.5f, eff); return(seq); }
public static HapticSequence ThockClunk() { HapticSequence seq = new HapticSequence(); HapticEffect eff = new HapticEffect(Effect.Click, 0.15f); seq.AddEffect(0, eff); eff = new HapticEffect(Effect.Fuzz, .2f); seq.AddEffect(.15, eff); return(seq); }
private HapticEffectSettings GetEffectSettings(HapticEffect effect) { foreach (HapticEffectSettings effectSetting in effectSettings) { if (effectSetting.effect == effect) { return(effectSetting); } } return(new HapticEffectSettings()); }
public static HapticSequence DoubleClickImpact() { HapticSequence seq = new HapticSequence(); HapticEffect eff = new HapticEffect(Effect.Double_Click, 0.00f); seq.AddEffect(0, eff); eff = new HapticEffect(Effect.Buzz, .05f); seq.AddEffect(.05, eff); eff = new HapticEffect(Effect.Buzz, .10f); seq.AddEffect(.10, 0.6f, eff); eff = new HapticEffect(Effect.Buzz, .15f); seq.AddEffect(.2, 0.2f, eff); return(seq); }
public static HapticSequence TripleClickFuzzFalloff() { HapticSequence seq = new HapticSequence(); HapticEffect eff = new HapticEffect(Effect.Triple_Click, 0.20f); seq.AddEffect(0.0, 0.7f, eff); eff = new HapticEffect(Effect.Fuzz, .20f); seq.AddEffect(0.2, eff); eff = new HapticEffect(Effect.Fuzz, .20f); seq.AddEffect(0.4, 0.5f, eff); return(seq); }
public static HapticSequence PulseBumpPulse() { HapticSequence seq = new HapticSequence(); HapticEffect eff = new HapticEffect(Effect.Pulse, 0.40f); seq.AddEffect(0.0, 0.7f, eff); eff = new HapticEffect(Effect.Bump, .0f); seq.AddEffect(0.40, eff); eff = new HapticEffect(Effect.Pulse, 0.0f); seq.AddEffect(0.55, 0.2f, eff); return(seq); }
//todo: reimplement all these as assets public static HapticSequence ClickHumDoubleClick() { HapticSequence seq = new HapticSequence(); HapticEffect eff = new HapticEffect(Effect.Click); seq.AddEffect(0, eff); // eff = new HapticEffect("transition_hum", .50f, 1.0f); seq.AddEffect(0.10, eff); eff = new HapticEffect(Effect.Double_Click); seq.AddEffect(0.6, eff); return(seq); }
override public void OnInspectorGUI() { HapticEffect HE = (HapticEffect)target; if (HE.gameObject.gameObject.GetComponent <Collider>() == null) { EditorGUILayout.LabelField("*********************************************************"); EditorGUILayout.LabelField(" Haptic Effect must be assigned to an object with a collider."); EditorGUILayout.LabelField("*********************************************************"); } else { HE.effectType = (HapticEffect.EFFECT_TYPE)EditorGUILayout.EnumPopup("Effect Type", HE.effectType); switch (HE.effectType) { case HapticEffect.EFFECT_TYPE.CONSTANT: HE.Direction = EditorGUILayout.Vector3Field("Direction", HE.Direction); HE.Magnitude = EditorGUILayout.Slider("Magnitude", (float)HE.Magnitude, 0.0f, 1.0f); break; case HapticEffect.EFFECT_TYPE.FRICTION: HE.Gain = EditorGUILayout.Slider("Gain", (float)HE.Gain, 0.0f, 1.0f); HE.Magnitude = EditorGUILayout.Slider("Magnitude", (float)HE.Magnitude, 0.0f, 1.0f); break; case HapticEffect.EFFECT_TYPE.SPRING: HE.Gain = EditorGUILayout.Slider("Gain", (float)HE.Gain, 0.0f, 1.0f); HE.Magnitude = EditorGUILayout.Slider("Magnitude", (float)HE.Magnitude, 0.0f, 1.0f); HE.Position = EditorGUILayout.Vector3Field("Position", HE.Position); break; case HapticEffect.EFFECT_TYPE.VIBRATE: HE.Gain = EditorGUILayout.Slider("Gain", (float)HE.Gain, 0.0f, 1.0f); HE.Magnitude = EditorGUILayout.Slider("Magnitude", (float)HE.Magnitude, 0.0f, 1.0f); HE.Frequency = EditorGUILayout.Slider("Frequency", (float)HE.Frequency, 1.0f, 1000.0f); HE.Direction = EditorGUILayout.Vector3Field("Direction", HE.Direction); break; case HapticEffect.EFFECT_TYPE.VISCOUS: HE.Gain = EditorGUILayout.Slider("Gain", (float)HE.Gain, 0.0f, 1.0f); HE.Magnitude = EditorGUILayout.Slider("Magnitude", (float)HE.Magnitude, 0.0f, 1.0f); break; } } }
public void Feedback(HapticEffect effect, KeyClicks mode = KeyClicks.Default) { var soundEnabled = (mode & KeyClicks.On) > 0; if (mode == KeyClicks.Default) { soundEnabled = (Forms9Patch.Settings.KeyClicks & KeyClicks.On) > 0; if (Forms9Patch.Settings.KeyClicks == KeyClicks.Default) { soundEnabled = Android.Provider.Settings.System.GetInt(Android.App.Application.Context.ContentResolver, Android.Provider.Settings.System.SoundEffectsEnabled) != 0; //vibeEnabled = Android.Provider.Settings.System.GetInt(Android.App.Application.Context.ContentResolver, Android.Provider.Settings.System.HapticFeedbackEnabled) != 0; } } var permission = Android.App.Application.Context.CheckCallingOrSelfPermission("android.permission.VIBRATE"); if (_vibrator != null && permission == Permission.Granted && Android.Provider.Settings.System.GetInt(Android.App.Application.Context.ContentResolver, Android.Provider.Settings.System.HapticFeedbackEnabled) != 0) { _vibrator.Vibrate(10); } if (_audio != null && soundEnabled) { SoundEffect sound = SoundEffect.KeyClick; switch (effect) { case HapticEffect.None: return; case HapticEffect.KeyClick: break; case HapticEffect.Return: sound = SoundEffect.Return; break; case HapticEffect.Delete: sound = SoundEffect.Delete; break; } _audio.PlaySoundEffect(sound); } }
/// <summary> /// Shoots the player body somewhere with a simple buzz emanation impulse. /// </summary> /// <param name="ShotWhere">Self explanator. DO NOT PROVIDE MULTIPLE AREAS.</param> /// <returns>Don't forget to call .Play() on the returned Impulse to create an instance of the haptic effect it defines.</returns> public static ImpulseGenerator.Impulse DesertOfDangerShot(AreaFlag ShotWhere = AreaFlag.Chest_Right) { HapticSequence seq = new HapticSequence(); //This will be slightly different then the default Effect.Buzz effect Impulse. If you ask for an effect with a duration of 0, it'll play the natural duration. //Natural durations range from .05s (click, buzz, etc) to .25s (the multiple click families) //So by providing a duration of .1, this will be slightly different than the line: // HapticEffect eff = new HapticEffect(Effect.Buzz, 0.00f, 1.0f); HapticEffect eff = new HapticEffect(Effect.Buzz, 0.10f); seq.AddEffect(0, eff); //The Desert of Danger demo set the entire impulse duration to .25s, //this means that it emanated out from where the playerwas hit. return(ImpulseGenerator.BeginEmanatingEffect(ShotWhere) .WithEffect(seq) .WithDuration(.25f)); }
/// <summary> /// This is the Impulse that was used for the Desert of Danger recoil effect. /// It is imperfect in the implementation because it doesn't allow for flexibility to pick the effect. /// It could also take a more flexible Duration component but the core here is to give you what we used. /// Use ImpulseGenerator.CreateImpulse() function instead of modifying this. /// This sample does work. /// </summary> /// <param name="StartLocation">Pick the location to begin. DO NOT PROVIDE MULTIPLE AREAS.</param> /// <param name="EndLocation">Pick the destination to reach. DO NOT PROVIDE MULTIPLE AREAS.</param> /// <returns>Don't forget to call .Play() on the returned Impulse to create an instance of the haptic effect it defines.</returns> public static ImpulseGenerator.Impulse DesertOfDangerRecoil(AreaFlag StartLocation = AreaFlag.Forearm_Left, AreaFlag EndLocation = AreaFlag.Upper_Arm_Left) { //A simple code sequence HapticSequence seq = new HapticSequence(); //The elements we will add HapticEffect eff = new HapticEffect(Effect.Buzz, 0.00f); HapticEffect eff2 = new HapticEffect(Effect.Buzz, 0.15f); //The time stamps of the different effects. seq.AddEffect(0, 1.0, eff); seq.AddEffect(.1, 0.5, eff2); //In Desert of Danger, we used a duration of .1 seconds. This means the recoil effect took .1 seconds to hit ALL pads it aimed to. If you hand in different pads, it'll likely want a longer duration. //Since we only used the forearm and the upper arm, .1s is more than sufficient. //We could've used a file for this, but this was right as we were conceptualizing and beginning the usage of the ImpulseGenerator. return(ImpulseGenerator.BeginTraversingImpulse(StartLocation, EndLocation) .WithDuration(.10f) .WithEffect(seq)); }
public static HapticSequence Shimmer() { HapticSequence seq = new HapticSequence(); HapticEffect eff = new HapticEffect(Effect.Double_Click); //This is from the NS.DoD.Shimmer.sequence reimplemented as HapticSequence. this is because we don't yet have HapticSequence+File Sequence cross use. //{ "time" : 0.0, "effect" : "transition_hum", "strength" : 0.1, "duration" : 0.05}, //{ "time" : 0.05, "effect" : Effect.Hum, "strength" : 0.1, "duration" : 0.1}, //{ "time" : 0.15, "effect" : Effect.Hum, "strength" : 0.5, "duration" : 0.1}, //{ "time" : 0.25, "effect" : Effect.Hum, "strength" : 0.1, "duration" : 0.1} //Todo: new api, now we do have cross use // seq.AddEffect(0, eff); //eff = new HapticEffect("transition_hum", 0.05f, 0.1f); seq.AddEffect(.05, eff); eff = new HapticEffect(Effect.Hum, .1f); seq.AddEffect(.15, 0.1f, eff); eff = new HapticEffect(Effect.Hum, .1f); seq.AddEffect(.25, .5f, eff); return(seq); }
/// <summary> /// Creating a randomized code sequence is totally doable. /// This is a less than ideal approach (because static method) /// In your code you shouldn't use a static method like this (Do as I say, not as I do) /// This one is about picking three effects at random (with random strength levels as well) /// </summary> /// <param name="randSeed">Hand in a random seed (or better yet, don't use random in static functions</param> /// <returns>A HapticSequence reference for use in Impulses</returns> public static HapticSequence ThreeRandomEffects(int randSeed) { //Debug.Log(randSeed + "\n"); System.Random rand = new System.Random(randSeed); HapticSequence seq = new HapticSequence(); int effIndex = rand.Next(0, SuitImpulseDemo.effectOptions.Length); HapticEffect eff = new HapticEffect(SuitImpulseDemo.effectOptions[effIndex], 0.0f); seq.AddEffect(0.0, ((float)rand.Next(2, 10)) / 10, eff); effIndex = rand.Next(0, SuitImpulseDemo.effectOptions.Length); eff = new HapticEffect(SuitImpulseDemo.effectOptions[effIndex], 0.0f); seq.AddEffect(.20f, ((float)rand.Next(2, 10)) / 10, eff); effIndex = rand.Next(0, SuitImpulseDemo.effectOptions.Length); eff = new HapticEffect(SuitImpulseDemo.effectOptions[effIndex], 0.0f); seq.AddEffect(.4f, ((float)rand.Next(2, 10)) / 10, eff); return(seq); }
/// <summary> /// Feedback the specified effect and mode. /// </summary> /// <param name="effect">Effect.</param> /// <param name="mode">Mode.</param> public void Feedback(HapticEffect effect, KeyClicks mode = KeyClicks.Default) { var soundEnabled = (mode & KeyClicks.On) > 0; if (mode == KeyClicks.Default) { soundEnabled = (Forms9Patch.Settings.KeyClicks & KeyClicks.On) > 0; if (Forms9Patch.Settings.KeyClicks == KeyClicks.Default) { // this no longer works and there doesn't appear to be a way to detect if keyclicks is on //var type = CFPreferences.CurrentApplication; CFPreferences.AppSynchronize("/var/mobile/Library/Preferences/com.apple.preferences.sounds"); soundEnabled = CFPreferences.GetAppBooleanValue("keyboard", "/var/mobile/Library/Preferences/com.apple.preferences.sounds"); } } if (soundEnabled) { switch (effect) { case HapticEffect.None: break; case HapticEffect.KeyClick: click.PlaySystemSoundAsync(); break; case HapticEffect.Return: modifier.PlaySystemSoundAsync(); break; case HapticEffect.Delete: delete.PlaySystemSoundAsync(); break; } } }
/// <summary> /// Creates a new instance of a haptic effect. /// </summary> /// <param name="effect">The effect.</param> /// <returns>The effect instance.</returns> public HapticEffectInstance NewEffect(HapticEffect effect) { var nativeEffect = effect.ToNative(); return(HapticEffectInstance.IndexToInstance(Pointer, Native.CheckError(Native.SDL_HapticNewEffect(Pointer, in nativeEffect)))); }
/// <summary> /// Determines whether the effect is supported. /// </summary> /// <param name="effect">The effect.</param> /// <returns>Whether the effect is supported.</returns> public bool EffectSupported(HapticEffect effect) { var nativeEffect = effect.ToNative(); return(Native.SDL_HapticEffectSupported(Pointer, in nativeEffect)); }
/// <summary> /// Updates the effect instance. /// </summary> /// <param name="effect">The effect to update to.</param> public void UpdateEffect(HapticEffect effect) { var nativeEffect = effect.ToNative(); _ = SdlSharp.Native.CheckError(SdlSharp.Native.SDL_HapticUpdateEffect(Native, Index, in nativeEffect)); }
public void Feedback(HapticEffect effect, EffectMode mode = EffectMode.Default) { if (mode == EffectMode.Off || effect == HapticEffect.None || !UIDevice.CurrentDevice.CheckSystemVersion(10, 0)) { return; } if (mode == EffectMode.Default && Forms9Patch.Settings.HapticEffectMode == EffectMode.Off) { return; } switch (effect) { case HapticEffect.Selection: { using (var selection = new UISelectionFeedbackGenerator()) { selection.Prepare(); selection.SelectionChanged(); } } break; case HapticEffect.LightImpact: { using (var impact = new UIImpactFeedbackGenerator(UIImpactFeedbackStyle.Light)) { impact.Prepare(); impact.ImpactOccurred(); } } break; case HapticEffect.MediumImpact: { using (var impact = new UIImpactFeedbackGenerator(UIImpactFeedbackStyle.Medium)) { impact.Prepare(); impact.ImpactOccurred(); } } break; case HapticEffect.HeavyImpact: { using (var impact = new UIImpactFeedbackGenerator(UIImpactFeedbackStyle.Heavy)) { impact.Prepare(); impact.ImpactOccurred(); } } break; case HapticEffect.ErrorNotification: { // Initialize feedback using (var notification = new UINotificationFeedbackGenerator()) { notification.Prepare(); notification.NotificationOccurred(UINotificationFeedbackType.Error); } } break; case HapticEffect.WarningNotification: { // Initialize feedback using (var notification = new UINotificationFeedbackGenerator()) { notification.Prepare(); notification.NotificationOccurred(UINotificationFeedbackType.Warning); } } break; case HapticEffect.SuccessNotification: { // Initialize feedback using (var notification = new UINotificationFeedbackGenerator()) { notification.Prepare(); notification.NotificationOccurred(UINotificationFeedbackType.Success); } } break; } }
/// <summary> /// Creates a new instance of a haptic effect. /// </summary> /// <param name="effect">The effect.</param> /// <returns>The effect instance.</returns> public HapticEffectInstance NewEffect(HapticEffect effect) { var nativeEffect = effect.ToNative(); return(HapticEffectInstance.IndexToInstance(Native, SdlSharp.Native.CheckError(SdlSharp.Native.SDL_HapticNewEffect(Native, in nativeEffect)))); }
/// <summary> /// Updates the effect instance. /// </summary> /// <param name="effect">The effect to update to.</param> public void UpdateEffect(HapticEffect effect) { var nativeEffect = effect.ToNative(); _ = Native.CheckError(Native.SDL_HapticUpdateEffect(Pointer, Index, in nativeEffect)); }
public void Feedback(HapticEffect effect, FeedbackMode mode = FeedbackMode.Default) { if (effect == HapticEffect.None || mode == FeedbackMode.Off || (mode == FeedbackMode.Default && Forms9Patch.Feedback.HapticMode == FeedbackMode.Off)) { return; } var hapticEnabled = true; if (mode == FeedbackMode.Default) { hapticEnabled = Android.Provider.Settings.System.GetInt(Android.App.Application.Context.ContentResolver, Android.Provider.Settings.System.HapticFeedbackEnabled) != 0; } if (hapticEnabled && AppEnabled) { if (effect == HapticEffect.Selection) { Settings.Activity.Window.DecorView.PerformHapticFeedback(Android.Views.FeedbackConstants.KeyboardTap); } else if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O) { VibrationEffect droidEffect = null; switch (effect) { case HapticEffect.LightImpact: droidEffect = VibrationEffect.CreateOneShot(200, 128); break; case HapticEffect.MediumImpact: droidEffect = VibrationEffect.CreateOneShot(200, 196); break; case HapticEffect.HeavyImpact: droidEffect = VibrationEffect.CreateOneShot(200, 255); break; case HapticEffect.ErrorNotification: droidEffect = VibrationEffect.CreateWaveform(new long[] { 0, 200, 100, 200, 100, 200 }, new int[] { 0, 196, 0, 196, 0, 255 }, -1); break; case HapticEffect.WarningNotification: droidEffect = VibrationEffect.CreateWaveform(new long[] { 0, 200, 100, 200 }, new int[] { 0, 196, 0, 255 }, -1); break; case HapticEffect.SuccessNotification: droidEffect = VibrationEffect.CreateWaveform(new long[] { 0, 200, 100, 200 }, new int[] { 0, 255, 0, 196 }, -1); break; case HapticEffect.Long: droidEffect = VibrationEffect.CreateOneShot(800, 255); break; } if (droidEffect != null) { _vibrator.Vibrate(droidEffect); } } else { #pragma warning disable CS0618 // Type or member is obsolete long[] pattern = null; switch (effect) { case HapticEffect.LightImpact: _vibrator.Vibrate(200, Attributes); break; case HapticEffect.MediumImpact: _vibrator.Vibrate(300, Attributes); break; case HapticEffect.HeavyImpact: _vibrator.Vibrate(400, Attributes); break; case HapticEffect.ErrorNotification: pattern = new long[] { 0, 200, 100, 200, 100, 200 }; break; case HapticEffect.WarningNotification: pattern = new long[] { 0, 200, 100, 200 }; break; case HapticEffect.SuccessNotification: pattern = new long[] { 0, 200, 100, 200 }; break; case HapticEffect.Long: _vibrator.Vibrate(800, Attributes); break; } if (pattern != null) { _vibrator.Vibrate(pattern, -1, Attributes); } #pragma warning restore CS0618 // Type or member is obsolete } } }
/// <summary> /// Determines whether the effect is supported. /// </summary> /// <param name="effect">The effect.</param> /// <returns>Whether the effect is supported.</returns> public bool EffectSupported(HapticEffect effect) { var nativeEffect = effect.ToNative(); return(SdlSharp.Native.SDL_HapticEffectSupported(Native, in nativeEffect)); }