Пример #1
0
    private void DetectTipDistance()
    {
        Frame currentFrame = provider.CurrentFrame;

        foreach (Hand hand in currentFrame.Hands)
        {
            if (hand.IsRight)
            {
                foreach (Finger finger in hand.Fingers)
                {
                    if (finger.Type == Finger.FingerType.TYPE_THUMB)
                    {
                        thumb = finger.TipPosition;
                    }
                    else if (finger.Type == Finger.FingerType.TYPE_INDEX)
                    {
                        index = finger.TipPosition;
                    }
                    else if (finger.Type == Finger.FingerType.TYPE_PINKY)
                    {
                        pinky = finger.TipPosition;
                    }
                }

                if (handRotation.RightPalmUp != true)
                {
                    rightPalmLabel.SetActive(false);
                    if (thumb.DistanceTo(index) <= 0.02f)
                    {
                        Debug.Log("LEFT-CLICK");
                        mouseControl.LeftClick();
                        StartCoroutine(DelayNextClick());
                    }
                }
                else
                {
                    rightPalmLabel.SetActive(true);
                    if (thumb.DistanceTo(index) <= 0.02f)
                    {
                        Debug.Log("RIGHT-CLICK");
                        mouseControl.RightClick();
                        StartCoroutine(DelayNextClick());
                    }
                    else if (thumb.DistanceTo(pinky) <= 0.02f)
                    {
                        Debug.Log("MIDDLE-CLICK");
                        mouseControl.MiddleClick();
                        StartCoroutine(DelayNextClick());
                    }
                }

                //GrabDragDrop(hand);
            }
        }
    }
    void Update()
    {
        if (IsWaiting == false)
        {
            if (useLeftHand == true)
            {
                if (gesture.LeftIsVisible)
                {
                    if (gesture.LeftIsFacingAway == true)
                    {
                        PalmLabel.SetActive(false);
                        if (gesture.LeftIndexPinch == true)
                        {
                            if (wasHolding == false)
                            {
                                Debug.Log("LEFT-CLICK-DOWN");
                                mouseControl.LeftDown();
                                wasHolding = true;
                            }
                        }
                        else
                        {
                            Debug.Log("LEFT-CLICK-UP");
                            mouseControl.LeftUp();
                            wasHolding = false;
                        }
                    }
                    else if (gesture.LeftIsFacingAway == false)
                    {
                        if (wasHolding == true)
                        {
                            Debug.Log("LEFT-CLICK-UP");
                            mouseControl.LeftUp();
                            wasHolding = false;
                        }
                        PalmLabel.SetActive(true);
                        if (gesture.LeftIndexPinch == true)
                        {
                            Debug.Log("RIGHT-CLICK");
                            mouseControl.RightClick();
                            StartCoroutine(DelayNextClick(1.0f));
                        }
                        else if (gesture.LeftPinkyPinch == true)
                        {
                            Debug.Log("MIDDLE-CLICK");
                            mouseControl.MiddleClick();
                            StartCoroutine(DelayNextClick(1.0f));
                        }
                    }
                }
            }
            else
            {
                if (gesture.RightIsVisible)
                {
                    if (gesture.RightIsFacingAway == true)
                    {
                        PalmLabel.SetActive(false);
                        if (gesture.RightIndexPinch == true)
                        {
                            if (wasHolding == false)
                            {
                                Debug.Log("LEFT-CLICK-DOWN");
                                mouseControl.LeftDown();
                                wasHolding = true;
                            }
                        }
                        else
                        {
                            if (wasHolding == true)
                            {
                                Debug.Log("LEFT-CLICK-UP");
                                mouseControl.LeftUp();
                                wasHolding = false;
                            }
                        }
                    }
                    else if (gesture.RightIsFacingAway == false)
                    {
                        if (wasHolding == true)
                        {
                            Debug.Log("LEFT-CLICK-UP");
                            mouseControl.LeftUp();
                            wasHolding = false;
                        }

                        PalmLabel.SetActive(true);
                        if (gesture.RightIndexPinch == true)
                        {
                            Debug.Log("RIGHT-CLICK");
                            mouseControl.RightClick();
                            StartCoroutine(DelayNextClick(1.0f));
                        }
                        else if (gesture.RightPinkyPinch == true)
                        {
                            Debug.Log("MIDDLE-CLICK");
                            mouseControl.MiddleClick();
                            StartCoroutine(DelayNextClick(1.0f));
                        }
                    }
                }
            }
        }
    }