-
-
Save meta-meta/0ed405ca2d5a7498587bb41ad6f02c8c to your computer and use it in GitHub Desktop.
OVR Haptics Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
/* | |
* Haptics internal update (Process()) is triggered by OVRManager, which | |
* you need to have in your scene. | |
*/ | |
public class HapticTest : MonoBehaviour { | |
private OVRHapticsClip _clip; | |
[SerializeField] private AnimationCurve _ampEnv; | |
private void Awake() { | |
Debug.Log(OVRHaptics.Config.MinimumBufferSamplesCount); // 1 | |
Debug.Log(OVRHaptics.Config.MaximumBufferSamplesCount); // 256 | |
Debug.Log(OVRHaptics.Config.OptimalBufferSamplesCount); // 20 | |
Debug.Log(OVRHaptics.Config.SampleRateHz); // 320 | |
Debug.Log(OVRHaptics.Config.SampleSizeInBytes); // 1 | |
_clip = new OVRHapticsClip(160); | |
_clip.Count = _clip.Capacity; | |
// Random clip | |
//new System.Random().NextBytes(_clip.Samples); | |
for (int i = 0; i < _clip.Capacity; i++) { | |
float val = 0.5f + 0.5f * Mathf.Sin((i / 160f) * 5f * Mathf.PI * 2f); | |
val *= _ampEnv.Evaluate(i / 160f); | |
_clip.Samples[i] = (byte) (val * 255f); | |
} | |
} | |
public void Update() { | |
if (OVRInput.GetDown(OVRInput.Button.PrimaryHandTrigger)) { | |
OVRHaptics.LeftChannel.Preempt(_clip); | |
} | |
if (OVRInput.GetDown(OVRInput.Button.SecondaryHandTrigger)) { | |
OVRHaptics.RightChannel.Preempt(_clip); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment