Пример #1
0
    // Call these events from HandsManager. This fires when the hand is moved.
    private void InteractionManager_SourceUpdated(UnityEngine.XR.WSA.Input.InteractionSourceState hand)
    {
        // Only display hand indicators when we have targeted an interactible and the hand is in a pressed state.
        if (!hand.selectPressed ||
            HandsManager.Instance.FocusedGameObject == null ||
            (HandsManager.Instance.FocusedGameObject != null &&
             HandsManager.Instance.FocusedGameObject.GetComponent <Interactible>() == null))
        {
            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_SourceLost(UnityEngine.XR.WSA.Input.InteractionSourceState hand)
    {
        HandDetected = false;

        // 2.a: Reset FocusedGameObject.
        ResetFocusedGameObject();
    }
Пример #3
0
        private void InteractionManager_SourceDetected(UnityEngine.XR.WSA.Input.InteractionSourceState state)
        {
            // Check to see that the source is a hand.
            if (state.source.kind != UnityEngine.XR.WSA.Input.InteractionSourceKind.Hand)
            {
                return;
            }
            trackedHands.Add(state.source.id);

            var     obj = Instantiate(TrackingObject) as GameObject;
            Vector3 pos;

            if (state.sourcePose.TryGetPosition(out pos))
            {
                obj.transform.position = pos;

                var heading   = pos - PlayerPosition.position;
                var distance  = heading.magnitude;
                var direction = heading / distance; // This is now the normalized direction.

                var correctedHeading   = (pos + correction) - PlayerPosition.position;
                var correctedDistance  = correctedHeading.magnitude;
                var correctedDirection = correctedHeading / correctedDistance;

                this.lastDirection = correctedDirection;

                //Debug.DrawRay(PlayerPosition.position, lastDirection, Color.green);
                //lineRenderer.SetPosition(0, PlayerPosition.position);
                //lineRenderer.SetPosition(1, pos);
            }

            trackingObject.Add(state.source.id, obj);
        }
Пример #4
0
        private void InteractionManager_OnSourceUpdated(InteractionSourceUpdatedEventArgs obj)
        {
            UnityEngine.XR.WSA.Input.InteractionSourceState sourceState = obj.state;

            // Only display hand indicators when we are in a holding state, since hands going out of view will affect any active gestures.
            if (!sourceState.anyPressed)
            {
                return;
            }

            // Only track a new hand if are not currently tracking a hand.
            if (!currentlyTrackedHand.HasValue)
            {
                currentlyTrackedHand = sourceState.source.id;
            }
            else if (currentlyTrackedHand.Value != sourceState.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 (sourceState.properties.sourceLossRisk > HandGuidanceThreshold)
            {
                ShowHandGuidanceIndicator(sourceState);
            }
            else
            {
                HideHandGuidanceIndicator(sourceState);
            }
        }
Пример #5
0
 private void RemoveTrackedHand(UnityEngine.XR.WSA.Input.InteractionSourceState hand)
 {
     if (currentlyTrackedHand.HasValue && currentlyTrackedHand.Value == hand.source.id)
     {
         handGuidanceIndicatorGameObject.SetActive(false);
         currentlyTrackedHand = null;
     }
 }
Пример #6
0
    // This fires when the hand is lost.
    private void InteractionManager_SourceLost(UnityEngine.XR.WSA.Input.InteractionSourceState hand)
    {
        if (!currentlyTrackedHand.HasValue || currentlyTrackedHand.Value != hand.source.id)
        {
            return;
        }

        RemoveTrackedHand(hand);
    }
Пример #7
0
    private void GetIndicatorPositionAndRotation(UnityEngine.XR.WSA.Input.InteractionSourceState hand, out Vector3 position, out Quaternion rotation)
    {
        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 = IndicatorParent.transform.position - hand.properties.sourceLossMitigationDirection * distanceFromCenter;
        rotation = Quaternion.LookRotation(Camera.main.transform.forward, hand.properties.sourceLossMitigationDirection);
    }
    private void WSAFingerPressed(UnityEngine.XR.WSA.Input.InteractionSourceState state)
    {
        CurrentHandState inputState = trackedHands.Find(CurrentInputState => CurrentInputState.HandId == state.source.id);

        if (inputState != null)
        {
            UpdateFromWSASource(inputState, state);
            OnFingerPressed(inputState);
        }
    }
    private void UpdateFromWSASource(CurrentHandState currentInputState, UnityEngine.XR.WSA.Input.InteractionSourceState state)
    {
        currentInputState.HandId      = state.source.id;
        currentInputState.LastPressed = currentInputState.Pressed;
        currentInputState.Pressed     = state.anyPressed;
        state.properties.location.TryGetVelocity(out currentInputState.Velocity);

        currentInputState.SourceLossRisk = state.properties.sourceLossRisk;
        currentInputState.SourceLossMitigationDirection = state.properties.sourceLossMitigationDirection;
    }
Пример #10
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;
     }
 }
Пример #11
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);
        }
