/// <summary>
        /// Activate this set so its actions can be called
        /// </summary>
        /// <param name="disableAllOtherActionSets">Disable all other action sets at the same time</param>
        /// <param name="priority">The priority of this action set. If you have two actions bound to the same input (button) the higher priority set will override the lower priority. If they are the same priority both will execute.</param>
        /// <param name="activateForSource">Will activate this action set only for the specified source. Any if you want to activate for everything</param>
        public void Activate(SteamVR_Input_Sources activateForSource = SteamVR_Input_Sources.Any, int priority = 0, bool disableAllOtherActionSets = false)
        {
            int sourceIndex = (int)activateForSource;

            if (disableAllOtherActionSets)
            {
                SteamVR_ActionSet_Manager.DisableAllActionSets();
            }

            if (rawSetActive[sourceIndex] == false)
            {
                rawSetActive[sourceIndex] = true;
                SteamVR_ActionSet_Manager.SetChanged();

                rawSetLastChanged[sourceIndex] = Time.realtimeSinceStartup;
            }

            if (rawSetPriority[sourceIndex] != priority)
            {
                rawSetPriority[sourceIndex] = priority;
                SteamVR_ActionSet_Manager.SetChanged();

                rawSetLastChanged[sourceIndex] = Time.realtimeSinceStartup;
            }
        }
Ejemplo n.º 2
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();
                //skeletonAction.Initialize(true);
                //skeletonAction.actionSet.Initialize(true);

#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();
            }

            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();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Deactivate the action set so its actions can no longer be called
        /// </summary>
        public void Deactivate(SteamVR_Input_Sources forSource = SteamVR_Input_Sources.Any)
        {
            if (rawSetActive[forSource] != false)
            {
                rawSetLastChanged[forSource] = Time.realtimeSinceStartup;
                SteamVR_ActionSet_Manager.SetChanged();
            }

            rawSetActive[forSource]   = false;
            rawSetPriority[forSource] = 0;
        }
Ejemplo n.º 4
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();

                skeletonAction.actionSet.Activate();

                SteamVR_ActionSet_Manager.UpdateActionStates(true);

                skeletonAction.UpdateValueWithoutEvents();
            }

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

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

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

            if (mirroring == MirrorType.LeftToRight || mirroring == MirrorType.RightToLeft)
            {
                for (int boneIndex = 0; boneIndex < transforms.Length; boneIndex++)
                {
                    bones[boneIndex].localPosition = MirrorPosition(boneIndex, transforms[boneIndex].pos);
                    bones[boneIndex].localRotation = MirrorRotation(boneIndex, transforms[boneIndex].rot);
                }
            }
            else
            {
                for (int boneIndex = 0; boneIndex < transforms.Length; boneIndex++)
                {
                    bones[boneIndex].localPosition = transforms[boneIndex].pos;
                    bones[boneIndex].localRotation = transforms[boneIndex].rot;
                }
            }

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