Created
April 22, 2019 13:05
-
-
Save Adjuvant/bfeb56d4ab4bc71a1faed463f8103008 to your computer and use it in GitHub Desktop.
Way to use oculus avatars with VRTK in Unity, mobile compatible. https://forums.oculusvr.com/developer/discussion/73121/cross-platform-avatar-hands-not-activating
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 System; | |
| using System.Collections; | |
| using System.Collections.Generic; | |
| using UnityEngine; | |
| using VRTK; | |
| using UnityEngine.XR; | |
| using Oculus.Avatar; | |
| using Photon.Pun; | |
| public class AvatarCustomDriverOpenVR : OvrAvatarDriver | |
| { | |
| void Awake() | |
| { | |
| } | |
| private void Start() | |
| { | |
| #if UNITY_ANDROID | |
| try | |
| { | |
| GameObject reference = VRTK_DeviceFinder.GetControllerLeftHand(); | |
| if (reference) { | |
| reference.GetComponent<VRTK_Pointer>().enabled = false; | |
| reference.GetComponent<VRTK_UIPointer>().enabled = false; | |
| if(reference.GetComponent<InputSwitcherUI>()!=null) reference.GetComponent<InputSwitcherUI>().enabled = false; | |
| } | |
| } | |
| catch (Exception e) { | |
| Debug.LogException(e); | |
| } | |
| #endif | |
| } | |
| float voiceAmplitude = 0.0f; | |
| ControllerPose GetControllerPose() | |
| { | |
| ovrAvatarButton buttons = 0; | |
| ovrAvatarTouch touches = 0; | |
| return new ControllerPose | |
| { | |
| buttons = buttons, | |
| touches = touches, | |
| joystickPosition = Vector3.zero, | |
| indexTrigger = 0, | |
| handTrigger = 0, | |
| isActive = true, | |
| }; | |
| } | |
| private void CalculateCurrentPose() | |
| { | |
| Vector3 headPos = UnityEngine.XR.InputTracking.GetLocalPosition(UnityEngine.XR.XRNode.CenterEye); | |
| CurrentPose = new PoseFrame | |
| { | |
| voiceAmplitude = voiceAmplitude, | |
| headPosition = headPos, | |
| headRotation = UnityEngine.XR.InputTracking.GetLocalRotation(UnityEngine.XR.XRNode.CenterEye), | |
| handLeftPosition = UnityEngine.XR.InputTracking.GetLocalPosition(UnityEngine.XR.XRNode.LeftHand), | |
| handLeftRotation = UnityEngine.XR.InputTracking.GetLocalRotation(UnityEngine.XR.XRNode.LeftHand), | |
| handRightPosition = UnityEngine.XR.InputTracking.GetLocalPosition(UnityEngine.XR.XRNode.RightHand), | |
| handRightRotation = UnityEngine.XR.InputTracking.GetLocalRotation(UnityEngine.XR.XRNode.RightHand), | |
| controllerLeftPose = GetControllerPose(), | |
| controllerRightPose = GetControllerPose(), | |
| }; | |
| } | |
| public override void UpdateTransforms(IntPtr sdkAvatar) | |
| { | |
| CalculateCurrentPose(); | |
| UpdateTransformsFromPose(sdkAvatar); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment