Ejemplo n.º 1
0
    void holdDownForGestureMode()
    {
        Touch touch;

        if (Input.touchCount > 0)
        {
            touch = Input.GetTouch(0);                                                  // Obtain 1st finger touch

            switch (touch.phase)
            {
            case TouchPhase.Began:
                //Debug.Log ("TouchDown");
                heldDown = 0;                                                   // Reset 'finger held down' timer
                isHold   = true;                                                // Potential to be a valid hold
                startpos = touch.position;                                      // Store first touch position
                break;

            // <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <>

            case TouchPhase.Moved:
                if (!popUp)                                                             //GestureMode not open?
                {
                    Debug.Log("Moving");
                    float dist = (touch.position - startpos).magnitude;                                         // Get current touch position and start position difference
                    if (dist > maxSwipeDist)                                                                    // If touch hold moves too far...
                    {
                        isHold = false;                                                                         // Not considered as hold
                    }
                }
                else                                                                            //GestureMode is open?
                {
                    Debug.Log("GestureMode: Swipe Moving");
                    float distG = (touch.position - gestStartPos).magnitude;                        // Get swipe Distance during gesture mode
                    if (minSwipeDist > distG)                                                       // If swipe is too short...
                    {
                        couldBeSwipeG = false;                                                      // Not considered as swipe
                    }
                    else                                                                            // else...
                    {
                        couldBeSwipeG = true;                                                       // Potiential to be swipe
                    }
                }
                break;

            // <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <>

            case TouchPhase.Stationary:
                //Debug.Log ("Touch Still");
                heldDown += Time.deltaTime;                                                                     // Keep track of time of touch held down

                if (heldDown > minHoldTime && !popUp && isHold)                                                 // Touch held for ___ time?? & GestureMode not open?? & potential to be hold??
                {
                    Debug.Log("GESTURE MODE ACTIVE: (Time held: " + heldDown + ")");
                    popUp = true;                                                                                       // Open Gesture Mode Panel
                    infoBrg.setGestureModeActivity(true);                                                               // used to freeze avatar's movement
                    //Handheld.Vibrate();											// vibration feedback

                    // GestureMode variables initialization
                    gestStartPos  = (touch.position);                                                                           // Store position of touch when gesture mode activated
                    couldBeSwipeG = true;                                                                                       // Potential to be considered as swipe
                }
                break;

            // <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <>

            case TouchPhase.Ended:
                Debug.Log("Touch Released **");
                Vector2 gestSwipeDist = touch.position - gestStartPos;

                if (couldBeSwipeG && minSwipeDist < gestSwipeDist.magnitude && popUp)                   // Valid Swipe?
                {
                    if (Mathf.Abs(gestSwipeDist.x) > Mathf.Abs(gestSwipeDist.y))                        // Vertical or Horizontal Swipe?
                    {
                        Debug.Log("Horizontal Gesture Swipe");
                        if (gestSwipeDist.x > 0)                                                                // Left or Right?
                        {
                            Debug.Log("Right Swipe Action Gesture");                                            // <---Insert Gesture Action (1) Here *Right*
                            EasyTTSUtil.SpeechFlush("Right Gesture. Norbu is awesome");
                        }
                        else
                        {
                            Debug.Log("Left Swipe Action Gesture");                                             // <---Insert Gesture Action (2) Here *Left*
                            EasyTTSUtil.SpeechFlush("Left Gesture. Juan is awesome");
                        }
                    }
                    else
                    {
                        Debug.Log("Verticcal Gesture Swipe");
                        if (gestSwipeDist.y > 0)
                        {                                                                       // Up or Down?
                            Debug.Log("Up Swipe Action Gesture");                               // <---Insert Gesture Action (3) Here *Up*
                            EasyTTSUtil.SpeechFlush("Up Gesture. music on");
                            infoBrg.setMusicOfforOn(true);
                        }
                        else
                        {
                            Debug.Log("Down Swipe Action Gesture");                                             // <---Insert Gesture Action (4) Here *Down*
                            EasyTTSUtil.SpeechFlush("Down Gesture. music off");
                            infoBrg.setMusicOfforOn(false);
                        }
                    }
                }

                popUp = false;                                                                                          // Close GestureMode Panel
                infoBrg.setGestureModeActivity(false);                                                                  // Used to unfreeze avatar's movement
                break;


            default:
                break;
            }
        }
    }