|
#if UNITY_EDITOR |
|
using UnityEditor; |
|
using UnityEngine; |
|
|
|
public static class OculusSDKAutomation |
|
{ |
|
|
|
private static readonly GameObject playerControllerPrefab = AssetDatabase.LoadAssetAtPath<GameObject>("Assets/Oculus/VR/Prefabs/OVRPlayerController.prefab"); |
|
|
|
private static readonly GameObject controllerPrefab = AssetDatabase.LoadAssetAtPath<GameObject>("Assets/Oculus/VR/Prefabs/OVRControllerPrefab.prefab"); |
|
|
|
private const string leftControllerAnchorPath = "OVRCameraRig/TrackingSpace/LeftHandAnchor/LeftControllerAnchor"; |
|
|
|
private const string rightControllerAnchorPath = "OVRCameraRig/TrackingSpace/RightHandAnchor/RightControllerAnchor"; |
|
|
|
[MenuItem("Oculus/Custom/Setup Player Controller")] |
|
private static void SetupPlayerController() |
|
{ |
|
|
|
var playerController = PrefabUtility.InstantiatePrefab(playerControllerPrefab) as GameObject; |
|
|
|
var characterController = playerController.GetComponent<CharacterController>(); |
|
var ovrCameraRig = playerController.GetComponentInChildren<OVRCameraRig>(); |
|
var ovrManager = playerController.GetComponentInChildren<OVRManager>(); |
|
|
|
characterController.radius = 0.25f; |
|
ovrManager.trackingOriginType = OVRManager.TrackingOrigin.FloorLevel; |
|
|
|
var characterCameraConstraint = playerController.AddComponent<CharacterCameraConstraint>(); |
|
|
|
characterCameraConstraint.CameraRig = ovrCameraRig; |
|
characterCameraConstraint.DynamicHeight = true; |
|
|
|
var leftControllerAnchor = playerController.transform.Find(leftControllerAnchorPath); |
|
var leftController = PrefabUtility.InstantiatePrefab(controllerPrefab, leftControllerAnchor) as GameObject; |
|
leftController.GetComponent<OVRControllerHelper>().m_controller = OVRInput.Controller.LTouch; |
|
var leftControllerRigidbody = leftController.AddComponent<Rigidbody>(); |
|
var leftControllerSphereCollider = leftController.AddComponent<SphereCollider>(); |
|
var leftOVRGrabber = leftController.AddComponent<OVRGrabber>(); |
|
|
|
leftControllerRigidbody.useGravity = false; |
|
leftControllerRigidbody.isKinematic = true; |
|
leftControllerSphereCollider.isTrigger = true; |
|
leftControllerSphereCollider.radius = 0.075f; |
|
|
|
var rightControllerAnchor = playerController.transform.Find(rightControllerAnchorPath); |
|
var rightController = PrefabUtility.InstantiatePrefab(controllerPrefab, rightControllerAnchor) as GameObject; |
|
rightController.GetComponent<OVRControllerHelper>().m_controller = OVRInput.Controller.RTouch; |
|
var rightControllerRigidbody = rightController.AddComponent<Rigidbody>(); |
|
var rightControllerSphereCollider = rightController.AddComponent<SphereCollider>(); |
|
var rightOVRGrabber = rightController.AddComponent<OVRGrabber>(); |
|
|
|
rightControllerRigidbody.useGravity = false; |
|
rightControllerRigidbody.isKinematic = true; |
|
rightControllerSphereCollider.isTrigger = true; |
|
rightControllerSphereCollider.radius = 0.075f; |
|
|
|
} |
|
|
|
} |
|
#endif |
Thanks! That step by step guide is the best documentation I have found on setting up grabbing with the controllers and that SDK. Tried the script, but it needs to be updated. By the way, setting the TrackingOriginType on the Camera Rig to Floor makes the auto-height calibration function properly on that SDK. That way the capsule collider doesn't need to be scaled up.
Thanks in advance if posting an update to that script. I would say "should work at Oculus", but that company is sadly gone...not going to say "should work at farsebook" to anybody I like.