Exemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        Frame frame = hc.GetFrame();

        if (!giveControlMenu.activeInHierarchy && !takeControlMenu.activeInHierarchy)
        {
            // Gesten
            GestureList gestures = frame.Gestures();
            foreach (Gesture g in gestures)
            {
                // Swipe Geste
                if (g.Type == Gesture.GestureType.TYPESWIPE)
                {
                    SwipeGesture swipeGesture   = new SwipeGesture(g);
                    Vector       swipeDirection = swipeGesture.Direction;

                    if (Mathf.Abs(swipeDirection.x) < Mathf.Abs(swipeDirection.y))
                    {
                        if (swipeDirection.y < 0)
                        {
                            // Debug.Log ("Runter");
                            if (!navigationPanel.activeInHierarchy && gamesButton.interactable == true)
                            {
                                pS.showhideNavigationPanel();
                            }
                        }
                        else if (swipeDirection.y > 0)
                        {
                            // Debug.Log ("Hoch");
                            if (navigationPanel.activeInHierarchy)
                            {
                                pS.showhideNavigationPanel();
                            }
                        }
                    }
                }
            }
        }

        if (frame.Hands.Count == 1)
        {
            // Steuerung des Cursors
            foreach (Hand hand in frame.Hands)
            {
                // Click-Gesture
                if (clickGesture(hand))
                {
                    //Debug.Log ("Click!");
                    if (mainMenu.activeInHierarchy)
                    {
                        clickedMainButton(transform.position);
                    }
                    else if (movieOne.activeInHierarchy || movieTwo.activeInHierarchy)
                    {
                        clickedButton(transform.position, "movieButtons");
                    }
                    else
                    {
                        clickedButton(transform.position, "playButton");
                    }

                    break;
                }

                // Grab-Gesture
                if (grabGesture(hand))
                {
                    // Debug.Log ("Grab!");
                    if (!mainMenu.activeInHierarchy)
                    {
                        if (musicPanel.activeInHierarchy)
                        {
                            pS.showhideMusicPanel();
                        }
                        else if (radioPanel.activeInHierarchy)
                        {
                            pS.showhideRadioPanel();
                        }
                        else if (moviePanel.activeInHierarchy)
                        {
                            pS.showhideMoviesPanel();
                        }
                        else if (movieOne.activeInHierarchy)
                        {
                            pS.showhideMovies1();
                        }
                        else if (movieTwo.activeInHierarchy)
                        {
                            pS.showhideMovies2();
                        }
                    }
                    break;
                }

                // Palm Position holen (x,y,z)
                handPosition.x = Mathf.RoundToInt(hand.PalmPosition.x);
                handPosition.y = Mathf.RoundToInt(hand.PalmPosition.y);
                // ungefähr x (-100 : 100 ) y (0 : 200) z (egal)

                // handPosition x von 0 - 200
                handPosition.x += 100;
                if (handPosition.x < 0)
                {
                    handPosition.x = 0;
                }
                if (handPosition.x > 200)
                {
                    handPosition.x = 200;
                }

                // handPosition y von 50 - 250
                if (handPosition.y < 50)
                {
                    handPosition.y = 50;
                }
                if (handPosition.y > 250)
                {
                    handPosition.y = 250;
                }
                handPosition.y -= 50;

                // relative Position der Koordinaten berechnen
                float relPositionX = ((float)handPosition.x) / leapCordSystemCap;
                float relPositionY = ((float)handPosition.y) / leapCordSystemCap;

                // Position auf dem Canvas berechnen
                int canvasPositionX = Mathf.RoundToInt(canvasWidth * relPositionX);
                int canvasPositionY = Mathf.RoundToInt(canvasHeight * relPositionY);
                //Debug.Log ("canvas x: " + canvasPositionX + ", canvas y: " + canvasPositionY);

                // Cursor an richtige Stelle verschieben
                transform.position = new Vector3(canvasPositionX, canvasPositionY, 0.0f);
            }
        }
    }