private void InteractionManager_SourceUpdated(UnityEngine.VR.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.pressed)
            {
                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);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Fired when Interaction Manager detects a source of interaction.
        /// </summary>
        /// <param name="state">UnityEngine.VR.WSA.Input.InteractionSourceState</param>
        private void OnSourceDetected(UnityEngine.VR.WSA.Input.InteractionSourceState state)
        {
            //hand instance.
            Misc.HoloHand hand;

            //check if we alrdy stored this hand.
            if (_foundHands.ContainsKey(state.source.id))
            {
                //get hand.
                _foundHands.TryGetValue(state.source.id, out hand);

                //update hand.
                hand.Update(state);
            }
            else
            {
                //create new hand.
                hand = new Misc.HoloHand();

                //update hand.
                hand.Update(state);

                //add to hands list.
                _foundHands.Add(hand.ID, hand);
            }

            //call the delegate.
            if (OnSourceDelegate != null)
            {
                OnSourceDelegate();
            }
        }
 private void RemoveTrackedHand(UnityEngine.VR.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;
     }
 }
        private void GetIndicatorPositionAndRotation(UnityEngine.VR.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);
        }
        private void HideHandGuidanceIndicator(UnityEngine.VR.WSA.Input.InteractionSourceState hand)
        {
            if (!currentlyTrackedHand.HasValue)
            {
                return;
            }

            if (handGuidanceIndicatorGameObject != null)
            {
                handGuidanceIndicatorGameObject.SetActive(false);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Fired when an Interaction Source is updated.
        /// </summary>
        /// <param name="state">UnityEngine.VR.WSA.Input.InteractionSourceState</param>
        private void OnSourceUpdated(UnityEngine.VR.WSA.Input.InteractionSourceState state)
        {
            //check if we alrdy stored this hand.
            if (_foundHands.ContainsKey(state.source.id))
            {
                //hand instance.
                Misc.HoloHand hand;

                //get hand.
                _foundHands.TryGetValue(state.source.id, out hand);

                //update hand.
                hand.Update(state);
            }
        }
Exemplo n.º 7
0
        private void OnAirTap(UnityEngine.VR.WSA.Input.InteractionSourceState state)
        {
            // Try to intersect one of the buttons
            Vector3 hitPos, hitNormal;
            Button  hitButton;

            if (AppState.Instance.AppCursor.RayCastUI(out hitPos, out hitNormal, out hitButton) &&
                (hitButton != null))
            {
                if (hitButton.onClick != null)
                {
                    hitButton.onClick.Invoke();
                }
            }
        }
        /// <summary>
        /// Update the source data for the currently detected sources.
        /// </summary>
        private void UpdateSourceData()
        {
            // Poll for updated reading from hands
            UnityEngine.VR.WSA.Input.InteractionSourceState[] sourceStates = UnityEngine.VR.WSA.Input.InteractionManager.GetCurrentReading();
            if (sourceStates != null)
            {
                for (var i = 0; i < sourceStates.Length; ++i)
                {
                    UnityEngine.VR.WSA.Input.InteractionSourceState handSource = sourceStates[i];
                    SourceData sourceData = GetOrAddSourceData(handSource.source);
                    currentSources.Add(handSource.source.id);

                    UpdateSourceState(handSource, sourceData);
                }
            }
        }
        private void ShowHandGuidanceIndicator(UnityEngine.VR.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);
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Updates all properties
        /// </summary>
        /// <param name="state">UnityEngine.VR.WSA.Input.InteractionSourceState</param>
        public void Update(UnityEngine.VR.WSA.Input.InteractionSourceState state)
        {
            //Hand check.
            if (state.source.kind != UnityEngine.VR.WSA.Input.InteractionSourceKind.Hand)
            {
                return;
            }

            //update all variables.
            this.ID        = state.source.id;
            this.IsPressed = state.pressed;

            //get the position.
            state.properties.location.TryGetPosition(out _position);


            //get the velocity.
            state.properties.location.TryGetVelocity(out _velocity);

            //get the delta position.
            _deltaPosition = _position - _velocity;
        }
Exemplo n.º 11
0
        /// <summary>
        /// Fired when Interaction Manager loses a source of interaction.
        /// </summary>
        /// <param name="state">UnityEngine.VR.WSA.Input.InteractionSourceState</param>
        private void OnSourceLost(UnityEngine.VR.WSA.Input.InteractionSourceState state)
        {
            //check if we alrdy stored this hand.
            if (_foundHands.ContainsKey(state.source.id))
            {
                //retrieve the hand entry.
                Misc.HoloHand hand;
                _foundHands.TryGetValue(state.source.id, out hand);

                //remove entry from list.
                _foundHands.Remove(state.source.id);

                //nullify the hand.
                hand = null;
            }


            //call the delegate.
            if (OnSourceDelegate != null)
            {
                OnSourceDelegate();
            }
        }
        /// <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.VR.WSA.Input.InteractionSourceState interactionSource, SourceData sourceData)
        {
            // Update source position
            Vector3 sourcePosition;

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

            // Check for source presses
            if (interactionSource.pressed != sourceData.IsSourceDownPending)
            {
                sourceData.IsSourceDownPending    = interactionSource.pressed;
                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);
        }
 private void InteractionManager_SourceLost(UnityEngine.VR.WSA.Input.InteractionSourceState hand)
 {
     // Stop displaying the guidance indicator when the user's hand leaves the view.
     RemoveTrackedHand(hand);
 }
 private void InteractionManager_SourceReleased(UnityEngine.VR.WSA.Input.InteractionSourceState hand)
 {
     // Stop displaying the guidance indicator when the user releases their finger from the pressed state.
     RemoveTrackedHand(hand);
 }