public override bool processInput(GestureProfile profile)
    {
        if (Input.touchCount > 0)
        {
            //
            //Check for adding new touches
            //
            for (int i = 0; i < Input.touchCount; i++)
            {
                Touch touch = Input.touches[i];
                if (touch.phase == TouchPhase.Began)
                {
                    touchDatas.Add(touch.fingerId, new TouchData(touch));
                    origTouchCenter           = TouchCenter;
                    origCameraZoom            = Managers.Camera.ZoomLevel;
                    origAvgDistanceFromCenter = AverageDistanceFromCenter;
                }
            }
            maxTouchCount = Mathf.Max(maxTouchCount, Input.touchCount);

            //
            // Gesture Identification
            //

            if (touchEvent == TouchEvent.UNKNOWN)
            {
                if (maxTouchCount == 1)
                {
                    Touch     touch = Input.touches[0];
                    TouchData data  = touchDatas[touch.fingerId];
                    //Drag Gesture
                    if (Vector2.Distance(data.origPosScreen, touch.position) >= dragThreshold)
                    {
                        touchEvent = TouchEvent.DRAG;
                    }
                    //Hold Gesture
                    if (Time.time - data.origTime >= holdThreshold)
                    {
                        touchEvent = TouchEvent.HOLD;
                    }
                }
                //If more than one touch
                else if (maxTouchCount > 1)
                {
                    touchEvent = TouchEvent.CAMERA;
                }
            }
            //If converting from a player gesture to a camera gesture,
            else if (touchEvent != TouchEvent.CAMERA && maxTouchCount > 1)
            {
                //End the current player gesture
                //(No need to process tap gesture,
                //because it requires that all input stops to activate)
                Touch     touch = Input.touches[0];
                TouchData data  = touchDatas[touch.fingerId];
                switch (touchEvent)
                {
                //DRAG
                case TouchEvent.DRAG:
                    profile.processDragGesture(
                        data.origPosWorld,
                        Utility.ScreenToWorldPoint(touch.position),
                        DragType.DRAG_PLAYER,
                        true
                        );
                    break;

                //HOLD
                case TouchEvent.HOLD:
                    profile.processHoldGesture(
                        Utility.ScreenToWorldPoint(touch.position),
                        Time.time - data.origTime,
                        true
                        );
                    break;
                }
                //Convert to camera gesture
                touchEvent = TouchEvent.CAMERA;
            }

            //
            //Main Processing
            //

            if (maxTouchCount == 1)
            {
                Touch     touch = Input.touches[0];
                TouchData data  = touchDatas[touch.fingerId];
                switch (touchEvent)
                {
                //DRAG
                case TouchEvent.DRAG:
                    profile.processDragGesture(
                        data.origPosWorld,
                        Utility.ScreenToWorldPoint(touch.position),
                        DragType.DRAG_PLAYER,
                        touch.phase == TouchPhase.Ended
                        );
                    break;

                //HOLD
                case TouchEvent.HOLD:
                    profile.processHoldGesture(
                        Utility.ScreenToWorldPoint(touch.position),
                        Time.time - data.origTime,
                        touch.phase == TouchPhase.Ended
                        );
                    break;
                }

                //
                // Check for tap end
                //
                if (touch.phase == TouchPhase.Ended)
                {
                    //If it's unknown,
                    if (touchEvent == TouchEvent.UNKNOWN)
                    {
                        //Then it's a tap
                        profile.processTapGesture(Utility.ScreenToWorldPoint(touch.position));
                    }
                }
            }
            else if (maxTouchCount > 1)
            {
                //Get the center and drag the camera to it
                profile.processDragGesture(
                    origTouchCenterWorld,
                    Utility.ScreenToWorldPoint(TouchCenter),
                    DragType.DRAG_CAMERA,
                    Input.touches
                    .Where(t =>
                           t.phase != TouchPhase.Ended &&
                           t.phase != TouchPhase.Canceled
                           ).ToArray()
                    .Length == 0
                    );
                //Get the change in scale and zoom the camera
                float adfc = AverageDistanceFromCenter;
                if (adfc > 0)
                {
                    float scaleFactor = origAvgDistanceFromCenter / adfc;
                    Managers.Camera.ZoomLevel = origCameraZoom * scaleFactor;
                }
            }

            //
            //Check for removing touches
            //
            for (int i = 0; i < Input.touchCount; i++)
            {
                Touch touch = Input.touches[i];
                if (touch.phase == TouchPhase.Ended)
                {
                    touchDatas.Remove(touch.fingerId);
                    origTouchCenter           = TouchCenter;
                    origCameraZoom            = Managers.Camera.ZoomLevel;
                    origAvgDistanceFromCenter = AverageDistanceFromCenter;
                }
            }
            return(true);
        }
        //If there is no input,
        else
        {
            //Reset gesture variables
            touchEvent                = TouchEvent.UNKNOWN;
            maxTouchCount             = 0;
            origTouchCenter           = Vector2.zero;
            origCameraZoom            = Managers.Camera.ZoomLevel;
            origAvgDistanceFromCenter = 0;
            touchDatas.Clear();
            return(false);
        }
    }
    // Use this for initialization
    void Start()
    {
        gestureProfiles.Add("Main", new GestureProfile());
        currentGP = gestureProfiles["Main"];

        Input.simulateMouseWithTouches = false;
    }
