Esempio n. 1
0
/*
 *              v	   .__.     .         .  .__                 .___          ,                v
 *          v	v      [__]._  _|._. _ * _|  |  \ _ .  ,* _. _   [__ . .._  _.-+-* _ ._  __		v	v
 *      v	v	v      |  |[ )(_][  (_)|(_]  |__/(/, \/ |(_.(/,  |   (_|[ )(_. | |(_)[ )_)      v	v	v
 *   v	v	v	v                                                                               v	v	v	v
 */

    void androidTouchInput2()
    {
        Touch touch;
        float swipeDist = 0;

        //string direction = "";
        //string newInstruct = infoBrg.getNextInstruction ();

        if (Input.touchCount > 0 && !infoBrg.isGestureModeActive())
        {
            //***********************************************************************
            if (Input.GetTouch(0).tapCount == 3)                // Triple Tap Function
            {
                resetGame();                                    // on Android Device
            }
            //***********************************************************************

            touch = Input.GetTouch(0);
            switch (touch.phase)
            {
            case TouchPhase.Began:                                              //                      v TOUCH BEGINNING PHASE v
                couldBeSwipe = true;                                            //                      chance of being a swipe
                startpos     = touch.position;                                  //                      take of first position touched
                break;

            //******************************************************************

            case TouchPhase.Moved:                                                              //      v TOUCH WHILE MOVING v
                swipeDist = touch.position.y - startpos.y;                                      //		take note of how far swiped

                if (minSwipeDist < Mathf.Abs(swipeDist))                                        //          CHOOSE ONLY 1 OR 2 (BELOW)
                {
                    isMoving = true;
                    //if(!autoWalk)
                    //moveInAndroid (swipeDist * speedAndroid); //	<-1-- Allows Free-Movement in Android Device
                    //else
                    //autoWalkInAndroid(swipeDist * speedAndroid);	//	<-2-- Auto-walks to next waypoint
                }
                if (Mathf.Abs(touch.position.y - startpos.y) > comfortZone)                             // is swipe too far?
                {                                                                                       // not a valid swipe
                    couldBeSwipe = false;
                }
                break;

            //*******************************************************************

            case TouchPhase.Stationary:                                                         //	    v TOUCH HELD DOWN (STATIONARY) v
                swipeDist = touch.position.y - startpos.y;                                      // take note of how far swiped

                if (minSwipeDist < Mathf.Abs(swipeDist))                                        // CONDITION:   Is swipe distance greater than minSwipeDistance?
                {
                    isMoving = true;
                    //if (!autoWalk)
                    //moveInAndroid (swipeDist * speedAndroid);         //	<-1-- Allows Free-Movement in Android Device
                    //else
                    //autoWalkInAndroid (swipeDist * speedAndroid);
                }
                break;

            //*******************************************************************
            case TouchPhase.Ended:                                                                                      //      v TOUCH OFF SCREEN (ENDED)
                swipeDist = (touch.position - startpos).magnitude;
                isMoving  = false;
                if (couldBeSwipe && (swipeDist > minSwipeDist))
                {
                    float xDistance = touch.position.x - startpos.x;
                    float yDistance = touch.position.y - startpos.y;

                    if (Mathf.Abs(xDistance) > Mathf.Abs(yDistance))                            // If horizontal swipe// rotate the avatar
                    {
                        if (!autoWalk)
                        {
                            rotate(xDistance);                                                                                          // (Turn avatar left or right 90 degrees)
                        }
                        //else
                        //autoRotate (xDistance);
                    }
                    else if (Mathf.Abs(xDistance) < Mathf.Abs(yDistance))
                    {
                        if (yDistance < 0)
                        {
                            distanceFromWayPoint();
                        }
                    }
                }
                break;

            default:
                break;
            }
        }
    }