SHARE
TWEET

Untitled

a guest Jan 16th, 2019 99 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using UnityEngine;
  2. using System.Collections;
  3. using System;
  4. using System.Collections.Generic;
  5. using Oculus.Avatar;
  6.  
  7. public class AvatarCustomDriver : OvrAvatarDriver
  8. {
  9.    
  10.     ControllerPose GetMalibuControllerPose(OVRInput.Controller controller)
  11.     {
  12.         ovrAvatarButton buttons = 0;
  13.         if (OVRInput.Get(OVRInput.Button.PrimaryIndexTrigger, controller)) buttons |= ovrAvatarButton.One;
  14.  
  15.         return new ControllerPose
  16.         {
  17.             buttons = buttons,
  18.             touches = OVRInput.Get(OVRInput.Touch.PrimaryTouchpad) ? ovrAvatarTouch.One : 0,
  19.             joystickPosition = OVRInput.Get(OVRInput.Axis2D.PrimaryTouchpad, controller),
  20.             indexTrigger = 0f,
  21.             handTrigger = 0f,
  22.             isActive = (OVRInput.GetActiveController() & controller) != 0,
  23.         };
  24.     }
  25.  
  26.     float voiceAmplitude = 0.0f;
  27.     ControllerPose GetControllerPose(OVRInput.Controller controller)
  28.     {
  29.         ovrAvatarButton buttons = 0;
  30.         if (OVRInput.Get(OVRInput.Button.One, controller)) buttons |= ovrAvatarButton.One;
  31.         if (OVRInput.Get(OVRInput.Button.Two, controller)) buttons |= ovrAvatarButton.Two;
  32.         if (OVRInput.Get(OVRInput.Button.Start, controller)) buttons |= ovrAvatarButton.Three;
  33.         if (OVRInput.Get(OVRInput.Button.PrimaryThumbstick, controller)) buttons |= ovrAvatarButton.Joystick;
  34.  
  35.         ovrAvatarTouch touches = 0;
  36.         if (OVRInput.Get(OVRInput.Touch.One, controller)) touches |= ovrAvatarTouch.One;
  37.         if (OVRInput.Get(OVRInput.Touch.Two, controller)) touches |= ovrAvatarTouch.Two;
  38.         if (OVRInput.Get(OVRInput.Touch.PrimaryThumbstick, controller)) touches |= ovrAvatarTouch.Joystick;
  39.         if (OVRInput.Get(OVRInput.Touch.PrimaryThumbRest, controller)) touches |= ovrAvatarTouch.ThumbRest;
  40.         if (OVRInput.Get(OVRInput.Touch.PrimaryIndexTrigger, controller)) touches |= ovrAvatarTouch.Index;
  41.         if (!OVRInput.Get(OVRInput.NearTouch.PrimaryIndexTrigger, controller)) touches |= ovrAvatarTouch.Pointing;
  42.         if (!OVRInput.Get(OVRInput.NearTouch.PrimaryThumbButtons, controller)) touches |= ovrAvatarTouch.ThumbUp;
  43.  
  44.         return new ControllerPose
  45.         {
  46.             buttons = buttons,
  47.             touches = touches,
  48.             joystickPosition = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick, controller),
  49.             indexTrigger = OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTrigger, controller),
  50.             handTrigger = OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger, controller),
  51.             isActive = (OVRInput.GetActiveController() & controller) != 0,
  52.         };
  53.     }
  54.  
  55.     private void CalculateCurrentPose()
  56.     {
  57. #if UNITY_2017_2_OR_NEWER
  58.         Vector3 headPos = UnityEngine.XR.InputTracking.GetLocalPosition(UnityEngine.XR.XRNode.CenterEye);
  59. #else
  60.         Vector3 headPos = UnityEngine.VR.InputTracking.GetLocalPosition(UnityEngine.VR.VRNode.CenterEye);
  61. #endif
  62.         bool isTrackedRemote = GetIsTrackedRemote();
  63.  
  64.         if (isTrackedRemote)
  65.         {
  66.  
  67. #if UNITY_ANDROID && !UNITY_EDITOR
  68.            
  69.             headPos.y += Core.GameSettings.Instance.OculusGoPlayerHeightOffset;
  70. #endif
  71.             CurrentPose = new PoseFrame
  72.             {
  73.                 voiceAmplitude = voiceAmplitude,
  74.                 headPosition = headPos,
  75. #if UNITY_2017_2_OR_NEWER
  76.                 headRotation = UnityEngine.XR.InputTracking.GetLocalRotation(UnityEngine.XR.XRNode.CenterEye),
  77. #else
  78.                 headRotation = UnityEngine.VR.InputTracking.GetLocalRotation(UnityEngine.VR.VRNode.CenterEye),
  79. #endif
  80.                 handLeftPosition = OVRInput.GetLocalControllerPosition(OVRInput.Controller.LTrackedRemote),
  81.                 handLeftRotation = OVRInput.GetLocalControllerRotation(OVRInput.Controller.LTrackedRemote),
  82.                 handRightPosition = OVRInput.GetLocalControllerPosition(OVRInput.Controller.RTrackedRemote),
  83.                 handRightRotation = OVRInput.GetLocalControllerRotation(OVRInput.Controller.RTrackedRemote),
  84.                 controllerLeftPose = GetMalibuControllerPose(OVRInput.Controller.LTrackedRemote),
  85.                 controllerRightPose = GetMalibuControllerPose(OVRInput.Controller.RTrackedRemote),
  86.             };
  87.         }
  88.         else
  89.         {
  90.             CurrentPose = new PoseFrame
  91.             {
  92.                 voiceAmplitude = voiceAmplitude,
  93.                 headPosition = headPos,
  94. #if UNITY_2017_2_OR_NEWER
  95.                 headRotation = UnityEngine.XR.InputTracking.GetLocalRotation(UnityEngine.XR.XRNode.CenterEye),
  96. #else
  97.                 headRotation = UnityEngine.VR.InputTracking.GetLocalRotation(UnityEngine.VR.VRNode.CenterEye),
  98. #endif
  99.                 handLeftPosition = OVRInput.GetLocalControllerPosition(OVRInput.Controller.LTouch),
  100.                 handLeftRotation = OVRInput.GetLocalControllerRotation(OVRInput.Controller.LTouch),
  101.                 handRightPosition = OVRInput.GetLocalControllerPosition(OVRInput.Controller.RTouch),
  102.                 handRightRotation = OVRInput.GetLocalControllerRotation(OVRInput.Controller.RTouch),
  103.                 controllerLeftPose = GetControllerPose(OVRInput.Controller.LTouch),
  104.                 controllerRightPose = GetControllerPose(OVRInput.Controller.RTouch),
  105.             };
  106.         }
  107.  
  108.     }
  109.  
  110.     public override void UpdateTransforms(IntPtr sdkAvatar)
  111.     {
  112.         CalculateCurrentPose();
  113.         UpdateTransformsFromPose(sdkAvatar);
  114.     }
  115. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top