Пример #12
0
        private void HideHandGuidanceIndicator(UnityEngine.XR.WSA.Input.InteractionSourceState hand)
        {
            if (!currentlyTrackedHand.HasValue)
            {
                return;
            }

            if (handGuidanceIndicatorGameObject != null)
            {
                handGuidanceIndicatorGameObject.SetActive(false);
            }
        }
    public void WSASourceEntered(UnityEngine.XR.WSA.Input.InteractionSourceState state)
    {
        // Track Hands
        if (state.source.kind == UnityEngine.XR.WSA.Input.InteractionSourceKind.Hand)
        {
            CurrentHandState inputState = new CurrentHandState();

            state.properties.location.TryGetPosition(out inputState.Position);

            UpdateFromWSASource(inputState, state);
            SourceEntered(inputState);
        }
    }
    public void WSASourceLost(UnityEngine.XR.WSA.Input.InteractionSourceState state)
    {
        if (state.source.kind == UnityEngine.XR.WSA.Input.InteractionSourceKind.Hand)
        {
            CurrentHandState inputState = trackedHands.Find(CurrentInputState => CurrentInputState.HandId == state.source.id); // handID

            if (inputState != null)
            {
                UpdateFromWSASource(inputState, state);
                SourceLost(inputState);
            }
        }
    }
Пример #15
0
    private void OnAirTap(UnityEngine.XR.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();
            }
        }
    }
Пример #16
0
    private void InteractionManager_SourcePressed(UnityEngine.XR.WSA.Input.InteractionSourceState hand)
    {
        if (InteractibleManager.Instance.FocusedGameObject != null)
        {
            // Play a select sound if we have an audio source and are not targeting an asset with a select sound.
            if (audioSource != null && !audioSource.isPlaying &&
                (InteractibleManager.Instance.FocusedGameObject.GetComponent <Interactible>() != null &&
                 InteractibleManager.Instance.FocusedGameObject.GetComponent <Interactible>().TargetFeedbackSound == null))
            {
                audioSource.Play();
            }

            // 2.a: Cache InteractibleManager's FocusedGameObject in FocusedGameObject.
            FocusedGameObject = InteractibleManager.Instance.FocusedGameObject;
        }
    }
 public void WSASourceUpdate(UnityEngine.XR.WSA.Input.InteractionSourceState state)
 {
     if (state.source.kind == UnityEngine.XR.WSA.Input.InteractionSourceKind.Hand)
     {
         Vector3 newPosition;
         if (state.properties.location.TryGetPosition(out newPosition))
         {
             CurrentHandState inputState = trackedHands.Find(CurrentInputState => CurrentInputState.HandId == state.source.id); // handID
             if (inputState != null)
             {
                 UpdateFromWSASource(inputState, state);
                 SourceUpdate(inputState, newPosition);
             }
         }
     }
 }
Пример #18
0
    /// <summary>
    /// If this hand is being tracked, display an indicator at the hand's current position.
    /// This indicator will show what direction the user should move their hand to increase their guidance score.
    /// </summary>
    /// <param name="hand">The hand being tracked.</param>
    private void ShowHandGuidanceIndicator(UnityEngine.XR.WSA.Input.InteractionSourceState hand)
    {
        if (!currentlyTrackedHand.HasValue)
        {
            return;
        }

        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);
        }
    }
Пример #19
0
        private void InteractionManager_SourceLost(UnityEngine.XR.WSA.Input.InteractionSourceState state)
        {
            // Check to see that the source is a hand.
            if (state.source.kind != UnityEngine.XR.WSA.Input.InteractionSourceKind.Hand)
            {
                return;
            }

            if (trackedHands.Contains(state.source.id))
            {
                trackedHands.Remove(state.source.id);
            }

            if (trackingObject.ContainsKey(state.source.id))
            {
                var obj = trackingObject[state.source.id];
                trackingObject.Remove(state.source.id);
                Destroy(obj);
            }
        }
