Interhaptics SDK for Unity 1.6
Loading...
Searching...
No Matches
HapticPreset.cs
Go to the documentation of this file.
1using UnityEngine;
2using System.Collections;
4
5namespace Interhaptics.Utils
6{
12 public static class HapticPreset
13 {
17 public enum PresetType
18 {
19 Selection,
20 Light,
21 Medium,
22 Heavy,
23 Rigid,
24 Soft,
25 Success,
26 Failure,
27 Warning
28 }
29
30 // Interleaved time and amplitude values for each preset.
31 // These arrays represent the time-amplitude pairs for each haptic effect.
32 private static readonly double[] selection = { 0.0, 0.471, 0.04, 0.471 };
33 private static readonly double[] light = { 0.0, 0.156, 0.04, 0.156 };
34 private static readonly double[] medium = { 0.0, 0.471, 0.08, 0.471 };
35 private static readonly double[] heavy = { 0.0, 1.0, 0.16, 1.0 };
36 private static readonly double[] rigid = { 0.0, 1.0, 0.04, 1.0 };
37 private static readonly double[] soft = { 0.0, 0.156, 0.16, 0.156 };
38 private static readonly double[] success = { 0.0, 0.0, 0.04, 0.157, 0.08, 0.0, 0.24, 1.0 };
39 private static readonly double[] failure = { 0.0, 0.0, 0.08, 0.47, 0.12, 0.0, 0.2, 0.47, 0.24, 0.0, 0.4, 1.0, 0.44, 0.0, 0.48, 0.157 };
40 private static readonly double[] warning = { 0.0, 0.0, 0.12, 1.0, 0.24, 0.0, 0.28, 0.47 };
41
47 public static void Play(PresetType presetType)
48 {
49 double[] preset = GetPreset(presetType);
50 // Initiate the haptic effect based on the retrieved preset pattern
51 HAR.Play(preset);
52 }
53
59 private static double[] GetPreset(PresetType presetType)
60 {
61 switch (presetType)
62 {
63 case PresetType.Selection: return selection;
64 case PresetType.Light: return light;
65 case PresetType.Medium: return medium;
66 case PresetType.Heavy: return heavy;
67 case PresetType.Rigid: return rigid;
68 case PresetType.Soft: return soft;
69 case PresetType.Success: return success;
70 case PresetType.Failure: return failure;
71 case PresetType.Warning: return warning;
72 default:
73 Debug.LogError("Preset type out of range.");
74 return null;
75 }
76 }
77 }
78}