コード例 #1
0
        private void InteractionManager_SourceUpdated(UnityEngine.XR.WSA.Input.InteractionSourceState hand)
        {
            // Only display hand indicators when we are in a holding state, since hands going out of view will affect any active gestures.
            if (!hand.selectPressed)
            {
                return;
            }

            // Only track a new hand if are not currently tracking a hand.
            if (!currentlyTrackedHand.HasValue)
            {
                currentlyTrackedHand = hand.source.id;
            }
            else if (currentlyTrackedHand.Value != hand.source.id)
            {
                // This hand is not the currently tracked hand, do not drawn a guidance indicator for this hand.
                return;
            }

            // Start showing an indicator to move your hand toward the center of the view.
            if (hand.properties.sourceLossRisk > HandGuidanceThreshold)
            {
                ShowHandGuidanceIndicator(hand);
            }
            else
            {
                HideHandGuidanceIndicator(hand);
            }
        }
コード例 #2
0
        private void InteractionManager_SourceReleasedCallback(UnityEngine.XR.WSA.Input.InteractionSourceReleasedEventArgs eventArgs)
        {
            UnityEngine.XR.WSA.Input.InteractionSourceState state = eventArgs.state;
            AFocuser focuser = GetFocuserForSource(state.source.kind);

            OnReleasedEvent(focuser);
        }
コード例 #3
0
 private void RemoveTrackedHand(UnityEngine.XR.WSA.Input.InteractionSourceState hand)
 {
     // Only remove a hand if we are currently tracking a hand, and the hand to remove matches this tracked hand.
     if (currentlyTrackedHand.HasValue && currentlyTrackedHand.Value == hand.source.id)
     {
         // Remove a hand by hiding the guidance indicator and nulling out the currentlyTrackedHand field.
         handGuidanceIndicatorGameObject.SetActive(false);
         currentlyTrackedHand = null;
     }
 }
コード例 #4
0
        private void GetIndicatorPositionAndRotation(UnityEngine.XR.WSA.Input.InteractionSourceState hand, out Vector3 position, out Quaternion rotation)
        {
            // Update the distance from IndicatorParent based on the user's hand's distance from the center of the view.
            // Bound this distance by this maxDistanceFromCenter field, in meters.
            const float maxDistanceFromCenter = 0.3f;
            float       distanceFromCenter    = (float)(hand.properties.sourceLossRisk * maxDistanceFromCenter);

            // Subtract direction from origin so that the indicator is between the hand and the origin.
            position = Cursor.transform.position - hand.properties.sourceLossMitigationDirection * distanceFromCenter;
            rotation = Quaternion.LookRotation(Camera.main.transform.forward, hand.properties.sourceLossMitigationDirection);
        }
コード例 #5
0
        private void HideHandGuidanceIndicator(UnityEngine.XR.WSA.Input.InteractionSourceState hand)
        {
            if (!currentlyTrackedHand.HasValue)
            {
                return;
            }

            if (handGuidanceIndicatorGameObject != null)
            {
                handGuidanceIndicatorGameObject.SetActive(false);
            }
        }
コード例 #6
0
        /// <summary>
        /// Update the source data for the currently detected sources.
        /// </summary>
        private void UpdateSourceData()
        {
            // Poll for updated reading from hands
            UnityEngine.XR.WSA.Input.InteractionSourceState[] sourceStates = UnityEngine.XR.WSA.Input.InteractionManager.GetCurrentReading();
            if (sourceStates != null)
            {
                for (var i = 0; i < sourceStates.Length; ++i)
                {
                    UnityEngine.XR.WSA.Input.InteractionSourceState handSource = sourceStates[i];
                    SourceData sourceData = GetOrAddSourceData(handSource.source);
                    currentSources.Add(handSource.source.id);

                    UpdateSourceState(handSource, sourceData);
                }
            }
        }
コード例 #7
0
        private void ShowHandGuidanceIndicator(UnityEngine.XR.WSA.Input.InteractionSourceState hand)
        {
            if (!currentlyTrackedHand.HasValue)
            {
                return;
            }

            // Get the position and rotation of the hand guidance indicator and display the indicator object.
            if (handGuidanceIndicatorGameObject != null)
            {
                Vector3    position;
                Quaternion rotation;
                GetIndicatorPositionAndRotation(hand, out position, out rotation);

                handGuidanceIndicatorGameObject.transform.position = position;
                handGuidanceIndicatorGameObject.transform.rotation = rotation * defaultHandGuidanceRotation;
                handGuidanceIndicatorGameObject.SetActive(true);
            }
        }
コード例 #8
0
        /// <summary>
        /// Updates the source positional information.
        /// </summary>
        /// <param name="interactionSource">Interaction source to use to update the position.</param>
        /// <param name="sourceData">SourceData structure to update.</param>
        private void UpdateSourceState(UnityEngine.XR.WSA.Input.InteractionSourceState interactionSource, SourceData sourceData)
        {
            // Update source position
            Vector3 sourcePosition;

            if (interactionSource.sourcePose.TryGetPosition(out sourcePosition))
            {
                sourceData.HasPosition    = true;
                sourceData.SourcePosition = sourcePosition;
            }

            // Check for source presses
            if (interactionSource.selectPressed != sourceData.IsSourceDownPending)
            {
                sourceData.IsSourceDownPending    = interactionSource.selectPressed;
                sourceData.SourceStateUpdateTimer = SourcePressDelay;
            }

            // Source presses are delayed to mitigate issue with hand position shifting during air tap
            sourceData.SourceStateChanged = false;
            if (sourceData.SourceStateUpdateTimer >= 0)
            {
                float deltaTime = UseUnscaledTime
                    ? Time.unscaledDeltaTime
                    : Time.deltaTime;

                sourceData.SourceStateUpdateTimer -= deltaTime;
                if (sourceData.SourceStateUpdateTimer < 0)
                {
                    sourceData.IsSourceDown       = sourceData.IsSourceDownPending;
                    sourceData.SourceStateChanged = true;
                }
            }

            SendSourceStateEvents(sourceData);
        }
コード例 #9
0
 private void InteractionManager_SourceLost(UnityEngine.XR.WSA.Input.InteractionSourceState hand)
 {
     // Stop displaying the guidance indicator when the user's hand leaves the view.
     RemoveTrackedHand(hand);
 }
コード例 #10
0
 private void InteractionManager_SourceReleased(UnityEngine.XR.WSA.Input.InteractionSourceState hand)
 {
     // Stop displaying the guidance indicator when the user releases their finger from the pressed state.
     RemoveTrackedHand(hand);
 }
コード例 #11
0
        private void InteractionManager_SourcePressedCallback(UnityEngine.XR.WSA.Input.InteractionSourceState state)
        {
            AFocuser focuser = GetFocuserForSource(state.source.kind);

            OnPressedEvent(focuser);
        }