Пример #20
0
        private void InteractionManager_SourceUpdated(UnityEngine.XR.WSA.Input.InteractionSourceState state)
        {
            uint    id = state.source.id;
            Vector3 pos;

            if (state.source.kind == UnityEngine.XR.WSA.Input.InteractionSourceKind.Hand)
            {
                if (trackingObject.ContainsKey(state.source.id))
                {
                    if (state.sourcePose.TryGetPosition(out pos))
                    {
                        trackingObject[state.source.id].transform.position = pos;
                        objectToMoveByHand.transform.position = pos;


                        //var heading = pos - PlayerPosition.position;
                        var heading   = pos - PlayerPosition.position;
                        var distance  = heading.magnitude;
                        var direction = heading / distance; // This is now the normalized direction.

                        var correctedHeading   = (pos + correction) - PlayerPosition.position;
                        var correctedDistance  = correctedHeading.magnitude;
                        var correctedDirection = correctedHeading / correctedDistance;

                        this.lastDirection = correctedDirection;

                        //Debug.DrawRay(PlayerPosition.position, direction, Color.green);
                        //lineRenderer.SetPosition(0, PlayerPosition.position);
                        //lineRenderer.SetPosition(1, pos + correction);// + direction * 2.0f);

                        if (RobotAR.StateMachine.GetCurrentState() == RobotAR.State.Pick)
                        {
                        }
                    }
                }
            }
        }
Пример #21
0
        private static void OnSourceEvent(EventType eventType, ref InteractionSourceState state, InteractionSourcePressType pressType)
        {
            switch (eventType)
            {
            case EventType.SourceDetected:
            {
                var deprecatedEventHandler = InteractionSourceDetectedLegacy;
                if (deprecatedEventHandler != null)
                {
                    deprecatedEventHandler(state);
                }

                var eventHandler = InteractionSourceDetected;
                if (eventHandler != null)
                {
                    eventHandler(new InteractionSourceDetectedEventArgs(state));
                }
            }
            break;

            case EventType.SourceLost:
            {
                var deprecatedEventHandler = InteractionSourceLostLegacy;
                if (deprecatedEventHandler != null)
                {
                    deprecatedEventHandler(state);
                }

                var eventHandler = InteractionSourceLost;
                if (eventHandler != null)
                {
                    eventHandler(new InteractionSourceLostEventArgs(state));
                }
            }
            break;

            case EventType.SourceUpdated:
            {
                var deprecatedEventHandler = InteractionSourceUpdatedLegacy;
                if (deprecatedEventHandler != null)
                {
                    deprecatedEventHandler(state);
                }

                var eventHandler = InteractionSourceUpdated;
                if (eventHandler != null)
                {
                    eventHandler(new InteractionSourceUpdatedEventArgs(state));
                }
            }
            break;

            case EventType.SourcePressed:
            {
                var deprecatedEventHandler = InteractionSourcePressedLegacy;
                if (deprecatedEventHandler != null)
                {
                    deprecatedEventHandler(state);
                }

                var eventHandler = InteractionSourcePressed;
                if (eventHandler != null)
                {
                    eventHandler(new InteractionSourcePressedEventArgs(state, pressType));
                }
            }
            break;

            case EventType.SourceReleased:
            {
                var deprecatedEventHandler = InteractionSourceReleasedLegacy;
                if (deprecatedEventHandler != null)
                {
                    deprecatedEventHandler(state);
                }

                var eventHandler = InteractionSourceReleased;
                if (eventHandler != null)
                {
                    eventHandler(new InteractionSourceReleasedEventArgs(state, pressType));
                }
            }
            break;

            default:
                throw new ArgumentException("OnSourceEvent: Invalid EventType");
            }
        }
Пример #22
0
 public InteractionSourcePressedEventArgs(InteractionSourceState state, InteractionSourcePressType pressType)
 {
     this           = default(InteractionSourcePressedEventArgs);
     this.state     = state;
     this.pressType = pressType;
 }
Пример #23
0
 private void InteractionManager_SourceDetected(UnityEngine.XR.WSA.Input.InteractionSourceState hand)
 {
     HandDetected = true;
 }
Пример #24
0
 private void InteractionManager_SourceReleased(UnityEngine.XR.WSA.Input.InteractionSourceState hand)
 {
     // 2.a: Reset FocusedGameObject.
     ResetFocusedGameObject();
 }
Пример #25
0
 // This fires when the finger is released.
 private void InteractionManager_SourceReleased(UnityEngine.XR.WSA.Input.InteractionSourceState hand)
 {
     RemoveTrackedHand(hand);
 }
 private static void OnSourceEvent(InteractionManager.EventType eventType, InteractionSourceState state, InteractionSourcePressType pressType)
 {
     /*
      * switch (eventType)
      * {
      * case InteractionManager.EventType.SourceDetected:
      * {
      *      InteractionManager.SourceEventHandler interactionSourceDetectedLegacy = InteractionManager.InteractionSourceDetectedLegacy;
      *      if (interactionSourceDetectedLegacy != null)
      *      {
      *              interactionSourceDetectedLegacy(state);
      *      }
      *      Action<InteractionSourceDetectedEventArgs> interactionSourceDetected = InteractionManager.InteractionSourceDetected;
      *      if (interactionSourceDetected != null)
      *      {
      *              interactionSourceDetected(new InteractionSourceDetectedEventArgs(state));
      *      }
      *      break;
      * }
      * case InteractionManager.EventType.SourceLost:
      * {
      *      InteractionManager.SourceEventHandler interactionSourceLostLegacy = InteractionManager.InteractionSourceLostLegacy;
      *      if (interactionSourceLostLegacy != null)
      *      {
      *              interactionSourceLostLegacy(state);
      *      }
      *      Action<InteractionSourceLostEventArgs> interactionSourceLost = InteractionManager.InteractionSourceLost;
      *      if (interactionSourceLost != null)
      *      {
      *              interactionSourceLost(new InteractionSourceLostEventArgs(state));
      *      }
      *      break;
      * }
      * case InteractionManager.EventType.SourceUpdated:
      * {
      *      InteractionManager.SourceEventHandler interactionSourceUpdatedLegacy = InteractionManager.InteractionSourceUpdatedLegacy;
      *      if (interactionSourceUpdatedLegacy != null)
      *      {
      *              interactionSourceUpdatedLegacy(state);
      *      }
      *      Action<InteractionSourceUpdatedEventArgs> interactionSourceUpdated = InteractionManager.InteractionSourceUpdated;
      *      if (interactionSourceUpdated != null)
      *      {
      *              interactionSourceUpdated(new InteractionSourceUpdatedEventArgs(state));
      *      }
      *      break;
      * }
      * case InteractionManager.EventType.SourcePressed:
      * {
      *      InteractionManager.SourceEventHandler interactionSourcePressedLegacy = InteractionManager.InteractionSourcePressedLegacy;
      *      if (interactionSourcePressedLegacy != null)
      *      {
      *              interactionSourcePressedLegacy(state);
      *      }
      *      Action<InteractionSourcePressedEventArgs> interactionSourcePressed = InteractionManager.InteractionSourcePressed;
      *      if (interactionSourcePressed != null)
      *      {
      *              interactionSourcePressed(new InteractionSourcePressedEventArgs(state, pressType));
      *      }
      *      break;
      * }
      * case InteractionManager.EventType.SourceReleased:
      * {
      *      InteractionManager.SourceEventHandler interactionSourceReleasedLegacy = InteractionManager.InteractionSourceReleasedLegacy;
      *      if (interactionSourceReleasedLegacy != null)
      *      {
      *              interactionSourceReleasedLegacy(state);
      *      }
      *      Action<InteractionSourceReleasedEventArgs> interactionSourceReleased = InteractionManager.InteractionSourceReleased;
      *      if (interactionSourceReleased != null)
      *      {
      *              interactionSourceReleased(new InteractionSourceReleasedEventArgs(state, pressType));
      *      }
      *      break;
      * }
      * default:
      *      throw new ArgumentException("OnSourceEvent: Invalid EventType");
      * }
      */
 }
Пример #27
0
 public InteractionSourceUpdatedEventArgs(InteractionSourceState state) : this()
 {
     this.state = state;
 }
Пример #28
0
 public static InteractionSourceState[] GetCurrentReading()
 {
     InteractionSourceState[] sourceStates = new InteractionSourceState[numSourceStates];
     GetCurrentReading_Internal(sourceStates);
     return(sourceStates);
 }
Пример #29
0
 public InteractionSourceReleasedEventArgs(InteractionSourceState state, InteractionSourcePressType pressType) : this()
 {
     this.state     = state;
     this.pressType = pressType;
 }
Пример #30
0
 public InteractionSourceLostEventArgs(InteractionSourceState state)
 {
     this       = default(InteractionSourceLostEventArgs);
     this.state = state;
 }