Created
February 14, 2017 02:56
-
-
Save unity3dcollege/5f75e6f74df469e53024ee17fda15041 to your computer and use it in GitHub Desktop.
This file contains hidden or 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; | |
public class OculusHapticsController : MonoBehaviour | |
{ | |
[SerializeField] | |
OVRInput.Controller controllerMask; | |
private OVRHapticsClip clipLight; | |
private OVRHapticsClip clipMedium; | |
private OVRHapticsClip clipHard; | |
private void Start() | |
{ | |
InitializeOVRHaptics(); | |
} | |
private void InitializeOVRHaptics() | |
{ | |
int cnt = 10; | |
clipLight = new OVRHapticsClip(cnt); | |
clipMedium = new OVRHapticsClip(cnt); | |
clipHard = new OVRHapticsClip(cnt); | |
for (int i = 0; i < cnt; i++) | |
{ | |
clipLight.Samples[i] = i % 2 == 0 ? (byte)0 : (byte)75; | |
clipMedium.Samples[i] = i % 2 == 0 ? (byte)0 : (byte)150; | |
clipHard.Samples[i] = i % 2 == 0 ? (byte)0 : (byte)255; | |
} | |
clipLight = new OVRHapticsClip(clipLight.Samples, clipLight.Samples.Length); | |
clipMedium = new OVRHapticsClip(clipMedium.Samples, clipMedium.Samples.Length); | |
clipHard = new OVRHapticsClip(clipHard.Samples, clipHard.Samples.Length); | |
} | |
public void Vibrate(VibrationForce vibrationForce) | |
{ | |
var channel = OVRHaptics.RightChannel; | |
if (controllerMask == OVRInput.Controller.LTouch) | |
channel = OVRHaptics.LeftChannel; | |
switch (vibrationForce) | |
{ | |
case VibrationForce.Light: | |
channel.Preempt(clipLight); | |
break; | |
case VibrationForce.Medium: | |
channel.Preempt(clipMedium); | |
break; | |
case VibrationForce.Hard: | |
channel.Preempt(clipHard); | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment