Esempio n. 1
0
        public static void InitializeHandles()
        {
            if (!Application.isPlaying || s_actionInitialized)
            {
                return;
            }
            s_actionInitialized = true;

            InitializePaths();

            SteamVR.Initialize();
#if VIU_STEAMVR_2_2_0_OR_NEWER
            SteamVR_ActionSet_Manager.UpdateActionStates();
#elif VIU_STEAMVR_2_1_0_OR_NEWER
            SteamVR_ActionSet_Manager.UpdateActionSetsState();
#else
            SteamVR_ActionSet.UpdateActionSetsState();
#endif

            var vrInput = OpenVR.Input;
            if (vrInput == null)
            {
                Debug.LogError("Fail loading OpenVR.Input");
                return;
            }

            pressActions.InitiateHandles(vrInput);
            touchActions.InitiateHandles(vrInput);
            v1Actions.InitiateHandles(vrInput);
            v2Actions.InitiateHandles(vrInput);
            vibrateActions.InitiateHandles(vrInput);

            s_actionSetHandle = SafeGetActionSetHandle(vrInput, ACTION_SET_PATH);
        }
Esempio n. 2
0
        public static void InitializeHandles()
        {
            if (!Application.isPlaying || s_actionInitialized)
            {
                return;
            }
            s_actionInitialized = true;

            InitializePaths();

            SteamVR.Initialize();
#if VIU_STEAMVR_2_2_0_OR_NEWER
            SteamVR_ActionSet_Manager.UpdateActionStates();
#elif VIU_STEAMVR_2_1_0_OR_NEWER
            SteamVR_ActionSet_Manager.UpdateActionSetsState();
#else
            SteamVR_ActionSet.UpdateActionSetsState();
#endif

            var vrInput = OpenVR.Input;
            if (vrInput == null)
            {
                Debug.LogError("Fail loading OpenVR.Input");
                return;
            }

            pressActions.ResolveHandles(vrInput);
            touchActions.ResolveHandles(vrInput);
            v1Actions.ResolveHandles(vrInput);
            v2Actions.ResolveHandles(vrInput);
            vibrateActions.ResolveHandles(vrInput);

            s_actionSetHandle = SafeGetActionSetHandle(vrInput, ACTION_SET_PATH);

            skeletonActionHandleLeft  = SafeGetActionHandle(vrInput, ACTION_SET_PATH + "/in/viu_skeleton_left");
            skeletonActionHandleRight = SafeGetActionHandle(vrInput, ACTION_SET_PATH + "/in/viu_skeleton_right");

            if (skeletonActionHandleLeft == OpenVR.k_ulInvalidActionHandle)
            {
                Debug.LogWarning("Skeleton action for left hand is not found: " + ACTION_SET_PATH + "/in/viu_skeleton_left");
            }

            if (skeletonActionHandleRight == OpenVR.k_ulInvalidActionHandle)
            {
                Debug.LogWarning("Skeleton action for right hand is not found: " + ACTION_SET_PATH + "/in/viu_skeleton_right");
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Returns an array of positions/rotations that represent the state of each bone in a reference pose.
        /// </summary>
        /// <param name="referencePose">Which reference pose to return</param>
        public void ForceToReferencePose(EVRSkeletalReferencePose referencePose)
        {
            bool temporarySession = false;

            if (Application.isEditor && Application.isPlaying == false)
            {
                temporarySession = SteamVR.InitializeTemporarySession(true);
                Awake();

#if UNITY_EDITOR
                //gotta wait a bit for steamvr input to startup //todo: implement steamvr_input.isready
                string title     = "SteamVR";
                string text      = "Getting reference pose...";
                float  msToWait  = 3000;
                float  increment = 100;
                for (float timer = 0; timer < msToWait; timer += increment)
                {
                    bool cancel = UnityEditor.EditorUtility.DisplayCancelableProgressBar(title, text, timer / msToWait);
                    if (cancel)
                    {
                        UnityEditor.EditorUtility.ClearProgressBar();

                        if (temporarySession)
                        {
                            SteamVR.ExitTemporarySession();
                        }
                        return;
                    }
                    System.Threading.Thread.Sleep((int)increment);
                }
                UnityEditor.EditorUtility.ClearProgressBar();
#endif

                skeletonAction.actionSet.Activate();

                SteamVR_ActionSet_Manager.UpdateActionStates(true);

                skeletonAction.UpdateValueWithoutEvents();
            }

            if (skeletonAction.active == false)
            {
                Debug.LogError("<b>[SteamVR Input]</b> Please turn on your " + inputSource.ToString() + " controller and ensure SteamVR is open.");
                return;
            }

            SteamVR_Utils.RigidTransform[] transforms = skeletonAction.GetReferenceTransforms(EVRSkeletalTransformSpace.Parent, referencePose);

            if (transforms == null || transforms.Length == 0)
            {
                Debug.LogError("<b>[SteamVR Input]</b> Unable to get the reference transform for " + inputSource.ToString() + ". Please make sure SteamVR is open and both controllers are connected.");
            }

            for (int boneIndex = 0; boneIndex < transforms.Length; boneIndex++)
            {
                bones[boneIndex].localPosition = transforms[boneIndex].pos;
                bones[boneIndex].localRotation = transforms[boneIndex].rot;
            }

            if (temporarySession)
            {
                SteamVR.ExitTemporarySession();
            }
        }