Esempio n. 3
0
 /// <summary>
 /// Switches the gesture profile to the profile with the given name
 /// </summary>
 /// <param name="gpName">The name of the GestureProfile</param>
 public void switchGestureProfile(string gpName)
 {
     //Deactivate current
     currentGP.deactivate();
     //Switch from current to new
     currentGP = gestureProfiles[gpName];
     //Activate new
     currentGP.activate();
 }
Esempio n. 4
0
    public float holdThresholdScale       = 1.0f;//the amount to multiply the holdThreshold by

    // Use this for initialization
    void Start()
    {
        cmaController = cam.GetComponent <CameraController>();

        gestureProfiles.Add("Main", new GestureProfile());
        currentGP = gestureProfiles["Main"];

        Input.simulateMouseWithTouches = false;
    }
Esempio n. 5
0
    public bool cheatsEnabled        = false;     //whether or not the cheats are enabled


    // Use this for initialization
    void Start()
    {
        plrController = player.GetComponent <PlayerController>();
        rb2dPlayer    = player.GetComponent <Rigidbody2D>();
        cmaController = cam.GetComponent <CameraController>();

        gestureProfiles.Add("Main", new GestureProfile());
        gestureProfiles.Add("Rewind", new RewindGestureProfile());
        currentGP = gestureProfiles["Main"];

        Input.simulateMouseWithTouches = false;
    }
Esempio n. 6
0
 public override bool processInput(GestureProfile profile)
 {
     if (InputOngoing)
     {
         float horizontal = Input.GetAxis("Horizontal");
         float vertical   = Input.GetAxis("Vertical");
         if (Input.GetButton("Jump"))
         {
             vertical = 1;
         }
         Vector2 dir = (horizontal != 0 || vertical != 0)
             ? (
             (Vector2)((Camera.main.transform.up * vertical)
                       + (Camera.main.transform.right * horizontal)
                       ).normalized)
             : Vector2.zero;
         bool isInputNow   = dir != Vector2.zero;
         bool wasInputPrev = prevDir != Vector2.zero;
         if (isInputNow || wasInputPrev)
         {
             if (!wasInputPrev && isInputNow)
             {
                 //Gesture Start
                 gestureStartTime = Time.time;
             }
             float range = Managers.Player.Teleport.baseRange;
             if (Input.GetButton("Short"))
             {
                 range /= 2;
             }
             profile.processHoldGesture(
                 (Vector2)Managers.Player.transform.position + (dir * range),
                 Time.time - gestureStartTime,
                 !isInputNow
                 );
             return(true);
         }
         else if (Input.GetButtonDown("Rotate"))
         {
             profile.processTapGesture(Managers.Player.transform.position);
             return(true);
         }
         prevDir = dir;
     }
     return(false);
 }
Esempio n. 7
0
 public abstract bool processInput(GestureProfile profile);
Esempio n. 8
0
    public override bool processInput(GestureProfile profile)
    {
        if (InputOngoing)
        {
            //
            //Check for click start
            //
            if (mouseEvent == MouseEvent.UNKNOWN)
            {
                //Click beginning
                if (Input.GetMouseButtonDown(mouseButton))
                {
                    origPosScreen = Input.mousePosition;
                    origTime      = Time.time;
                    dragType      = DragType.DRAG_PLAYER;
                }
                else if (Input.GetMouseButtonDown(mouseButton2))
                {
                    origPosScreen = Input.mousePosition;
                    origTime      = Time.time;
                    dragType      = DragType.DRAG_CAMERA;
                }
                else if (Input.GetAxis("Mouse ScrollWheel") != 0)
                {
                    mouseEvent = MouseEvent.SCROLL;
                }
                //Click middle
                else
                {
                    //Check Drag
                    float dragDistance = Vector2.Distance(origPosScreen, Input.mousePosition);
                    if (dragDistance >= dragThreshold)
                    {
                        mouseEvent = MouseEvent.DRAG;
                    }
                    //Check Hold
                    else if (Time.time - origTime >= holdThreshold)
                    {
                        mouseEvent = MouseEvent.HOLD;
                    }
                }
            }

            //
            //Main Processing
            //

            switch (mouseEvent)
            {
            case MouseEvent.DRAG:
                profile.processDragGesture(
                    OrigPosWorld,
                    Utility.ScreenToWorldPoint(Input.mousePosition),
                    dragType,
                    Input.GetMouseButtonUp(mouseButton) || Input.GetMouseButtonUp(mouseButton2)
                    );
                break;

            case MouseEvent.HOLD:
                profile.processHoldGesture(
                    Utility.ScreenToWorldPoint(Input.mousePosition),
                    Time.time - origTime,
                    Input.GetMouseButtonUp(mouseButton) || Input.GetMouseButtonUp(mouseButton2)
                    );
                break;

            case MouseEvent.SCROLL:
                if (Input.GetAxis("Mouse ScrollWheel") < 0)
                {
                    Managers.Camera.ZoomLevel *= 1.2f;
                }
                else if (Input.GetAxis("Mouse ScrollWheel") > 0)
                {
                    Managers.Camera.ZoomLevel /= 1.2f;
                }
                break;
            }

            //
            //Check for click end
            //
            if (Input.GetMouseButtonUp(mouseButton))
            {
                //If it's unknown,
                if (mouseEvent == MouseEvent.UNKNOWN)
                {
                    //Then it's a click.
                    mouseEvent = MouseEvent.CLICK;
                    profile.processTapGesture(Utility.ScreenToWorldPoint(Input.mousePosition));
                }
            }
            if (Input.GetMouseButtonUp(mouseButton2))
            {
                //If it's unknown,
                if (mouseEvent == MouseEvent.UNKNOWN)
                {
                    //Then it's a camera drag
                    mouseEvent = MouseEvent.DRAG;
                    profile.processDragGesture(
                        OrigPosWorld,
                        Utility.ScreenToWorldPoint(Input.mousePosition),
                        dragType,
                        true
                        );
                }
            }
            return(true);
        }
        //If there's no input,
        else
        {
            //Reset gesture variables
            mouseEvent = MouseEvent.UNKNOWN;
            dragType   = DragType.UNKNOWN;
            //Hover gesture
            profile.processHoverGesture(
                Utility.ScreenToWorldPoint(Input.mousePosition)
                );
            return(false);
        }
    }